def test_boxplotDataframe(self): # if the ouput file already exists, remove it if os.path.exists(testFolder + 'boxplotDataframe.png'): os.remove(testFolder + 'boxplotDataframe.png') msmsPrecursorPerFeaturePerIntensity = rFunctions.readCsvFile( testFolder + 'msmsPrecursorPerFeaturePerIntensity.csv', sep=',') self.plots.boxplotDataframe(testFolder + 'boxplotDataframe.png', msmsPrecursorPerFeaturePerIntensity, width=400, height=400, title='feature and ms/ms per intensity', xlab='log 10 of intensity', ylab='# of MS/MS per feature') R.r['dev.off']() # if after this the ouput does not exist, fail the test if not os.path.exists(testFolder + 'boxplotDataframe.png'): self.fail( testFolder + 'boxplotDataframe.png does not exist. File not written out correctly' ) # remove the plot if os.path.exists(testFolder + 'boxplotDataframe.png'): os.remove(testFolder + 'boxplotDataframe.png')
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')
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')
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')
def test_boxplotDataframe(self): # if the ouput file already exists, remove it if os.path.exists(testFolder+'boxplotDataframe.png'): os.remove(testFolder+'boxplotDataframe.png') msmsPrecursorPerFeaturePerIntensity = rFunctions.readCsvFile(testFolder+'msmsPrecursorPerFeaturePerIntensity.csv', sep=',') self.plots.boxplotDataframe(testFolder+'boxplotDataframe.png', msmsPrecursorPerFeaturePerIntensity, width=400, height=400, title='feature and ms/ms per intensity', xlab = 'log 10 of intensity', ylab = '# of MS/MS per feature') R.r['dev.off']() # if after this the ouput does not exist, fail the test if not os.path.exists(testFolder+'boxplotDataframe.png'): self.fail(testFolder+'boxplotDataframe.png does not exist. File not written out correctly') # remove the plot if os.path.exists(testFolder+'boxplotDataframe.png'): os.remove(testFolder+'boxplotDataframe.png')
def test_barplot(self): # reading in a csv file, seperated by tabs into a matrix csvData = rFunctions.readCsvFile(testFolder+'feature_precursor.csv', head=True, sep='\t') # get the # precursors column and put it in a vector (R dataframe translate '#' to 'X.' and ' ' to '.' precursorVector = csvData[rFunctions.index(csvData, 'X..precursors')] precursTable = R.r['table'](precursorVector) # if the ouput file already exists, remove it if os.path.exists(testFolder+'test_barplot.png'): os.remove(testFolder+'test_barplot.png') self.plots.barplot(testFolder+'test_barplot.png', precursTable) R.r['dev.off']() if not os.path.exists(testFolder+'test_barplot.png'): self.fail(testFolder+'test_barplot.png does not exist. File not written out correctly') else: os.remove(testFolder+'test_barplot.png')
def test_barplot(self): # reading in a csv file, seperated by tabs into a matrix csvData = rFunctions.readCsvFile(testFolder + 'feature_precursor.csv', head=True, sep='\t') # get the # precursors column and put it in a vector (R dataframe translate '#' to 'X.' and ' ' to '.' precursorVector = csvData[rFunctions.index(csvData, 'X..precursors')] precursTable = R.r['table'](precursorVector) # if the ouput file already exists, remove it if os.path.exists(testFolder + 'test_barplot.png'): os.remove(testFolder + 'test_barplot.png') self.plots.barplot(testFolder + 'test_barplot.png', precursTable) R.r['dev.off']() if not os.path.exists(testFolder + 'test_barplot.png'): self.fail( testFolder + 'test_barplot.png does not exist. File not written out correctly' ) else: os.remove(testFolder + 'test_barplot.png')
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')
def test_readCsvFile(self): self.assertIsInstance( rFunctions.readCsvFile(testFolder + 'feature.csv'), R.vectors.DataFrame)
def test_readCsvFile(self): self.assertIsInstance(rFunctions.readCsvFile(testFolder+'feature.csv'), R.vectors.DataFrame)