joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
582 stars 187 forks source link

command to merge a otu_table and tax_table #1645

Open Robvh-git opened 1 year ago

Robvh-git commented 1 year ago

Hello,

I have a subsetted phyloseq object "x", containing 9 taxa.

I've created relative abundances of the read data (using microbiome::), so when running otu_table(x) I get relative abundances for each feature. The feature IDs are currently long strings, e.g.: "31fad54be44797f948a21c9e010ec9a7"

When running tax_table(x) I get the taxonomic info per feature ID.

In the relative abundance data (otu_table(x)) I want to replace the long feature ID strings, for the genus (or whole tax information, if only genus is not possible) of each feature id, as shown in tax_table(x).

I can imagine that there is a phyloseq function specifically for doing this, but I cannot seem to find it.

Could anyone please advise me how to do this?

Thanks!

david-barnett commented 1 year ago

To replace the long taxa ID strings with their classification at genus, you might like the tax_rename function from my package microViz

https://david-barnett.github.io/microViz/reference/tax_rename.html

Example from the documentation:


library(phyloseq)
library(microViz)
data("ibd_phylo", package = "corncob")

ps <- ibd_phylo %>%
  tax_filter(min_prevalence = 3) %>%
  tax_fix()

# show a few of the current, uninformative names
taxa_names(ps) %>% head(15)
#>  [1] "OTU.49"  "OTU.50"  "OTU.52"  "OTU.54"  "OTU.56"  "OTU.57"  "OTU.59" 
#>  [8] "OTU.76"  "OTU.90"  "OTU.92"  "OTU.108" "OTU.142" "OTU.185" "OTU.197"
#> [15] "OTU.200"

# change names to genus classification plus number
psNewNames <- ps %>% tax_rename(rank = "Genus")

taxa_names(psNewNames) %>% head(15)
#>  [1] "Faecalibacterium 203"             "Escherichia/Shigella 081"        
#>  [3] "Clostridium_XlVa 045"             "Lachnospiraceae Family 20"       
#>  [5] "Bacteroides 0825"                 "Flavonifractor 25"               
#>  [7] "Ruminococcaceae Family 05"        "Clostridium_XlVa 028"            
#>  [9] "Faecalibacterium 204"             "Escherichia/Shigella 088"        
#> [11] "Escherichia/Shigella 130"         "Clostridium_XlVa 110"            
#> [13] "Lachnospiraceae Family 58"        "Lachnospiracea_incertae_sedis 34"
#> [15] "Bacteroides 0967"