Exemplo n.º 1
0
    def test_compareCoordinate(self):
        expectedCsvRead = [
            'id', '# precursors\r\nf_43922326584371237334',
            '1\r\nf_130205234428175237334', '0\r\nf_8613715360396561740',
            '0\r\nf_13020522388175237334', '1\r\n'
        ]  # this is the expected output of reading the output csv file
        expectedReturnValue = {
            'totalPrecursorsInFeatures': 2,
            'averagePrecursorsInFeatures': 0.5,
            'featPerPrecursorDict': {
                'f_13020522388175237334': 1,
                'f_130205234428175237334': 0,
                'f_43922326584371237334': 1,
                'f_8613715360396561740': 0
            }
        }

        # to make sure that the test isn't passing when the method doesn't work, but the file already exists
        # the file is deleted at the beginning of the test rather than at the end, because user might want to check how an example output file looks
        if os.path.exists(testFolder + 'testPrecursorPerFeature.csv'):
            os.remove(testFolder + 'testPrecursorPerFeature.csv')

        actualReturnValue = compare.compareCoordinate(
            testFolder + 'mzml_test_file_1.mzML',
            testFolder + 'featurexmlTestFile_1.featureXML', True,
            testFolder + 'testPrecursorPerFeature.csv')
        csvFile = open(testFolder + 'testPrecursorPerFeature.csv')
        csvRead = csvFile.read().split('\t')

        self.assertDictEqual(expectedReturnValue, actualReturnValue)
        self.assertListEqual(expectedCsvRead, csvRead)

        if os.path.exists(testFolder + 'testPrecursorPerFeature.csv'):
            os.remove(testFolder + 'testPrecursorPerFeature.csv')
Exemplo n.º 2
0
 def test_precursorPerFeatureCsvWriter(self):
     expectedFirstLine = ['id', '# precursors\r\n'] 
     expectedSecondLine = {'f_43922326584371237334': 1, 'f_8613715360396561740': 0, 'f_13020522388175237334': 1}
     
     if os.path.exists(testFolder+'featPerPrecursorCsvTest.csv'):
         os.remove(testFolder+'featPerPrecursorCsvTest.csv') # to make sure that the test isn't passing when the method doesn't work, but the file already exists
     msrun = pymzml.run.Reader(testFolder+'mzml_test_file_1.mzML')
     precursPerFeature = compare.compareCoordinate(testFolder+'mzml_test_file_1.mzML', testFolder+'featurexmlTestFile_1.featureXML')['featPerPrecursorDict']    # see compareFeatureXMLmzML.py for details
     writer = output.CompareDataWriter(testFolder+'featPerPrecursorCsvTest.csv')
     writer.precursorPerFeatureCsvWriter(precursPerFeature)
     csvFile =  open(testFolder+'featPerPrecursorCsvTest.csv')
     actualFirstLine = csvFile.readline().split('\t')
     actualSecondLine = csvFile.readline().split('\t')
     os.remove(testFolder+'featPerPrecursorCsvTest.csv')
Exemplo n.º 3
0
 def test_compareCoordinate(self):
     expectedCsvRead = ['id','# precursors\r\nf_43922326584371237334','1\r\nf_130205234428175237334','0\r\nf_8613715360396561740','0\r\nf_13020522388175237334','1\r\n']     # this is the expected output of reading the output csv file
     expectedReturnValue = {'totalPrecursorsInFeatures':2, 'averagePrecursorsInFeatures':0.5, 'featPerPrecursorDict':{'f_13020522388175237334': 1, 'f_130205234428175237334': 0, 'f_43922326584371237334': 1, 'f_8613715360396561740': 0}}
     
     # to make sure that the test isn't passing when the method doesn't work, but the file already exists
     # the file is deleted at the beginning of the test rather than at the end, because user might want to check how an example output file looks
     if os.path.exists(testFolder+'testPrecursorPerFeature.csv'): 
         os.remove(testFolder+'testPrecursorPerFeature.csv') 
         
     actualReturnValue = compare.compareCoordinate(testFolder+'mzml_test_file_1.mzML', testFolder+'featurexmlTestFile_1.featureXML', True, testFolder+'testPrecursorPerFeature.csv')
     csvFile =  open(testFolder+'testPrecursorPerFeature.csv')        
     csvRead = csvFile.read().split('\t')
     
     
     self.assertDictEqual(expectedReturnValue, actualReturnValue)
     self.assertListEqual(expectedCsvRead, csvRead)
     
     if os.path.exists(testFolder+'testPrecursorPerFeature.csv'): 
         os.remove(testFolder+'testPrecursorPerFeature.csv') 
Exemplo n.º 4
0
    def test_precursorPerFeatureCsvWriter(self):
        expectedFirstLine = ['id', '# precursors\r\n']
        expectedSecondLine = {
            'f_43922326584371237334': 1,
            'f_8613715360396561740': 0,
            'f_13020522388175237334': 1
        }

        if os.path.exists(testFolder + 'featPerPrecursorCsvTest.csv'):
            os.remove(
                testFolder + 'featPerPrecursorCsvTest.csv'
            )  # to make sure that the test isn't passing when the method doesn't work, but the file already exists
        msrun = pymzml.run.Reader(testFolder + 'mzml_test_file_1.mzML')
        precursPerFeature = compare.compareCoordinate(
            testFolder + 'mzml_test_file_1.mzML',
            testFolder + 'featurexmlTestFile_1.featureXML'
        )['featPerPrecursorDict']  # see compareFeatureXMLmzML.py for details
        writer = output.CompareDataWriter(testFolder +
                                          'featPerPrecursorCsvTest.csv')
        writer.precursorPerFeatureCsvWriter(precursPerFeature)
        csvFile = open(testFolder + 'featPerPrecursorCsvTest.csv')
        actualFirstLine = csvFile.readline().split('\t')
        actualSecondLine = csvFile.readline().split('\t')
        os.remove(testFolder + 'featPerPrecursorCsvTest.csv')