microbiome / mia

Microbiome analysis
https://microbiome.github.io/mia/
Artistic License 2.0
50 stars 27 forks source link

Batch transformations. #429

Open antagomir opened 1 year ago

antagomir commented 1 year ago

Create Function to add given transformation to all altExps / ranks at once, or at least provide an example in OMA/mia.

This is handy also since methods like agglomerateFeaturesByRank or splitByRank will only deal with count and relabundance assays, and ignore the rest (like CLR, which does translate directly in such operations). Hence there is often a need to add transformations in batch for all altExps after such operations.

TuomasBorman commented 1 year ago

Maybe apply.altexp parameter to transformAssay?

TuomasBorman commented 5 months ago

@Insaynoah Could you check this?

If apply.altexp=TRUE

  1. Do transformation to TreeSE. (just like it does currently)
  2. If there are altExps, lapply over them and apply transformation
TuomasBorman commented 5 months ago

https://github.com/microbiome/mia/blob/c629462bf92e2c8cd48e878667dbd08a34b23fa1/R/transformCounts.R#L235

It might be that you have to move code from lines 235-258 to internal function. Then call that internal function from the transformAssay().

# In input check, check that assays present. --> If apply.altexp was specified, check also assays of altexp --> fail fast
#
x <- .perform_transformation()

if( apply.altexps && length(altExps) > 0 ){
   altExps() <- lapply(altExps(), .perform_ransformation()
}

return(x)
.perform_transform <- funciton(){
1. Apply pseudocount
2. Apply transformation
3. return TreeSE with transformed data
}
antagomir commented 5 months ago

Thanks @Insaynoah if you have a chance to check it

TuomasBorman commented 4 months ago

This is useful and often needed. @ake123 can you check? See the comments above

tse <- agglomerateByRanks(tse)
tse <- transformAssay(tse, method = "relabundance", apply.altexp = TRUE)
antagomir commented 4 months ago

Yes. Just one reservation: imo we could allow users to choose which altexps they would like to include. The default could be all (as in apply.altexp=TRUE) but it could also be a subset selection, like apply.altexp=c("counts", "relabundance").

Could it be just a shorter "altexp" instead of "apply.altexp"?

TuomasBorman commented 4 months ago

altexp is ok, so it would be

tse <- transformAssay(tse, method = "relabundance", altexp = c("phylum", "genus"))

antagomir commented 4 months ago

Hups, yes.

ake123 commented 4 months ago

This is ready I am waiting for the other PR closed then make a PR for this.

Daenarys8 commented 3 weeks ago

Can we close this?

antagomir commented 3 weeks ago

We can close when the PR is merged?