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

Is it possible to transform sample counts by value stored in sample data? #1743

Closed tacaro closed 2 months ago

tacaro commented 2 months ago

I'm trying to transform sample counts by a scaling factor that is present in the sample_data. This scaling factor represents an independent estimate of total microbial biomass and is specific to each sample. As a rough approximation of absolute abundance, I'm multiplying relative abundance by the total cell biomass to get taxon-specific absolute abundance.

absolute_abundance = relative_abundance * biomass_quantity

So, I think the best candidate for doing this would be transform_sample_counts(), (documentation) but I'm having trouble accessing data from within the sample data portion of the PS object.

ps.samples.abs <-  ps.samples.PLFA |> 
  transform_sample_counts(
    function(x) (x/sum(x)) * biomass_mg
    )
# Error in fun(1:10) : object 'biomass_mg' not found

If this function is inappropriate for the task at hand, is there a possible workaround? Any help or ideas are appreciated!

tacaro commented 2 months ago

Just found this - which worked for me. https://github.com/joey711/phyloseq/issues/497