示例#1
0
    def test_histogram(self):
        ###TEST 1 HISTOGRAM###
        # if the ouput file already exists, remove it
        if os.path.exists(testFolder + 'test_histogram.png'):
            os.remove(testFolder + 'test_histogram.png')

        # reading in a csv file, seperated by tabs into a matrix
        csvData = rFunctions.readCsvFile(testFolder + 'feature.csv',
                                         sep='\t',
                                         head=True,
                                         na='N/A')
        # get only the rows with unique ids and put it in a new matrix
        csvUniqID = rFunctions.getRowsWithUniqColumn(csvData, 'id')
        # get a vector of all intensities using the index function from R_functions
        intensityVector = csvData[rFunctions.index(csvUniqID, 'intensity')]
        logIntensityVector = rFunctions.takeLog(intensityVector, 10)

        # using all possible **kwargs arguments to test if they are all parsed correctly
        self.plots.histogram(testFolder + 'test_histogram.png',
                             logIntensityVector,
                             plotArgs={'labels': True},
                             width=400,
                             height=400,
                             title='test #features per intensity',
                             ylab='# of test features')
        # if after this the ouput does not exist, fail the test
        if not os.path.exists(testFolder + 'test_histogram.png'):
            self.fail(
                testFolder +
                'test_histogram.png does not exist. File not written out correctly'
            )
        else:
            os.remove(testFolder + 'test_histogram.png')

        ###TEST 3 HISTOGRAMS
        # if the test doesn't give an error it succeeded
        if os.path.exists(testFolder + 'testOverlapHistogram.png'):
            os.remove(
                testFolder + 'testOverlapHistogram.png'
            )  # to make sure that the test isn't passing when the method doesn't work, but the file already exists
        outpng = testFolder + 'testOverlapHistogram.png'
        vector1 = R.IntVector((0, 2, 2, 3, 3, 3, 4, 4, 5))
        vector2 = R.IntVector((2, 4, 4, 5, 5, 5, 6, 6, 7))
        vector3 = R.IntVector((4, 6, 6, 7, 7, 7, 8, 8, 9))
        plots = rPlots.Plots()
        plots.histogram(outpng, vector1, vector2, vector3)
        R.r['dev.off']()
        if os.path.exists(testFolder + 'testOverlapHistogram.png'):
            os.remove(testFolder + 'testOverlapHistogram.png')
示例#2
0
 def test_takeLog(self):
     # because of rounding issues after 7 numbers after the comma I round both expected and actual to an int
     expectedLogVector = R.IntVector((5.0, 5.0, 4.0, 5.0, 5.0, 5.0, 3.0, 5.0))
     expectedLogList = []
     # you can't compare vectors directly because this part >> Python:0x12241f80 << is always different, I transform them to lists first
     for value in expectedLogVector:
         expectedLogList.append(value)
     
     vector = R.IntVector((59843, 34982, 12425, 90534, 34532, 54642, 1239, 43534))
     actualLogVector = R.r['round'](rFunctions.takeLog(vector, 10))
     actualLogList = []
     for value in actualLogVector:
         actualLogList.append(value)
     
     self.assertEqual(expectedLogList, actualLogList)
示例#3
0
    def test_takeLog(self):
        # because of rounding issues after 7 numbers after the comma I round both expected and actual to an int
        expectedLogVector = R.IntVector(
            (5.0, 5.0, 4.0, 5.0, 5.0, 5.0, 3.0, 5.0))
        expectedLogList = []
        # you can't compare vectors directly because this part >> Python:0x12241f80 << is always different, I transform them to lists first
        for value in expectedLogVector:
            expectedLogList.append(value)

        vector = R.IntVector(
            (59843, 34982, 12425, 90534, 34532, 54642, 1239, 43534))
        actualLogVector = R.r['round'](rFunctions.takeLog(vector, 10))
        actualLogList = []
        for value in actualLogVector:
            actualLogList.append(value)

        self.assertEqual(expectedLogList, actualLogList)
示例#4
0
    def test_boxplotFormulae(self):
        # if the ouput file already exists, remove it
        if os.path.exists(testFolder + 'boxplotFormulae.png'):
            os.remove(testFolder + 'boxplotFormulae.png')

        featDataframe = rFunctions.readCsvFile(testFolder + 'feature.csv')
        featDataframeUniq = rFunctions.getRowsWithUniqColumn(
            featDataframe, 'id')
        precursorPerFeatureDataframe = rFunctions.readCsvFile(
            testFolder + 'feature_precursor.csv', head=True, sep='\t')
        mergedFeatureDataframe = R.r['merge'](featDataframeUniq,
                                              precursorPerFeatureDataframe)
        mergedFeatureDataframe[rFunctions.index(
            mergedFeatureDataframe,
            'intensity')] = R.r['round'](rFunctions.takeLog(
                featDataframeUniq[rFunctions.index(featDataframeUniq,
                                                   'intensity')], 10))
        vector1 = mergedFeatureDataframe[rFunctions.index(
            mergedFeatureDataframe, 'X..precursors')]
        vector2 = mergedFeatureDataframe[rFunctions.index(
            mergedFeatureDataframe, 'intensity')]

        self.plots.boxplotFormulae(testFolder + 'boxplotFormulae.png',
                                   vector1,
                                   vector2,
                                   mergedFeatureDataframe,
                                   title='MS/MS per feature per intensity',
                                   ylab='# of MS/MS per feature',
                                   xlab='Rounded log10 of intensity')
        R.r['dev.off']()
        # if after this the ouput does not exist, fail the test
        if not os.path.exists(testFolder + 'boxplotFormulae.png'):
            self.fail(
                testFolder +
                'boxplotFormulae.png does not exist. File not written out correctly'
            )
        # remove the plot
        if os.path.exists(testFolder + 'boxplotFormulae.png'):
            os.remove(testFolder + 'boxplotFormulae.png')
