def test_fillSpectrumException(self): mzMLinstance = pymzml.run.Reader( testFolder + 'mzml_test_file_1.mzML') # make a Reader instance with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(RuntimeError, fd.fillSpectrum, mzMLinstance) with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(RuntimeError, fd.fillSpectrum, mzMLinstance)
def test_fillMsrunException(self): with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') self.assertRaises(sqlite.IntegrityError, fd.fillMsrun, testFolder + 'mzml_test_file_1.mzML') with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(RuntimeError, fd.fillMsrun, testFolder + 'mzml_test_file_1.mzML')
def test_linkSpectrumToFeature(self): expectedNumResult = 4 expectedResult = [(1, 2), (1, 2), (1, 4), (1, 4)] mzMLinstance = pymzml.run.Reader( testFolder + 'mzml_test_file_1.mzML') # make a Reader instance featureXML = parseFeatureXML.Reader( testFolder + 'featurexmlTestFile_1.featureXML') # make a Reader instance with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.fillFeatures(featureXML) fd.fillSpectrum(mzMLinstance) fd.linkSpectrumToFeature() actualResult = [] self.cursor.execute("SELECT * FROM feature_has_MSMS_precursor") for result in self.cursor.fetchall(): actualResult.append(result) actualResult.append(result) self.assertEqual(expectedNumResult, len(actualResult)) self.assertListEqual(expectedResult, actualResult)
def test_fillMsrun(self): with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') self.cursor.execute("SELECT msrun_name FROM `msrun`") self.assertEqual(self.cursor.fetchone()[0], 'test') with database.ConnectMySQL('gjb-mysql-1.cluster.lifesci.dundee.ac.uk', 'ndeklein', 'm31th3amh4', 'test') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') self.mysql_cursor.execute("SELECT msrun_name FROM `msrun`") self.assertEqual(self.mysql_cursor.fetchone()[0], 'test')
def test_fillFeaturesException(self): featureXML = parseFeatureXML.Reader( testFolder + 'featurexmlTestFile_1.featureXML') # make a Reader instance with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(RuntimeError, fd.fillFeatures, featureXML)
def test_updateDescription(self): # updating from within the same instance with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.updateDescription('update from same instance') self.cursor.execute( "SELECT description FROM `msrun` WHERE msrun_name = 'test'") self.assertEqual(str(self.cursor.fetchone()[0]), 'update from same instance') with database.ConnectMySQL('gjb-mysql-1.cluster.lifesci.dundee.ac.uk', 'ndeklein', 'm31th3amh4', 'test') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.updateDescription('update from same instance') self.mysql_cursor.execute( "SELECT description FROM `msrun` WHERE msrun_name = 'test'") self.assertEqual(str(self.mysql_cursor.fetchone()[0]), 'update from same instance') # updating from within a different instance with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.updateDescription('update from different instance') self.cursor.execute( "SELECT description FROM `msrun` WHERE msrun_name = 'test'") self.assertEqual(str(self.cursor.fetchone()[0]), 'update from different instance') with database.ConnectMySQL('gjb-mysql-1.cluster.lifesci.dundee.ac.uk', 'ndeklein', 'm31th3amh4', 'test') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.updateDescription('update from different instance') self.mysql_cursor.execute( "SELECT description FROM `msrun` WHERE msrun_name = 'test'") self.assertEqual(str(self.mysql_cursor.fetchone()[0]), 'update from different instance')
def test_fillFeatureMappingException(self): featureXML = parseFeatureXML.Reader(testFolder + 'featurexmlTestFile_1.featureXML') featureXML_2 = parseFeatureXML.Reader( testFolder + 'featurexmlTestFile_2.featureXML') trafoXML = testFolder + 'featurexmlTestFile_2.trafoXML' with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(KeyError, fd.fillFeatureMapping, featureXML, featureXML_2, trafoXML)
def test_fillFeatureMapping(self): featureXML_1 = parseFeatureXML.Reader( testFolder + 'featurexmlTestFile_1.featureXML') featureXML_2 = parseFeatureXML.Reader( testFolder + 'featurexmlTestFile_2.featureXML') trafoXML = testFolder + 'featurexmlTestFile_2.trafoXML' with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.fillFeatures(featureXML_1) fd.fillFeatures(featureXML_2) fd.fillFeatureMapping(featureXML_1, featureXML_2, trafoXML)
def test_updatedDescriptionException(self): with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') # msrun_name test doesn't exist, should give RuntimeError self.assertRaises(RuntimeError, fd.updateDescription, 'test') # for next test, fill msrun fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') veryLongDescription = 'a' * 501 # description can be only 500 chars max self.assertRaises(TypeError, database.FillDatabase.updateDescription, 'test', veryLongDescription) self.connection.commit()
def test_fillSpectrum(self): expectedNumResult = 10 mzMLinstance = pymzml.run.Reader( testFolder + 'mzml_test_file_1.mzML', 'MS:1000527') # make a Reader instance actualResult = [] with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'None') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.fillSpectrum(mzMLinstance) self.cursor.execute("SELECT * FROM `spectrum`") for result in self.cursor.fetchall(): actualResult.append(result) self.assertEqual(expectedNumResult, len(actualResult))
def test_fillFeatures(self): expectedNumResult = 4 featureXML = parseFeatureXML.Reader( testFolder + 'featurexmlTestFile_1.featureXML') # make a Reader instance with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.fillFeatures(featureXML) actualResult = [] for feature in featureXML.getSimpleFeatureInfo(): self.cursor.execute("SELECT * FROM `feature` WHERE feature_id = ?", (str(featureXML['id']), )) actualResult.append(self.cursor.fetchone()) self.connection.commit() self.assertEqual(len(actualResult), expectedNumResult)
def test_fillMascot(self): expectedPeptideNumResult = 2 expectedPeptideResult = [(1,462.24009999999998,922.46569999999997, 2,923.45010000000002,-0.98440000000000005,1,20.309999999999999,75.0\ ,u'K',u'CDVDIRK',u'D',u'Label:13C(6)15N(2) (K); Label:13C(6)15N(4) (R)',u'0.0000065.0',None,u'462.240142822266_751.5624'\ ,3),(2,335.22239999999999,668.43029999999999,2,668.35339999999997,0.076899999999999996,0,12.720000000000001,400.0\ , None,u'FLDFK',None,None,None,None,u'335.222412109375_2270.0684',4)] expectedProtNumResult = 2 expectedProtResult = [(1, 462.24009999999998, 922.46569999999997, 2, 923.45010000000002, -0.98440000000000005, 1, 20.309999999999999, 75.0, u'K'\ , u'CDVDIRK', u'D', u'Label:13C(6)15N(2) (K); Label:13C(6)15N(4) (R)', u'0.0000065.0', None, u'462.240142822266_751.5624', 3) ,(2, 335.22239999999999, 668.43029999999999, 2, 668.35339999999997, 0.076899999999999996, 0, 12.720000000000001, 400.0, None\ , u'FLDFK', None, None, None, None, u'335.222412109375_2270.0684', 4)] mzMLinstance = pymzml.run.Reader( testFolder + 'mzml_test_file_1.mzML', 'MS:1000527') # make a Reader instance mascot = parseMascot.Reader(testFolder + 'test_mascot.xml') with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon, 'test') fd.fillMsrun(testFolder + 'mzml_test_file_1.mzML') fd.fillSpectrum(mzMLinstance) fd.fillMascot(mascot) actualPeptideResult = [] self.cursor.execute("SELECT * FROM `MASCOT_peptide`") for result in self.cursor.fetchall(): actualPeptideResult.append(result) actualProteinResult = [] self.cursor.execute("SELECT * FROM `MASCOT_protein`") for result in self.cursor.fetchall(): actualProteinResult.append(result) self.assertEqual(expectedPeptideNumResult, len(actualPeptideResult)) self.assertListEqual(expectedPeptideResult, actualPeptideResult) self.assertEqual(expectedProtNumResult, len(actualPeptideResult)) self.assertListEqual(expectedProtResult, actualPeptideResult)
def test_fillMascotException(self): mascot = parseMascot.Reader(testFolder + 'test_mascot.xml') with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(RuntimeError, fd.fillMascot, mascot)
def test_linkSpectrumToFeatureException(self): with database.ConnectSqlite(testDatabasePath + 'test_pyMSA_database.db') as sqlCon: fd = database.FillDatabase(sqlCon) self.assertRaises(RuntimeError, fd.linkSpectrumToFeature)