microeco icon indicating copy to clipboard operation
microeco copied to clipboard

add taxonomy to ASV-level heatmaps

Open jamorillo opened this issue 1 year ago • 4 comments

Hello, I would like to get a heat map at ASV level, that also indicates the taxonomy of the ASVs at genus level (for example the rows should be like: "ASV1234_Bacillus"). I tried this way first, using your toy dataset, but I get an error:

library(tidyverse) library(microeco) library(magrittr)

add ASVs to taxonomy:

dataset2 <- clone(dataset)
dataset2$rename_taxa(newname_prefix = "ASV")

include ASVs in taxa table: dataset2$add_rownames2taxonomy(use_name = "ASVs")

tidy: dataset2$tax_table %<>% tidy_taxonomy dataset2$tidy_dataset()

check that ASVs is a new column in taxonomy: tax <- dataset2$tax_table

output of str(tax):

str(tax) 'data.frame': 404 obs. of 8 variables: $ Kingdom: chr "k__Archaea" "k__Bacteria" "k__Bacteria" "k__Bacteria" ... $ Phylum : chr "p__Miscellaneous Crenarchaeotic Group" "p__Proteobacteria" "p__Proteobacteria" "p__Proteobacteria" ... $ Class : chr "c__" "c__Betaproteobacteria" "c__Deltaproteobacteria" "c__Deltaproteobacteria" ... $ Order : chr "o__" "o__Burkholderiales" "o__Syntrophobacterales" "o__Desulfuromonadales" ... $ Family : chr "f__" "f__Comamonadaceae" "f__Syntrophaceae" "f__Geobacteraceae" ... $ Genus : chr "g__" "g__" "g__Syntrophus" "g__Geoalkalibacter" ... $ Species: chr "s__" "s__" "s__" "s__" ... $ ASVs : chr "a__ASV1" "a__ASV2" "a__ASV3" "a__ASV4" ...

OK, the "ASVs" column is in. But when I try to generate the trans object:

t1 <- trans_abund$new(dataset = dataset2, taxrank = "ASVs", high_level = "Genus", ntaxa = 50) I get this error: Error in initialize(...) : The input parameter taxrank: ASVs is not found! Please check whether it is correct!

I don´t understand it, because "ASVs" was already a new column of the taxonomy table.

How can I proceed till the heatmap? thanks! jose

jamorillo avatar Jun 13 '23 12:06 jamorillo

Hi. You must use cal_abund function to regenerate the taxonomic abundance table list. Please add one step before you use trans_abund class.

dataset2$cal_abund()
# then run 
t1 <- trans_abund$new(dataset = dataset2,
taxrank = "ASVs",
high_level = "Genus",
ntaxa = 50)

Please feel free to tell me if it is still there.

Chi

ChiLiubio avatar Jun 13 '23 14:06 ChiLiubio

Hi again. Many thanks for the fast response! Doing this I get the heatmap:

dataset2$cal_abund() t1 <- trans_abund$new(dataset = dataset2, taxrank = "ASVs", high_level = "Genus", ntaxa = 50)

ASV_plot <- t1$plot_heatmap( xtext_keep = FALSE, withmargin = TRUE, xtext_type_hor = FALSE )

But how could I add the genus classification to the ASVs in the heatmap? (in case they have) I tried to add another column to the taxonomy table and use it for this but it did not work. thanks jose

jamorillo avatar Jun 13 '23 14:06 jamorillo

Hi. I take an example. This solution is to partly select the taxonomic lineages when generating the taxonomic abundance list。

library(microeco)
library(magrittr)
data("dataset")
dataset2 <- clone(dataset)

dataset2$rename_taxa(newname_prefix = "ASV")
dataset2$add_rownames2taxonomy(use_name = "ASVs")

dataset2$tax_table %<>% tidy_taxonomy
dataset2$tidy_dataset()
# select the columns you want to show
dataset2$cal_abund(select_cols = c("Genus", "ASVs"))
# you can find the prefix in this table is what we need
View(dataset2$taxa_abund$ASVs)
# remember to use delete_full_prefix to show all the prefix
t1 <- trans_abund$new(dataset = dataset2,
taxrank = "ASVs",
delete_full_prefix = FALSE,
ntaxa = 50)

t1$plot_heatmap(
withmargin = TRUE,
)

If you donot need the prefix 'a__' before the ASV names, please delete the line dataset2$tax_table %<>% tidy_taxonomy.


library(microeco)
library(magrittr)
data("dataset")
dataset2 <- clone(dataset)
dataset2$rename_taxa(newname_prefix = "ASV")
dataset2$add_rownames2taxonomy(use_name = "ASVs")
# select the columns you want to show
dataset2$cal_abund(select_cols = c("Genus", "ASVs"))
View(dataset2$taxa_abund$ASVs)

# use delete_full_prefix to show all the prefix
t1 <- trans_abund$new(dataset = dataset2,
taxrank = "ASVs",
delete_full_prefix = FALSE,
ntaxa = 50)

t1$plot_heatmap(
withmargin = TRUE,
)

Chi

ChiLiubio avatar Jun 14 '23 02:06 ChiLiubio

Hello, It works very well, thank you very much. I have applied this to my own dataset. best regards, jose

jamorillo avatar Jun 19 '23 10:06 jamorillo