File: plot_spectrum.py

package info (click to toggle)
python-pymzml 2.5.2%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,792 kB
  • sloc: python: 6,495; pascal: 341; makefile: 233; sh: 30
file content (57 lines) | stat: -rwxr-xr-x 1,506 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

import pymzml


def main():
    """
    This function shows how to plot a simple spectrum. It can be directly
    plotted via this script or using the python console.

    usage:

        ./plot_spectrum.py

    """

    example_file = os.path.join(
        os.path.dirname(__file__), os.pardir, "tests", "data", "example.mzML"
    )
    run = pymzml.run.Reader(example_file)
    p = pymzml.plot.Factory()
    for spec in run:
        p.new_plot()
        p.add(spec.peaks("centroided"), color=(0, 0, 0), style="sticks", name="peaks")
        filename = "example_plot_{0}_{1}.html".format(
            os.path.basename(example_file), spec.ID
        )
        p.save(
            filename=filename,
            layout={
                "xaxis":{
                    "ticks": 'outside',
                    "ticklen": 2,
                    "tickwidth": 0.25,
                    "showgrid": False,
                    "linecolor": 'black',
                }, 
                "yaxis": {
                    "ticks": 'outside',
                    "ticklen": 2,
                    "tickwidth": 0.25,
                    "showgrid": False,
                    "linecolor": 'black',
                },
                "plot_bgcolor": 'rgba(255, 255, 255, 0)',
                "paper_bgcolor": 'rgba(255, 255, 255, 0)',
            },
        )
        print("Plotted file: {0}".format(filename))
        break


if __name__ == "__main__":
    main()