MATLAB Answers

Get M/Z values in a msheatmap/msdotplot overlay with a pixel pseudocolor value greater than 120 (the range is 0 - 195)?

4 views (last 30 days)
I have an LCMS acquisition with 1897 time variables and a varying range of M/Z variables. The mzXML file was imported using 'mzXMLread' which works well.
I used the 'mzxml2peaks' function to get the M/Z spectrum for each of the 1987 time variables and a time vector for my file, which works well.
I saved my data in a struct like 'newdata' with the fields 'peaks', 'time', which is all thats needed to visualise the data. Peaks can be accessed via 'newdata(1).peaks' and
the time vector can be accessed via 'newdata(1).time'.
Next I proceeded with the steps as mentioned in the msdotplot help section
[MZ,Y] = msppresample(newdata(1).peaks,5000);
after which, I overlayed this heatmap with the dotplot to highlight features of interest
axis([400 1700 903 1626])
where, 400 to 1700 is the x axis (M/Z range) and 903 to 1626 is the y axis (time range). This is the range I am interested in seeing.
I have attached the resulting figure as 'Figure n1.png' which gets me a pseudocolor range of values [0 195].
I am interested to get the x axis coordinates (and exact M/Z values) of those pixels whose color value is greater than 120. I have been scrambling to use functions like findobj, get, set, gca, gcf but couldnt quite get it working. I also tried imtool, but imtool compresses the image and appears to lose the actual X and Y data. Furthermore, there appear to be too many pixels to pick by hand.
Can someone point me to the right direction for this please, I would be obliged? Thank you.


Sign in to comment.

Accepted Answer

Tim DeFreitas
Tim DeFreitas on 20 Apr 2020
Edited: Tim DeFreitas on 21 Apr 2020
Rather than inspecting the range of colors in the heatmap after it's produced, I'd suggest finding the values in Y that are above a certain threshold. Something like the following:
Yind = log(Y) > someValue; % Select an appropriate threshold and index into Y
% Filter heatmap data first
MZfilt = MZ(any(Yind, 2)); % Select MZ where any value is above threshold
Timefilt = newdata(1).time(any(Yind,1)) % Select times where any value is above threshold
Yfilt = log(Y(Yind)); % **EDIT -- this selects the correct values but is the wrong shape, see comment**
% Now plot results, all values should match.
% The heatmap may look strange if there are very few values meeting your threshold.
msheatmap(MZfilt, Timefilt, Yfilt)


Sindhuraj Mukherjee
Sindhuraj Mukherjee on 21 Apr 2020
Hi Tim! Thank you for your answer. I have a couple of followup questions :-
I do think its better to threshold Y and find the relevant M/Z. I did this by using the 'quantile' function. Does this work the same way as the 'Quantile' option in msdotplot? I did get a singular value using 'quantile' which I substituted with 'someValue' as given in your code.
MZfilt, Timefilt, Yfilt show different sizes. Is this expected? I presumed I would get similar shapes of MZfilt, Timefilt and Yfilt. The heatmap doesnt show up, because the values for MZfilt, Timefilt and Yfilt dont match up to make the heatmap.
Anyways, I am interested in the actual M/Z, so maybe I can just use MZfilt and get relevant M/Z which I can then use in other software for data export to get the relevant reconstructed ion chromatogram.
Would you happen to know any peer reviewed research papers which use msdotplot, msheatmap and LCMS stuff?
Tim DeFreitas
Tim DeFreitas on 21 Apr 2020
Hi Sindhuraj,
The sizes should be compatible, I made a mistake in my code above creating Yfilt. This should produce the correct sized matrix:
Yfilt = Y(any(Yind,2), :);
Yfilt = Yfilt(:,any(Yind,1)');
Yfilt = log(Yfilt);
msdotplot uses the quantile function internally, so the results should be the same. Unfortunately I'm not aware of any specific papers using these functions, though it's possible that papers are using these plots and not mentioning these functions by name.
Hope this helps,
Sindhuraj Mukherjee
Sindhuraj Mukherjee on 21 Apr 2020
Thanks for the updated code Tim, I do indeed get the corrected heatmap.
I can use the MZfilt matrix now to get the M/Z values I need (which was possible with your earlier bit of code).
The heatmap I have is from a mixture (component + solvent). If I wanted to get M/Z values unique to the component, would you recommend following the same steps of MZfilt, Timefilt and Yfilt for my solvent, extracting those values and subtracting them in a new heatmap argument? My objective is to find solvent removed M/Z values.

Sign in to comment.

More Answers (0)


Translated by