1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| library(tidyverse) otu <- read.table("feature-table.tsv",header = T, sep = "\t",comment.char="",skip=1) colnames(otu)[1]<-"OTU.ID" tax <- read.table("taxonomy.tsv", header = T, sep = "\t")
sum(tax$Taxon == "Unassigned")
sum(is.na(tax$Taxon)) rankTaxon <- data.frame(Taxon = tax$Taxon) rankTaxon <- separate(rankTaxon, Taxon, sep = "; ", into = as.character(1:7)) colnames(rankTaxon) <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species") rankTaxon <- cbind(id = tax$Feature.ID, rankTaxon, Confidence = tax$Confidence) otuWithTax <- right_join(otu, rankTaxon, by = c("OTU.ID" = "id")) totalCount <- rowSums(otuWithTax[, 2:ncol(otu)]) totalPercent <- totalCount / sum(totalCount) * 100 otuWithTax$totalCount <- totalCount otuWithTax$totalPercent <- totalPercent otuWithTax <- arrange(otuWithTax, desc(totalCount)) otuWithTax$OTU.IX<-paste0("OTU",1:nrow(otuWithTax)) otuWithTax<-otuWithTax[otuWithTax$totalCount > 1,] write.csv(otuWithTax, "OTUByNaive_bayesSortByOneMore.csv", row.names = F)
sum(otuWithTax$totalCount > 1)
|