| 1 |
.. code-block:: python |
| 2 |
|
| 3 |
#!/usr/bin/env python |
| 4 |
|
| 5 |
import pymzml |
| 6 |
from collections import defaultdict as ddict |
| 7 |
import os |
| 8 |
|
| 9 |
|
| 10 |
def main(): |
| 11 |
""" |
| 12 |
Testscript to isolate the n-highest peaks from an example file. |
| 13 |
|
| 14 |
Usage: |
| 15 |
|
| 16 |
./highest_peaks.py |
| 17 |
|
| 18 |
Parses the file '../tests/data/example.mzML' and extracts the 2 highest |
| 19 |
intensities from each spectrum. |
| 20 |
|
| 21 |
""" |
| 22 |
example_file = os.path.join( |
| 23 |
os.path.dirname(__file__), os.pardir, "tests", "data", "example.mzML" |
| 24 |
) |
| 25 |
run = pymzml.run.Reader(example_file) |
| 26 |
highest_i_dict = ddict(list) |
| 27 |
|
| 28 |
number_of_peaks_to_extract = 2 |
| 29 |
|
| 30 |
for spectrum in run: |
| 31 |
# print( spectrum.ID ) |
| 32 |
if spectrum.ms_level == 1: |
| 33 |
for mz, i in spectrum.highest_peaks(number_of_peaks_to_extract): |
| 34 |
highest_i_dict[spectrum.ID].append(i) |
| 35 |
for spectrum_id, highest_peak_list in highest_i_dict.items(): |
| 36 |
assert len(highest_peak_list) == number_of_peaks_to_extract |
| 37 |
print( |
| 38 |
"Spectrum {0}; highest intensities: {1}".format( |
| 39 |
spectrum_id, highest_peak_list |
| 40 |
) |
| 41 |
) |
| 42 |
|
| 43 |
|
| 44 |
if __name__ == "__main__": |
| 45 |
main() |