I have a taxonomy list created from bracken that I want to import to phyloseq. I have my taxa in one column like so:
k__Bacteria|p__Coprothermobacterota|c__Coprothermobacteria|o__Coprothermobacterales|f__Coprothermobacteraceae|g__Coprothermobacter
I've managed to separate these into columns based on their taxa (see code below). The problem arises when there's candidate species such as
k__Bacteria|f__Candidatus_Chazhemtobacteraceae|g__Candidatus_Chazhemtobacterium
As you can see, it needs to go into the Family column, and the Phylum and Class (etc) columns should be left NA. I'm stuck on how to do this; after separating into columns, how can I then sort the taxa into the correct classification based on the "x__" string (and then remove this string?)
Thank you!
I've managed to separate into the columns "Kingdom", "Phylum", "Class" "Order", "Family" and "Genus" using dplyr:
new_tax <- s_abund %>%
dplyr::rename("taxonomy" = "#Classification") %>%
dplyr::select(taxonomy) %>%
separate(taxonomy, sep = "\\|", remove = FALSE, into = c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus"))
You can do use
strsplit
, and thenpivot_wider()
like this:Output:
Input: