Skip to content

Commit

Permalink
updates to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesands committed Aug 8, 2024
1 parent c6cb56d commit b77f8c0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
5 changes: 4 additions & 1 deletion Tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,10 @@ class test_dataset_addsampleinfo(unittest.TestCase):

def setUp(self):
self.Data = nPYc.MSDataset(os.path.join('..','..','npc-standard-project','Derived_Data','UnitTest1_PCSOP.069_QI.csv'), fileType='QI')
self.Data.addSampleInfo(descriptionFormat='Filenames')
try:
self.Data.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored


def test_dataset_load_npc_lims(self):
Expand Down
26 changes: 20 additions & 6 deletions Tests/test_msdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,10 @@ class test_msdataset_import_QI(unittest.TestCase):
def setUp(self):

self.msData = nPYc.MSDataset(os.path.join('..','..','npc-standard-project','Derived_Data','UnitTest1_PCSOP.069_QI.csv'), fileType='QI')

self.msData.addSampleInfo(descriptionFormat='Filenames')
try:
self.msData.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored


def test_dimensions(self):
Expand Down Expand Up @@ -1883,10 +1885,16 @@ def setUp(self):
path = os.path.join('..','..','npc-standard-project','Derived_Data', 'UnitTest1_PCSOP.069_Metaboscape.xlsx')

self.lcData = nPYc.MSDataset(path, fileType='Metaboscape', noFeatureParams=18, sheetName='Test Data')
self.lcData.addSampleInfo(descriptionFormat='Filenames')
try:
self.lcData.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored

self.diData = nPYc.MSDataset(path, fileType='Metaboscape', noFeatureParams=16, sheetName='Test Data (DI)')
self.diData.addSampleInfo(descriptionFormat='Filenames')
try:
self.diData.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored


def test_dimensions(self):
Expand Down Expand Up @@ -2058,7 +2066,10 @@ def test_csv_import(self):
path = os.path.join('..','..','npc-standard-project','Derived_Data', 'UnitTest1_PCSOP.069_Metaboscape_LC.csv')

lcData = nPYc.MSDataset(path, fileType='Metaboscape', noFeatureParams=18)
lcData.addSampleInfo(descriptionFormat='Filenames')
try:
lcData.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored

assert_frame_equal(self.lcData.sampleMetadata, lcData.sampleMetadata)
numpy.testing.assert_array_equal(self.lcData.intensityData, lcData.intensityData)
Expand Down Expand Up @@ -2188,7 +2199,10 @@ class test_msdataset_addsampleinfo(unittest.TestCase):
def setUp(self):

self.msData = nPYc.MSDataset(os.path.join('..','..','npc-standard-project','Derived_Data','UnitTest1_PCSOP.069_QI.csv'), fileType='QI')
self.msData.addSampleInfo(descriptionFormat='Filenames')
try:
self.msData.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored


def test_msdataset_load_npc_lims(self):
Expand Down
24 changes: 18 additions & 6 deletions Tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def setUp(self):
self.msData = nPYc.MSDataset(
os.path.join('..', '..', 'npc-standard-project', 'Derived_Data', 'UnitTest1_PCSOP.069_QI.csv'),
fileType='QI')
self.msData.addSampleInfo(descriptionFormat='Filenames')
try:
self.msData.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored

self.msData.sampleMetadata['Correction Batch'] = 1
self.msData.sampleMetadata['Run Order'] = [i for i in range(1, self.msData.noSamples + 1)]
Expand Down Expand Up @@ -79,7 +82,10 @@ def setUp(self):
self.data = nPYc.MSDataset(
os.path.join('..', '..', 'npc-standard-project', 'Derived_Data', 'UnitTest1_PCSOP.069_QI.csv'),
fileType='QI')
self.data.addSampleInfo(descriptionFormat='Filenames')
try:
self.data.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored
self.data.addSampleInfo(descriptionFormat='Raw Data',
filePath=os.path.join('..', '..', 'npc-standard-project', 'Raw_Data', 'ms',
'parameters_data'))
Expand Down Expand Up @@ -141,7 +147,7 @@ def test_report_samplesummary_postexclusion(self):
assert sampleSummary['Acquired'].loc['Long-Term Reference', 'Total'] == 1
assert sampleSummary['Acquired'].loc['Serial Dilution', 'Total'] == 92
assert sampleSummary['Acquired'].loc['Blank', 'Total'] == 2
assert 'Unspecified SampleType or AssayRole' not in sampleSummary['Acquired'].index
assert sampleSummary['Acquired'].loc['Unknown', 'Total'] == 0

