def test_singlereaction(self): """ 1 -1> 2 """ session = self.Session() session.add(Molecule(molid=1, nhits=1)) session.add(Molecule(molid=2, nhits=1)) session.add(Reaction(reactid=1, name=u'esterase', reactant=1, product=2)) session.flush() fill_molecules_reactions(session) expected1 = { u'products': { u'esterase': { u'nr': 1, u'nrp': 1 } } } self.assertDictEqual(self.getReactionSequence(1), expected1) expected2 = { u'reactants': { u'esterase': { u'nr': 1, u'nrp': 1 } } } self.assertDictEqual(self.getReactionSequence(2), expected2)
def test_noreactions(self): session = self.Session() session.add(Molecule(molid=1, nhits=1)) session.flush() fill_molecules_reactions(session) self.assertDictEqual(self.getReactionSequence(1), {})
def test_reactionson4molecules(self): """ 1 -1> 2 -3> 4 1 -2> 3 -4> 4 """ session = self.Session() session.add(Molecule(molid=1, nhits=1)) session.add(Molecule(molid=2, nhits=1)) session.add(Molecule(molid=3, nhits=0)) session.add(Molecule(molid=4, nhits=1)) session.add(Reaction(reactid=1, name=u'esterase', reactant=1, product=2)) session.add(Reaction(reactid=2, name=u'theogallin', reactant=1, product=3)) session.add(Reaction(reactid=3, name=u'dehydrox', reactant=2, product=4)) session.add(Reaction(reactid=4, name=u'reduc', reactant=3, product=4)) session.flush() fill_molecules_reactions(session) expected1 = { u'products': {u'esterase': {u'nr': 1, u'nrp': 1}, u'theogallin': {u'nr': 1}} } self.assertDictEqual(self.getReactionSequence(1), expected1) expected2 = { u'reactants': {u'esterase': {u'nr': 1, u'nrp': 1}}, u'products': {u'dehydrox': {u'nr': 1, u'nrp': 1}} } self.assertDictEqual(self.getReactionSequence(2), expected2) expected3 = { u'reactants': {u'theogallin': {u'nr': 1, u'nrp': 1}}, u'products': {u'reduc': {u'nr': 1, u'nrp': 1}} } self.assertDictEqual(self.getReactionSequence(3), expected3) expected4 = { u'reactants': {u'dehydrox': {u'nr': 1, u'nrp': 1}, u'reduc': {u'nr': 1}} } self.assertDictEqual(self.getReactionSequence(4), expected4)
def populateTestingDB(session): """Populates test db with data Adds 1 molecule with one fragment. Adds 1 molecule with one fragment which has 2 child fragments of which one has another child fragment. Run, Scan and Peak are filled to create a working run. session session connection to db """ url1 = u'<a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi' url1 += u'?cid=289">CID: 289</a>' url2 = u'<a href="http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi' url2 += u'?cid=152432">CID: 152432</a>' session.add(Run( ionisation_mode=-1, skip_fragmentation=True, ms_intensity_cutoff=200000.0, msms_intensity_cutoff=50, mz_precision=10, mz_precision_abs=0.002, use_all_peaks=True, ms_filename=u'F123456.mzxml', abs_peak_cutoff=1000, max_ms_level=3, precursor_mz_precision=10, max_broken_bonds=4, description=u'My first description', max_water_losses=1, )) session.add(Molecule( molid=72, mol=u'Molfile', refscore=1.0, reactionsequence={ u'reactantof': { u'esterase': { u'nr': 2, u'nrp': 1 } } }, smiles=u'C1=CC=C(C(=C1)O)O', inchikey14=u'YCIMNLLNPGFGHC', formula=u'C6H6O2', predicted=False, nhits=1, name=u'pyrocatechol', mim=110.03677, logp=1.231, reference=url1 )) session.add(Scan( scanid=641, mslevel=1, rt=933.317, lowmz=90.3916, highmz=1197.78, basepeakmz=305.034, basepeakintensity=807577.0, totioncurrent=5957620 )) session.add_all([ # basepeak Peak(scanid=641, mz=305.033508300781, intensity=807576.625), # peak of molecule Peak(scanid=641, mz=109.0295639038086, intensity=345608.65625) ]) session.add(Fragment( fragid=948, molid=72, scanid=641, mz=109.0295639038086, mass=110.0367794368, score=200, parentfragid=0, atoms=u"0,1,2,3,4,5,6,7", deltah=-1.0, deltappm=-1.84815979523607e-08, formula=u"C5H4", )) # fragments of molid=352 + scanid=870 session.add(Molecule( predicted=False, molid=352, mol=u"Molfile of dihydroxyphenyl-valerolactone", formula=u"C11H12O4", name=u"dihydroxyphenyl-valerolactone", refscore=1.0, reactionsequence={ u'productof': { u'theogallin': { u'nr': 1, u'nrp': 0 } } }, smiles=u"O=C1CCC(Cc2ccc(O)c(O)c2)O1", inchikey14=u'ZNXXWTPQHVLMQT', reference=url2, mim=208.07355, logp=2.763, nhits=1 )) session.add_all([Scan( scanid=870, mslevel=1, rt=1254.15, lowmz=91.0302, highmz=1171.51, basepeakmz=287.023, basepeakintensity=1972180.0, totioncurrent=9265290 ), Scan( scanid=871, mslevel=2, rt=1254.93, lowmz=51.5211, highmz=216.864, basepeakmz=163.076, basepeakintensity=279010.0, totioncurrent=809307, precursormz=207.0663147, precursorintensity=293096.0, precursorscanid=870 ), Scan( scanid=872, mslevel=3, rt=1256.77, lowmz=50.3338, highmz=172.155, basepeakmz=119.087, basepeakintensity=17387.0, totioncurrent=236842, precursormz=163.0762329, precursorintensity=6163.73, precursorscanid=871 )]) session.add_all([ # basepeak Peak(scanid=870, mz=287.022979736328, intensity=1972180.625), # peak of molecule Peak(scanid=870, mz=207.066284179688, intensity=293095.84375), # basepeak and peak of frag 1709 Peak(scanid=871, mz=163.076232910156, intensity=279010.28125), # peak of frag 1708 Peak(scanid=871, mz=123.04508972168, intensity=211603.046875), # basepeak and peak of frag 1710 Peak(scanid=872, mz=119.086540222168, intensity=17386.958984375), ]) session.add_all([Fragment( fragid=1707, molid=352, scanid=870, mass=208.0735588736, mz=207.066284179688, score=100, parentfragid=0, atoms=u"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14", deltah=-1, deltappm=-8.18675317722029e-09, formula=u"C3H5O3", ), Fragment( fragid=1708, molid=352, scanid=871, mass=123.0446044689, mz=123.04508972167969, score=201, parentfragid=1707, atoms=u"6,7,8,9,10,11,12,13,14", deltah=0, deltappm=3.943698856902144e-12, formula=u"C3H5O3", ), Fragment( fragid=1709, molid=352, scanid=871, mass=164.08372962939995, mz=163.07623291015625, score=65, parentfragid=1707, atoms=u"3,4,5,6,7,8,9,10,11,12,13,14", deltah=-1, deltappm=-1.235815738001507e-08, formula=u"C3H5O3", ), Fragment( fragid=1710, scanid=872, molid=352, mass=116.0626002568, mz=119.08654022216797, score=4, parentfragid=1709, atoms=u"4,5,6,7,8,9,11,13,14", deltah=3, deltappm=5.0781684060061766e-08, formula=u"C3H5O3", )]) session.flush()
def populateWithUseAllPeaks(session): """ Dataset with multiple fragments of same molecule on lvl1 scan """ session.add(Run( ionisation_mode=-1, skip_fragmentation=True, ms_intensity_cutoff=200000.0, msms_intensity_cutoff=50, mz_precision=10, mz_precision_abs=0.002, use_all_peaks=False, ms_filename=u'F123456.mzxml', abs_peak_cutoff=1000, max_ms_level=3, precursor_mz_precision=10, max_broken_bonds=4, description=u'My second description', max_water_losses=1, )) session.add(Molecule( molid=12, refscore=0.119004, reactionsequence=['sulfation_(aromatic_hydroxyl)'], smiles=u'Oc1ccc(CC2OC(=O)CC2)cc1OS(O)(=O)=O', inchikey14=u'YAXFVDUJDAQPTJ', formula=u'C11H12O7S', predicted=True, name=u'5-(3,4)-dihydroxyphenyl-g-valerolactone (F)', mol=u'Molfile', reference=u'', mim=288.0303734299, logp=1.9027, nhits=1 )) session.add_all([Scan( scanid=1, mslevel=1, rt=0.503165, lowmz=286.529, highmz=288.239, basepeakmz=287.023, basepeakintensity=39047000.0, totioncurrent=49605000.0, precursorscanid=0 ), Scan( scanid=2, mslevel=2, rt=0.544193333333333, lowmz=66.8575, highmz=288.026, basepeakmz=207.066, basepeakintensity=32485600.0, totioncurrent=42005700.0, precursormz=287.0231323, precursorintensity=39047000.0, precursorscanid=1 )]) session.add_all([Peak( scanid=1, mz=287.015686035156, intensity=1058332.875 ), Peak( scanid=1, mz=287.023132324219, intensity=39047040.0 ), Peak( scanid=2, mz=207.066223144531, intensity=32485624.0 ), Peak( scanid=2, mz=287.022827148438, intensity=6491798.0 )]) session.add_all([Fragment( fragid=17, molid=12, scanid=1, mz=287.015686035156, mass=288.0303734299, score=0.0, parentfragid=0, atoms=u'0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18', deltah=-1.0, deltappm=-7.046696487857745e-09, formula=u"C4H6O2", ), Fragment( fragid=18, molid=12, scanid=1, mz=287.023132324219, mass=288.0303734299, score=0.5, parentfragid=0, atoms=u'0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18', deltah=-1.0, deltappm=-7.020570507205176e-09, formula=u"C4H6O2", ), Fragment( fragid=19, molid=12, scanid=2, mz=207.066223144531, mass=207.0657338415, score=0.5, parentfragid=18, atoms=u'0,1,2,3,4,5,6,7,8,9,10,11,12,13,14', deltah=0.0, deltappm=2.3630267823129625e-12, formula=u"C4H6O2", ), Fragment( fragid=20, molid=12, scanid=2, mz=287.022827148438, mass=288.0303734299, score=0.0, parentfragid=18, atoms=u'0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18', deltah=-1.0, deltappm=-7.021641217476223e-09, formula=u"C4H6O2", )])