| 1 |
.. code-block:: python |
| 2 |
|
| 3 |
#!/usr/bin/env python |
| 4 |
import sys |
| 5 |
import pymzml |
| 6 |
|
| 7 |
|
| 8 |
def main(mzml_file): |
| 9 |
""" |
| 10 |
Basic example script to demonstrate the usage of pymzML. Requires a mzML |
| 11 |
file as first argument. |
| 12 |
|
| 13 |
usage: |
| 14 |
|
| 15 |
./simple_parser.py <path_to_mzml_file> |
| 16 |
|
| 17 |
Note: |
| 18 |
|
| 19 |
This script uses the new syntax with the MS level being a property of |
| 20 |
the spectrum class ( Spectrum.ms_level ). The old syntax can be found in |
| 21 |
the script simple_parser_v2.py where the MS level can be queried as a key |
| 22 |
(Spectrum['ms level']) |
| 23 |
|
| 24 |
|
| 25 |
""" |
| 26 |
i = 0 |
| 27 |
run = pymzml.run.Reader(mzml_file) |
| 28 |
for n, spec in enumerate(run): |
| 29 |
print( |
| 30 |
"Spectrum {0}, MS level {ms_level}".format( |
| 31 |
spec["id"], |
| 32 |
ms_level=spec["ms level"], |
| 33 |
# scan_time = spec['scan_time'] |
| 34 |
), |
| 35 |
end="\r", |
| 36 |
) |
| 37 |
i = sum(spec.i) |
| 38 |
print("Parsed {0} spectra from file {1}".format(n, mzml_file)) |
| 39 |
print() |
| 40 |
|
| 41 |
|
| 42 |
if __name__ == "__main__": |
| 43 |
if len(sys.argv) < 2: |
| 44 |
print(main.__doc__) |
| 45 |
exit() |
| 46 |
mzml_file = sys.argv[1] |
| 47 |
main(mzml_file) |