# Acquired - Marked for exclusion
assert sampleSummary['Acquired'].loc['All', 'Marked for Exclusion'] == 0
Expand All @@ -150,14 +156,16 @@ def test_report_samplesummary_postexclusion(self):
assert sampleSummary['Acquired'].loc['Long-Term Reference', 'Marked for Exclusion'] == 0
assert sampleSummary['Acquired'].loc['Serial Dilution', 'Marked for Exclusion'] == 0
assert sampleSummary['Acquired'].loc['Blank', 'Marked for Exclusion'] == 0
assert sampleSummary['Acquired'].loc['Unknown', 'Marked for Exclusion'] == 0

# Acquired - Already Excluded
assert sampleSummary['Acquired'].loc['All', 'Missing/Excluded'] == 3
assert sampleSummary['Acquired'].loc['Study Sample', 'Missing/Excluded'] == 3
assert sampleSummary['Acquired'].loc['All', 'Missing/Excluded'] == 5
assert sampleSummary['Acquired'].loc['Study Sample', 'Missing/Excluded'] == 4
assert sampleSummary['Acquired'].loc['Study Reference', 'Missing/Excluded'] == 0
assert sampleSummary['Acquired'].loc['Long-Term Reference', 'Missing/Excluded'] == 0
assert sampleSummary['Acquired'].loc['Serial Dilution', 'Missing/Excluded'] == 0
assert sampleSummary['Acquired'].loc['Blank', 'Missing/Excluded'] == 0
assert sampleSummary['Acquired'].loc['Unknown', 'Missing/Excluded'] == 1


class test_reports_nmr_generatereport(unittest.TestCase):
Expand Down Expand Up @@ -466,6 +474,7 @@ def setUp(self):
'SampleType': [SampleType.StudySample,
SampleType.StudySample,
SampleType.StudySample],
'SampleClass': ['Study Sample', 'Study Sample', 'Study Sample'],
'Dilution': [numpy.nan, numpy.nan, numpy.nan],
'Correction Batch': [numpy.nan, numpy.nan, numpy.nan],
'Subject ID': ['', '', ''], 'Sample ID': ['', '', ''],
Expand Down Expand Up @@ -879,7 +888,10 @@ def test_reports_final_peakpanther(self):
data = nPYc.MSDataset(
os.path.join('..', '..', 'npc-standard-project', 'Derived_Data', 'UnitTest1_PCSOP.069_QI.csv'),
fileType='QI')
data.addSampleInfo(descriptionFormat='Filenames')
try:
data.addSampleInfo(descriptionFormat='Filenames')
except nPYc.utilities._errorHandling.npycToolboxError:
pass # This is user warning, not an error so can be ignored
data.addSampleInfo(descriptionFormat='Raw Data',
filePath=os.path.join('..', '..', 'npc-standard-project', 'Raw_Data', 'ms',
'parameters_data'))
Expand Down
4 changes: 2 additions & 2 deletions nPYc/reports/_generateSampleReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def _generateSampleReport(dataTrue, withExclusions=False, destinationPath=None,
if SS_exclusions.shape[0] != 0:
sampleSummary['StudySamples Exclusion Details'] = SS_exclusions

# Drop rows where no samples present for that datatype
sampleSummary['Acquired'].drop(sampleSummary['Acquired'].index[sampleSummary['Acquired']['Total'].values == 0], axis=0, inplace=True)
# Drop rows where no samples present for that datatype across any column
sampleSummary['Acquired'].drop(sampleSummary['Acquired'].index[sampleSummary['Acquired'].sum(axis=1) == 0], axis=0, inplace=True)

# Update 'All', 'Missing/Excluded' to only reflect sample types present in data
sampleSummary['Acquired'].loc['All', 'Missing/Excluded'] = sum(sampleSummary['Acquired']['Missing/Excluded'][1:])
Expand Down

0 comments on commit b77f8c0

Please sign in to comment.