| 1 |
.. code-block:: python |
| 2 |
|
| 3 |
#!/usr/bin/env python |
| 4 |
# -*- coding: utf-8 -*- |
| 5 |
|
| 6 |
import os |
| 7 |
import sys |
| 8 |
|
| 9 |
import pymzml |
| 10 |
from pymzml.plot import Factory |
| 11 |
|
| 12 |
|
| 13 |
def main(mzml_file): |
| 14 |
""" |
| 15 |
Plots a chromatogram for the given mzML file. File is saved as |
| 16 |
'chromatogram_<mzml_file>.html'. |
| 17 |
|
| 18 |
usage: |
| 19 |
|
| 20 |
./plot_chromatogram.py <path_to_mzml_file> |
| 21 |
|
| 22 |
""" |
| 23 |
run = pymzml.run.Reader(mzml_file) |
| 24 |
mzml_basename = os.path.basename(mzml_file) |
| 25 |
pf = Factory() |
| 26 |
pf.new_plot() |
| 27 |
pf.add(run["TIC"].peaks(), color=(0, 0, 0), style="lines", title=mzml_basename) |
| 28 |
pf.save( |
| 29 |
"chromatogram_{0}.html".format(mzml_basename), |
| 30 |
layout={"xaxis": {"title": "Retention time"}, "yaxis": {"title": "TIC"}}, |
| 31 |
) |
| 32 |
return |
| 33 |
|
| 34 |
|
| 35 |
if __name__ == "__main__": |
| 36 |
if len(sys.argv) < 2: |
| 37 |
print(main.__doc__) |
| 38 |
exit() |
| 39 |
mzml_file = sys.argv[1] |
| 40 |
main(mzml_file) |