I'm sorting out taxa.
The data in the Taxon column was sorted by placing k in the Kingdom column, p in the Phylum column, and c in the Class column. And I deleted k__, p__ and c__.
Most have been successful, but some have not.
I marked the problem with the picture. Green should be placed in the green column, blue in the blue column, and red in the red column. However, because the feature.id has no information about the phylum level and the Taxon is entered, an incorrect result is obtained.
How should I handle this part? I want to know how to move some elements in some rows.
I am attaching the code I wrote.
Thank you so much for your help.
But it is not perfect as you know. Please give me any suggestion for solving this problem. Thank you so much for your help.
Tax21 <- Tax1 %>% select(-Confidence) %>%
mutate(Kingdom = str_split(Taxon, ";") %>% sapply(`[`,1) %>%
str_replace("k__", "")) %>%
mutate(Phylum = str_split(Taxon, ";") %>% sapply(`[`,2) %>%
str_replace("p__", "")) %>%
mutate(Class = str_split(Taxon, ";") %>% sapply(`[`,3) %>%
str_replace("c__", "")) %>%
mutate(Order = str_split(Taxon, ";") %>% sapply(`[`,4) %>%
str_replace("o__", "")) %>%
mutate(Family = str_split(Taxon, ";") %>% sapply(`[`,5) %>%
str_replace("f__", "")) %>%
mutate(Genus = str_split(Taxon, ";") %>% sapply(`[`,6) %>%
str_replace("g__", "")) %>%
mutate(Species = str_split(Taxon, ";") %>% sapply(`[`,7) %>%
str_replace("s__", ""))%>%
mutate(Species = ifelse(grepl("cul", Species), NA, Species),
Genus = ifelse(grepl("cul", Genus), NA, Genus),
Species = ifelse(grepl("un", Species), NA, Species),
Genus = ifelse(grepl("un", Genus), NA, Genus),
Species = ifelse(grepl("metag", Species), NA, Species),
Genus = ifelse(grepl("metag", Genus), NA, Genus)) %>%
mutate(X = Species) %>%
View()