mixOmicsTeam / mixOmics

Development repository for the Bioconductor package 'mixOmics '
http://mixomics.org/
157 stars 52 forks source link

feature request: export loadings from plotLoadings without plotting #294

Open tyronechen opened 1 year ago

tyronechen commented 1 year ago

Is your feature request related to a problem? Please describe.

Aim is to export a table of all loading values from plotLoadings without plotting the associated bar graph. This was possible in an earlier version of mixOmics 6.17.3. Version tested is 6.23.4.

Describe the solution you'd like

I would like to skip the plot generation when exporting all loadings. This is computationally expensive with a lot of features.

Describe alternatives you've considered

A workaround exists, it is possible to generate the plot as normal, with plot=TRUE (see below) and then catch the output in a variable. However in the case of many features (>10000) it slows down and generates very big plots.

Additional context

Code below best shows the event. Minimum reproducible example based on the Koren case study. mixOmics 6.23.4.

> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: libopenblasp-r0.3.21.so

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] mixOmics_6.23.4 ggplot2_3.4.1   lattice_0.20-45 MASS_7.3-58.3

data("Koren.16S") # extract the microbial data
X <- Koren.16S$data.raw # set the raw OTU data as the predictor dataframe
Y <- Koren.16S$bodysite # set the bodysite class as the response vector
basic.koren.plsda = plsda(X, Y, logratio = 'CLR', ncomp = nlevels(Y))

Plot everything correctly:

x <- plotLoadings(basic.koren.plsda, contrib="max", plot=TRUE)
# pull out the values
dim(x$X)
[1] 980  10
...

This errors out. I traced this back to a line in plotLoadings. Here is one sample for plotLoadings.mixo_plsda (others have this too):

x <- plotLoadings(basic.koren.plsda, contrib="max", plot=FALSE)
Error in names(contrib.df) <- block :
  'names' attribute [1] must be the same length as the vector [0]

I note that this worked in mixOmics 6.17.3:

> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: libopenblasp-r0.3.15.so

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] mixOmics_6.17.3 ggplot2_3.3.6   lattice_0.20-45 MASS_7.3-58.1
LafontRapnouilTristan commented 3 months ago

Hi,

thanks for the amazing work! This would be great with any plot function of Mixomics.

For instance if I want to ggplotify the network I can store its data in a variable but can cause some issues with graphic state if working in Rmarkdown with graphical display in line. A direct access to the data used for your plot methods would be great! Thanks again!