File: test_readChromMzML.py

package info (click to toggle)
python-pymzml 0.7.6-dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 66,128 kB
  • ctags: 335
  • sloc: python: 2,428; makefile: 142; sh: 38
file content (86 lines) | stat: -rw-r--r-- 2,957 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3.2
# -*- coding: utf-8 -*-
# encoding: utf-8
#
# pymzml
#
# Copyright (C) 2010-2013 T. Bald, J. Barth, M. Specht, C. Fufezan, H. Roest
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest
import subprocess as sub
import os
from nose.tools import nottest
from nose.plugins.attrib import attr

import pymzml

class TestReadChromatogram(unittest.TestCase):

    def setUp(self):
        self.dirname = os.path.dirname(os.path.abspath(__file__))
        self.datadir = os.path.join(self.dirname, "data")
        self.mini_chrom_file = os.path.join(self.datadir, "mini.chrom.mzML")
        self.chromatogram_id = "4092_IEVLDYQAGDEAGIK/2_y7"
        # Second file
        self.mini_numpress_file = os.path.join(self.datadir, "mini_numpress.chrom.mzML")
        self.numpress_chrom_id = "some_test_id"

    def check_file(self, run):
        all_chromatograms = list(run)
        self.assertEqual(len(all_chromatograms), 3)

        chrom = run[self.chromatogram_id]

        self.assertEqual(len(chrom.peaks), 176)
        self.assertAlmostEqual(sum(chrom.i), 13374.0)

        self.assertAlmostEqual(chrom.i[0], 30.0)
        self.assertAlmostEqual(chrom.i[-1], 140.0)
        self.assertAlmostEqual(chrom.time[0], 3357.62)
        self.assertAlmostEqual(chrom.time[-1], 3955.05)

    def test_readfile(self):
        run = pymzml.run.Reader(self.mini_chrom_file)
        self.assertFalse(run.info['seekable'])

        self.check_file(run)

    def test_readfile_with_index(self):
        run = pymzml.run.Reader(self.mini_chrom_file, build_index_from_scratch=True)
        self.assertTrue(run.info['seekable'])

        self.check_file(run)

    @attr('numpress') 
    def test_read_numpress(self):
        run = pymzml.run.Reader(self.mini_numpress_file)
        self.assertFalse(run.info['seekable'])

        all_chromatograms = list(run)
        self.assertEqual(len(all_chromatograms), 1)

        chrom = run[self.numpress_chrom_id]

        self.assertEqual(len(chrom.peaks), 176)
        self.assertAlmostEqual(sum(chrom.i), 3657.0 )

        self.assertAlmostEqual(chrom.i[0], 0.0)
        self.assertAlmostEqual(chrom.i[-1], 28.0)
        self.assertAlmostEqual(chrom.time[0], 2302.530)
        self.assertAlmostEqual(chrom.time[-1], 2899.960000343)

if __name__ == '__main__':
    unittest.main()