Esempio n. 1
0
 def test_read_mzxml_ramped(self):
     mde = magma.MsDataEngine(self.db_session, 1, 1000, 5, 0.001, 0.005, 3)
     mzxml_file = pkg_resources.resource_filename(
         'magma', "tests/ramped_collision_data.mzXML")
     mde.store_mzxml_file(mzxml_file)
     scandata = self.db_session.query(Scan).count()
     self.assertEqual(scandata, 2)
Esempio n. 2
0
 def test_read_mzxml(self):
     mde = magma.MsDataEngine(self.db_session, -1, 10000, 5, 0.001, 0.005, 3)
     mzxml_file=pkg_resources.resource_filename('magma', "tests/theogallin.mzXML")
     mde.store_mzxml_file(mzxml_file)
     with self.assertRaises(DataProcessingError) as cm:
         mde.store_mzxml_file(mzxml_file)
     self.assertEqual(str(cm.exception), 'Attempt to read MS data twice')
     scandata = self.db_session.query(Scan).count()
     self.assertEqual(scandata,4)
     ae = magma.AnnotateEngine(self.db_session,0,3,1,0,5,0)
     ae.build_spectra()
Esempio n. 3
0
    def test_store_manual_tree_unallowed_element(self):
        mde = magma.MsDataEngine(self.db_session, -1, 1000, 5, 0.001, 0.005, 3)
        # create corrupt manual tree file
        import tempfile, os
        treefile = tempfile.NamedTemporaryFile(delete=False)
        treefile.write('C6H5At: 999 (C6H5: 1000, At: 100)')
        treefile.close()

        with self.assertRaises(FileFormatError) as cm:
            mde.store_manual_tree(treefile.name,-1)

        self.assertEqual(str(cm.exception), 'Element not allowed in formula tree: At')

        os.remove(treefile.name)
Esempio n. 4
0
 def test_generate_ions(self):
     mde = magma.MsDataEngine(self.db_session, 1, 1000, 5, 0.001, 0.005, 3)
     ae = magma.AnnotateEngine(self.db_session,
                               False,
                               3,
                               1,
                               0,
                               5,
                               True,
                               adducts='Na,K')
     self.assertIsInstance(ae, magma.AnnotateEngine)
     self.assertEqual(ae.ions, [{
         0: '[M]+'
     }, {
         1.0078250321: '[M+H]+',
         22.9897692809: '[M+Na]+',
         38.96370668: '[M+K]+'
     }])
Esempio n. 5
0
    def test_it(self):
        molblock = """Theogallin
  Mrv0541 05061310592D

 24 25  0  0  0  0            999 V2000
    5.0013    2.0625    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.5724    2.0625    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.0013    6.1875    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.7158    4.9500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.2868    2.4750    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.0013    1.2375    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.5724    1.2375    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.2868    5.7750    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.0013    4.5375    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.2868    0.8250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.2868    4.9500    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.2868    3.3000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.1530    6.4746    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.7158    5.7750    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.7158    0.8250    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    2.8579    0.8250    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.5724    6.1875    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    4.2868    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.5724    4.5375    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.5724    3.7125    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    5.7656    7.2031    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    6.9774    6.4458    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    6.5403    5.8038    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    5.0013    3.7125    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
  5  1  2  0  0  0  0
  5  2  1  0  0  0  0
  6  1  1  0  0  0  0
  7  2  2  0  0  0  0
  8  3  1  0  0  0  0
  9  4  1  0  0  0  0
 10  6  2  0  0  0  0
 10  7  1  0  0  0  0
 11  8  1  0  0  0  0
 11  9  1  0  0  0  0
 12  5  1  0  0  0  0
 14  3  1  0  0  0  0
 14  4  1  0  0  0  0
 14 13  1  0  0  0  0
 15  6  1  0  0  0  0
 16  7  1  0  0  0  0
 17  8  1  0  0  0  0
 18 10  1  0  0  0  0
 19 11  1  0  0  0  0
 20 12  2  0  0  0  0
 21 13  2  0  0  0  0
 22 13  1  0  0  0  0
 23 14  1  0  0  0  0
 24  9  1  0  0  0  0
 24 12  1  0  0  0  0
M  END
"""

        class Stub(object):
            pass

        # search_structure gets called by pp.Server.submit
        # submit will import modules, during test we have do the same
        import magma.pars as pars
        import magma.types as types
        import magma.fragmentation_cy as fragcy
        import magma.fragmentation_py as fragpy
        magma.magma = Stub()
        magma.magma.pars = pars
        magma.magma.types = types
        magma.magma.fragmentation_cy = fragcy
        magma.magma.fragmentation_py = fragpy

        magma.MsDataEngine(self.db_session, 1, 10000, 5, 0.001, 0.005, 5)
        ae = magma.AnnotateEngine(self.db_session,
                                  False,
                                  3,
                                  1,
                                  0,
                                  5,
                                  True,
                                  adducts='Na,K')
        mol = Chem.MolFromMolBlock(molblock)
        mim = 344.07434673460006
        molcharge = 1
        # TODO fill peaks
        peaks = []
        fast = False

        result = magma.search_structure(mol, mim, molcharge, peaks,
                                        ae.max_broken_bonds,
                                        ae.max_water_losses, ae.precision,
                                        ae.mz_precision_abs, ae.use_all_peaks,
                                        ae.ionisation_mode,
                                        ae.skip_fragmentation, fast, ae.ions)

        self.assertEqual(result, ([], 0))
Esempio n. 6
0
    def test_store_manual_subtree_corrupt_endlessloop(self):
        mde = magma.MsDataEngine(self.db_session, 1, 1000, 5, 0.001, 0.005, 3)
        # create corrupt manual tree file
        import tempfile, os
        treefile = tempfile.NamedTemporaryFile(mode='w', delete=False)
        treefile.write("""320.2: 999 (
    123.12    1
    135.2    3
    139.2    3
    145.18    2
    147.04    1
    149.136    39
    149.92    1
    150.32    2
    150.56    1
    150.88    1
    151.28    1
    153.36    1
    155.04    2
    155.296    2
    159.1    1
    161.28    5
    162.64    1
    163.155    43
    167.145    230
    167.808    4
    168.4    5
    169.06    7
    169.68    1
    175.177    8
    175.52    1
    177.12    4
    179.114    92
    179.509    5
    179.74    1
    179.92    2
    180.168    5
    181.04    1
    181.44    1
    189.28    2
    191.12    1
    195.04    3
    195.28    2
    203.235    23
    203.44    3
    205.2    1
    205.68    1
    206.96    4
    207.2    4
    207.36    1
    208.088    13
    219.232    14
    220.88    1
    221.12    4
    223.28    1
    229.12    5
    257.283    254
    257.92    4
    258.32    2
    258.733    3
    259.32    1
    273.12    3
    275.268    97
    282.88    1
    283.23    4
    291.251    9
    291.52    3
    301.242    254
    302    3
    302.4    2
    319.155    999
    319.8    2
)
        """)
        treefile.close()

        with self.assertRaises(FileFormatError) as cm:
            mde.store_manual_tree(treefile.name, 0)

        self.assertEqual(str(cm.exception), 'Corrupt Tree format ...')

        os.remove(treefile.name)