I have a huge database of that lists antibiotic resistance genes as part of a variable in a dataframe. I want to write a script that automatically assigns the correct antibiotic group the gene belongs to, to a new corresponding variable. For example:
Nr Gene
[1] 1 "TEM-1, CTX-M-12, CTX-M-14, ampC"
[2] 2 "VIM, blaCMY, CTX-M-24"
Now if, for example, I were to assign all genes containing "CTX" and "CMY" to beta-lactamases, and "VIM" to Vancomycin, it should return:
Nr Gene Group
[1] 1 "TEM-1, CTX-M-12, CTX-M-14, ampC" "beta-lactamases"
[2] 2 "VIM, blaCMY, CTX-M-24" "beta-lactamases, Vancomycin"
I have tried using the if function:
if ("*CTX*" or "*CMY*" %in% df$Gene) {
df$Group <- paste("beta-lactamases")
}
But does not work. Any help would be appreciated.