-1

I am trying to plot a graph/chromatogram of the x and y-values located in time_dependent_intensities, but only the ones with the largest y-values.

    run = pymzml.run.Reader(in_path)
    time_dependent_intensities = []
    for spectrum in run:
        if spectrum.ms_level == 1:
            has_peak_matches = spectrum.reduce(mz_range=(150,151))
            if has_peak_matches != []:
                for mz, I in has_peak_matches:
                    time_dependent_intensities.append(
                        [spectrum.scan_time_in_minutes(), I]
                    )
    print("RT   \ti")
    for i in time_dependent_intensities:
        print(i)
    return

When I print i, I end up with a huge list of stuff like this ranging from 0 - 15 with about 5 different y-values per x-value:

[14.9929171, 21.0]
[14.9929171, 21.0]
[14.9929171, 20.0]
[14.9929171, 31.0]
[14.9929171, 25.0]
[14.9929171, 21.0]
[14.9929171, 18.0]
[14.9967165, 22.0]
[14.9967165, 26.0]

How do I access the lists [x,y] within the time_dependent_intensities list but only plot the ones that have the largest y value.

1 Answers1

0

If you have a list of lists like this and you want to extract the maximum value of each list, a list expression is probably the most convenient option:

list_ = [[15, 10, 1, 18, 2],
         [1, 2, 10 , 15, 0],
         [15, 10, 1, 18, 2],
         [15, 10, 1, 18, 2],]

maxima = [max(x) for x in list_]
print(maxima)

>>> [18, 15, 18, 18]
Jan Joswig
  • 693
  • 5
  • 20