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/
568 stars 187 forks source link

Transforming OTU table counts sample-wise by variable ("absolute abundance") #497

Open BHelmut opened 9 years ago

BHelmut commented 9 years ago

Hi,

I would like to create some barplots with calculated values of an absolute abundance. I have a Phyloseq object with relative abundance values, created like this from a standard count table of illumina reads (16S bacteria): sediment.filt.ab <- transform_sample_counts(sediment.filt, function(x){x/sum(x)})

The sample_data table contains a variable Cellcounts that contains the measured total microbial abundance of each sample.

I would now like to calculate an OTU table with "absolute abundances" estimated from x(OTU, sample) * Cellcounts(sample). It seems like a simple task, but I am stumped at the moment. I cannot do this with transform_sample_counts because it only takes a single argument, right?

spholmes commented 9 years ago

Not quite understanding the query, it seems you just want to reverse the transformation you made, why are you transforming the data if you keep the absolute abundances as they are in sediment.filt what happens?

On Tue, Jun 30, 2015 at 8:13 AM, BHelmut notifications@github.com wrote:

Hi,

I would like to create some barplots with calculated values of an absolute abundance. I have a Phyloseq object with relative abundance values, created like this from a standard count table of illumina reads (16S bacteria): sediment.filt.ab <- transform_sample_counts(sediment.filt, function(x){x/sum(x)})

The sample_data table contains a variable Cellcounts that contains the measured total microbial abundance of each sample.

I would now like to calculate an OTU table with "absolute abundances" estimated from x(OTU, sample) * Cellcounts(sample). It seems like a simple task, but I am stumped at the moment. I cannot do this with transform_sample_counts because it only takes a single argument, right?

— Reply to this email directly or view it on GitHub https://github.com/joey711/phyloseq/issues/497.

Susan Holmes Professor, Statistics and BioX Director, MCS Sequoia Hall, 390 Serra Mall Stanford, CA 94305 http://www-stat.stanford.edu/~susan/

BHelmut commented 9 years ago

The absolute abundances in sediment.filt are raw read counts, which is not really meaningful, i.e. each sample has a different number of reads from the sequencing procedure, but they also represent microbial communities of different densities in the sediment studied.

I want plots both of the relative abundance of taxa with (sediment) depth (this I already have), but also plots of the absolute abundance (in the sediment, not in terms of sample reads)

So I want to multiply the relative abundance of an OTU (% of total reads) with the externally measured cellnumber (e.g. DAPI counts or 16s qPCR results).

I may just have found a way, but still need to test this:

sediment.filt.ab <- transform_sample_counts(sediment.filt, function(x){x/sum(x)}) sediment.filt.abs <- sediment.filt.ab

for(n in 1:nsamples(sediment.filt.ab)) { otu_table(sediment.filt.abs)[,n] <- otu_table(sediment.filt.ab)[,n]*sample_data(sediment.filt.ab)$Cellcounts [n] }

cramjaco commented 4 years ago

Can confirm that @BHelmut 's solution worked for me in an analogous situation.

tjarbour commented 4 years ago

Thanks @BHelmut (ver. 2015 ;) and @cramjaco. I also found this solution, which I like because it seems more transparent: https://github.com/joey711/phyloseq/issues/1224