saezlab / MetaProViz

R-package to perform metabolomics pre-processing, differential metabolite analysis, metabolite clustering and custom visualisations.
https://saezlab.github.io/MetaProViz/
GNU General Public License v3.0
10 stars 0 forks source link

Invisible return in all functions instead of assign and saving of Plot list #48

Closed ChristinaSchmidt1 closed 1 year ago

ChristinaSchmidt1 commented 1 year ago

invisible return in R: invisible() in the end of the function --> if the user assigns the results (e.g. Result <- MetaProViz::Function() ) the results are returned, otherwise not. We should check this out and rather return all the DFs in one multi-document upon assignment. This is based on some feedback I received, we can think about this later.

ChristinaSchmidt1 commented 1 year ago

Done for PCA

ChristinaSchmidt1 commented 1 year ago

Done for Volcano

ChristinaSchmidt1 commented 1 year ago

As mentioned in our meeting yesterday lets do the following: Make a list with two lists (Plots and DFs) and then within the list of Plots we have all produced plots of a function and within the list of DFs we have the result DFs. This is return using invisible return.

As you mentioned for some functions there is a problem that the plots are not displayed properly, so in this case we assign the plot list do the global environment and only return the list of DFs with invisible return to have a quick fix for the time being.

ChristinaSchmidt1 commented 1 year ago

I have looked into the issue you described that when you do this assign that the plots are not plotting, but that you only get the print out of the grid. This actually happens anytime when we use PCA, Volcano or heatmap, since those function have been modified in their grid and are hence gtable elements. gtable elements are like ggplots, but in order to generate the plot you can not simply do:

QC_Plots[[1]] #prints out gtable

If you want to visualize the plot in the Plots window you need to:

plot(QC_Plots[[1]]) #generates the plot of the gtable

Now, if a user wants to change e.g. the theme of the plot or do other things this needs to become a ggplot object again. We can do this by:

Newggplot <- ggplot() +
      annotation_custom(QC_Plots[[1]])

In order to not have to do this I have added the conversion into the viz functions. So now this issue should be gone. Meaning that with:

QC_Plots[[1]] 

we should now print out the plot and not the gtable.

dprymidis commented 1 year ago
ChristinaSchmidt1 commented 1 year ago

Plotting the plot is a bit of a tough one as this is really preference driven. I guess if we are talking about the QC plots, I would probably plot the main once, but not every round of hitellins T2 test. The same for volcano plots: If I rund only one I want to see the result, whilst if i do individual once for each pathway its like spam, which I dont need.

Since we are now collecting every plot in a list, I would turn of all plottings in all of the functions. This gives us two options:

  1. As a last step put plot=TRUE or plot=FALSE and just print each item in the plot list or not. So the user can just tunr it off or on.
  2. We could use facet_grid or patchwork::wrap_plots where we return a printed summary of all plots: https://patchwork.data-imaginist.com/reference/wrap_plots.html image

If save_as_plots=TRUE, we can also save the plot summary. Again if there are two many plots, this would lead to returning multiple summaries.

dprymidis commented 1 year ago

A resulting summary plot for Plot=TRUE image

for ORA (DM and MC) the plots dont fit in one, so I plot them one at a time. For MC_ORA we print only 1 set of plots.

ChristinaSchmidt1 commented 1 year ago
ChristinaSchmidt1 commented 1 year ago

I have removed the plots and only DFs are returned. For the ORA on DMA we get two DFs returned, one with the ORA results and one with the setting columns added to the input data. For ORA on a group column (e.g. from MCA), we get a list of DFs including ORAresults for each cluster.