pyopenms_viz icon indicating copy to clipboard operation
pyopenms_viz copied to clipboard

apply log scaling only to peakmap colors

Open timosachsenberg opened this issue 9 months ago • 10 comments

Might make sense to only apply it to colors but not the intensities? looks a bit off in the marginals

Image

timosachsenberg avatar Mar 13 '25 18:03 timosachsenberg

Yes @timosachsenberg , I see what you mean! Applying log scaling only to the colors while keeping raw intensities for the marginal plots should fix this. I’ll try implementing it and share the results. Let me know if you have any preferences on how to handle it!!!

Imama-Kainat avatar Mar 14 '25 09:03 Imama-Kainat

Image

Imama-Kainat avatar Mar 14 '25 22:03 Imama-Kainat

Image

Imama-Kainat avatar Mar 14 '25 22:03 Imama-Kainat

Hi @timosachsenberg ,

I'm facing a ModuleNotFoundError in app.py while trying to run pyopenms_viz using Streamlit. The error is related to plotMSExperiment, but after checking the repo, this function doesn't exist.

I found PeakMapPlot inside _core.py and tried importing it instead, but the app still doesn't run due to module import errors. I've installed dependencies (pip install -r requirements.txt, pip install -e .) and tried multiple fixes, but no luck:(

Can you confirm if plotMSExperiment was removed, and if PeakMapPlot is the correct alternative? Also, how should app.py be properly set up for visualization?

Imama-Kainat avatar Mar 14 '25 22:03 Imama-Kainat

Sir @timosachsenberg , could it be a solution to simply create a new variable copying self.z (before doing the log transformation) in case z_log_scale is True and use self.z (i.e. the transformed int) for the main plots and the previously created variable for the marginal plots?

Leandro1302 avatar Mar 14 '25 23:03 Leandro1302

Hi @timosachsenberg ,

I'm facing a ModuleNotFoundError in app.py while trying to run pyopenms_viz using Streamlit. The error is related to plotMSExperiment, but after checking the repo, this function doesn't exist.

I found PeakMapPlot inside _core.py and tried importing it instead, but the app still doesn't run due to module import errors. I've installed dependencies (pip install -r requirements.txt, pip install -e .) and tried multiple fixes, but no luck:(

Can you confirm if plotMSExperiment was removed, and if PeakMapPlot is the correct alternative? Also, how should app.py be properly set up for visualization?

Ahh, this was old code from the initial development/design of pyopenms_viz. Those modules no longer exist, and we never updated app.py. We used app.py for more exploratory and testing purposes and never removed it from the final release.

We could, either update app.py to reflect the new API (although, we have the streamlit-template repo which could also be used as a testing ground for pyopenms_viz plots), or just remove it completely.

The correct method call now would be:

import pyopenms_viz
import pandas as pd

ms_df.plot(kind = "peakmap", x = "rt", y = "mz", backend = "ms_plotly")

singjc avatar Mar 15 '25 01:03 singjc

@singjc do you have a suggestion how to handle the log scaling?

timosachsenberg avatar Mar 15 '25 08:03 timosachsenberg

@Imama-Kainat @Leandro1302 , we currently mutate the intensity data (either y for 1D plots or z for 2D plots) for two cases: 1) when we want to plot the intensity as relative intensity (0-100), or/and 2) log transform the data for a better visual for 2D plots.

Currently, we do it this way, I think because it's easier to keep track of the variable we want to plot, and we perform sorting prior to plotting for 2D plots, so that the most intense values get rendered last to avoid being masked by other points.

One option could be as @Leandro1302 suggested, to create a copy of the z variable that we can use for the marginal plots. Another option would be to reverse the transformation applied to z for the marginal plots to get the original data for plotting. For the log scaling we just apply np.log1p( z ), so prior to generating the marginal plots, we could apply np.expm1( z ) to convert the data back.

singjc avatar Mar 15 '25 15:03 singjc

@singjc thanks for mensioning Yes there can be these two approches i have implemented z_original = z.copy() approach to keep the raw intensity values intact for marginal plots while allowing transformations on z for rendering z_original to store raw intensity values before applying log transformation or normalization. Used z_original in marginal plots Becuase it preserver data integrity and avoid additional computation and easy mainatainablility

Imama-Kainat avatar Mar 15 '25 18:03 Imama-Kainat

Image

My log scaling flow

Imama-Kainat avatar Mar 15 '25 18:03 Imama-Kainat