示例#5
0
    def test_histogram(self):
        ###TEST 1 HISTOGRAM###
        # if the ouput file already exists, remove it
        if os.path.exists(testFolder+'test_histogram.png'):
            os.remove(testFolder+'test_histogram.png')
            
        # reading in a csv file, seperated by tabs into a matrix
        csvData = rFunctions.readCsvFile(testFolder+'feature.csv', sep = '\t', head=True, na='N/A')
        # get only the rows with unique ids and put it in a new matrix
        csvUniqID = rFunctions.getRowsWithUniqColumn(csvData, 'id')      
        # get a vector of all intensities using the index function from R_functions
        intensityVector = csvData[rFunctions.index(csvUniqID, 'intensity')]
        logIntensityVector = rFunctions.takeLog(intensityVector, 10)

        # using all possible **kwargs arguments to test if they are all parsed correctly
        self.plots.histogram(testFolder+'test_histogram.png', logIntensityVector, plotArgs={'labels':True}, width=400, height=400, title='test #features per intensity',  ylab = '# of test features')
        # if after this the ouput does not exist, fail the test
        if not os.path.exists(testFolder+'test_histogram.png'):
            self.fail(testFolder+'test_histogram.png does not exist. File not written out correctly')
        else:
            os.remove(testFolder+'test_histogram.png')


        ###TEST 3 HISTOGRAMS
        # if the test doesn't give an error it succeeded
        if os.path.exists(testFolder+'testOverlapHistogram.png'):
            os.remove(testFolder+'testOverlapHistogram.png') # to make sure that the test isn't passing when the method doesn't work, but the file already exists
        outpng = testFolder+'testOverlapHistogram.png'
        vector1 = R.IntVector((0,2,2,3,3,3,4,4,5))
        vector2 = R.IntVector((2,4,4,5,5,5,6,6,7))
        vector3 = R.IntVector((4,6,6,7,7,7,8,8,9))
        plots = rPlots.Plots()
        plots.histogram(outpng,vector1,vector2,vector3)
        R.r['dev.off']()
        if os.path.exists(testFolder+'testOverlapHistogram.png'):
            os.remove(testFolder+'testOverlapHistogram.png')
示例#6
0
    def test_boxplotFormulae(self):
        # if the ouput file already exists, remove it
        if os.path.exists(testFolder+'boxplotFormulae.png'):
            os.remove(testFolder+'boxplotFormulae.png')
            
        featDataframe = rFunctions.readCsvFile(testFolder+'feature.csv')
        featDataframeUniq = rFunctions.getRowsWithUniqColumn(featDataframe, 'id')
        precursorPerFeatureDataframe = rFunctions.readCsvFile(testFolder+'feature_precursor.csv', head=True, sep='\t')
        mergedFeatureDataframe = R.r['merge'](featDataframeUniq, precursorPerFeatureDataframe)
        mergedFeatureDataframe[rFunctions.index(mergedFeatureDataframe, 'intensity')] = R.r['round'](rFunctions.takeLog(featDataframeUniq[rFunctions.index(featDataframeUniq, 'intensity')], 10))
        vector1 = mergedFeatureDataframe[rFunctions.index(mergedFeatureDataframe, 'X..precursors')]
        vector2 = mergedFeatureDataframe[rFunctions.index(mergedFeatureDataframe,'intensity')]

        self.plots.boxplotFormulae(testFolder+'boxplotFormulae.png', vector1, vector2, mergedFeatureDataframe, 
                                title = 'MS/MS per feature per intensity', ylab = '# of MS/MS per feature', xlab = 'Rounded log10 of intensity')
        R.r['dev.off']() 
        # if after this the ouput does not exist, fail the test
        if not os.path.exists(testFolder+'boxplotFormulae.png'):
            self.fail(testFolder+'boxplotFormulae.png does not exist. File not written out correctly')
        # remove the plot
        if os.path.exists(testFolder+'boxplotFormulae.png'):
            os.remove(testFolder+'boxplotFormulae.png')