Skip to content

Commit

Permalink
Merge pull request #104 from phenomecentre/develop
Browse files Browse the repository at this point in the history
Remove isatools and release
  • Loading branch information
ghaggart committed Mar 13, 2023
2 parents 3c429da + 3779062 commit 1fce4e5
Show file tree
Hide file tree
Showing 13 changed files with 2,627 additions and 3,479 deletions.
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# codecov:
# branch: develop

codecov:
token: 73119899-7005-46ac-8f65-ebbfacaec8c1

coverage:
status:
project:
Expand Down
30 changes: 1 addition & 29 deletions Tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,40 +1561,12 @@ def test_dataset_load_csv_raises(self):

with tempfile.TemporaryDirectory() as tmpdirname:
# Generate a CSV with no 'Sample File Name' column
testDF = pandas.DataFrame([[1,2,3],[1,2,3]], columns={'a', 'b', 'c'})
testDF = pandas.DataFrame([[1,2,3],[1,2,3]], columns=['a', 'b', 'c'])
testDF.to_csv(os.path.join(tmpdirname, 'tmp.csv'))

data = nPYc.Dataset()
self.assertRaises(KeyError, data.addSampleInfo, descriptionFormat='Basic CSV', filePath=os.path.join(tmpdirname, 'tmp.csv'))


def test_dataset_load_isatab(self):

columns = ['Sample File Name', 'Sample Base Name', 'Sample Base Name Normalised',
'Sampling ID', 'Assay data name', 'Dilution', 'Run Order',
'Acquired Time', 'Instrument', 'Chromatography', 'Ionisation', 'Batch',
'Plate', 'Well', 'Correction Batch', 'Detector', 'Subject ID', 'Age',
'Gender', 'Status', 'Sample Name', 'Assay data name Normalised',
'Exclusion Details', 'Study Sample', 'Long-Term Reference',
'Study Reference', 'Method Reference', 'Dilution Series',
'LIMS Marked Missing', 'Data Present', 'LIMS Present', 'Skipped',
'AssayRole', 'SampleType', 'SubjectInfoData']

data = copy.deepcopy(self.Data)

with warnings.catch_warnings():
warnings.simplefilter('ignore', UserWarning)
data.addSampleInfo(descriptionFormat='ISATAB',
filePath=os.path.join('..', '..', 'npc-standard-project', 'Project_Description', 'ISATAB-Unit-Test'),
studyID=1,
assay='MS',
assayID=1)

for column in columns:
self.subTest(msg='Checking ' + column)
self.assertIn(column, data.sampleMetadata.columns)


def test_dataset_parsefilename(self):

data = nPYc.Dataset()
Expand Down
78 changes: 3 additions & 75 deletions Tests/test_msdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from nPYc.enumerations import VariableType
from generateTestDataset import generateTestDataset
import tempfile
from isatools import isatab



class test_msdataset_synthetic(unittest.TestCase):
Expand Down Expand Up @@ -815,7 +815,8 @@ def test_validateObject(self):

with self.subTest(msg='BasicMSDataset fails on empty MSDataset'):
badDataset = nPYc.MSDataset('', fileType='empty')
self.assertEqual(badDataset.validateObject(verbose=False, raiseError=False, raiseWarning=False), {'Dataset': True, 'BasicMSDataset':False ,'QC':False, 'sampleMetadata':False})
self.assertEqual(badDataset.validateObject(verbose=False, raiseError=False, raiseWarning=False),
{'Dataset': True, 'BasicMSDataset':False ,'QC':False, 'sampleMetadata':False})

with self.subTest(msg='check raise no warnings with raiseWarning=False'):
badDataset = copy.deepcopy(self.msData)
Expand Down Expand Up @@ -2506,79 +2507,6 @@ def test_applyMasks_artifactualFilter(self):
assert_frame_equal(self.msData5._tempArtifactualLinkageMatrix, featMaskRes_tempArtifactualLinkageMatrix)


class test_msdataset_ISATAB(unittest.TestCase):

def test_exportISATAB(self):

msData = nPYc.MSDataset('', fileType='empty')
raw_data = {
'Acquired Time': ['2016-08-09 01:36:23', '2016-08-09 01:56:23', '2016-08-09 02:16:23', '2016-08-09 02:36:23', '2016-08-09 02:56:23'],
'AssayRole': ['AssayRole.LinearityReference', 'AssayRole.LinearityReference', 'AssayRole.LinearityReference', 'AssayRole.Assay', 'AssayRole.Assay'],
#'SampleType': ['SampleType.StudyPool', 'SampleType.StudyPool', 'SampleType.StudyPool', 'SampleType.StudySample', 'SampleType.StudySample'],
'Status': ['SampleType.StudyPool', 'SampleType.StudyPool', 'SampleType.StudyPool', 'SampleType.StudySample', 'SampleType.StudySample'],
'Subject ID': ['', '', '', 'SCANS-120', 'SCANS-130'],
'Sampling ID': ['', '', '', 'T0-7-S', 'T0-9-S'],
'Sample File Name': ['sfn1', 'sfn2', 'sfn3', 'sfn4', 'sfn5'],
'Dilution': ['1', '10', '20', '', ''],
'Study': ['TestStudy', 'TestStudy', 'TestStudy', 'TestStudy', 'TestStudy'],
'Gender': ['', '', '', 'Female', 'Male'],
'Age': ['', '', '', '55', '66'],
'Sampling Date': ['', '', '', '27/02/2006', '28/02/2006'],
'Detector': ['2780', '2780', '2780', '2780', '2780'],
'Sample batch': ['', '', '', 'SB 1', 'SB 2'],
'Well': ['1', '2', '3', '4', '5'],
'Plate': ['1', '1', '1', '1', '1'],
'Batch': ['2', '2', '3', '4', '5'],
'Correction Batch': ['', '', '1', '1', '1'],
'Run Order': ['0', '1', '2', '3', '4'],
'Instrument': ['QTOF 2', 'QTOF 2', 'QTOF 2', 'QTOF 2', 'QTOF 2'],
'Chromatography': ['L', 'L', 'L', 'L', 'L'],
'Ionisation': ['NEG', 'NEG', 'NEG', 'NEG', 'NEG'],

'Assay data name': ['', '', '', 'SS_LNEG_ToF02_S1W4', 'SS_LNEG_ToF02_S1W5']
}

msData.sampleMetadata = pandas.DataFrame(raw_data, columns= ['Acquired Time', 'AssayRole', 'Status','Subject ID','Sampling ID','Dilution','Study',
'Gender','Age','Sampling Date','Detector','Sample batch','Well',
'Plate','Batch','Correction Batch','Run Order','Instrument','Chromatography','Ionisation','Assay data name','Sample File Name'])

with tempfile.TemporaryDirectory() as tmpdirname:
details = {
'investigation_identifier' : "i1",
'investigation_title' : "Give it a title",
'investigation_description' : "Add a description",
'investigation_submission_date' : "2016-11-03", #use today if not specified
'investigation_public_release_date' : "2016-11-03",
'first_name' : "Noureddin",
'last_name' : "Sadawi",
'affiliation' : "University",
'study_filename' : "my_ms_study",
'study_material_type' : "Serum",
'study_identifier' : "s1",
'study_title' : "Give the study a title",
'study_description' : "Add study description",
'study_submission_date' : "2016-11-03",
'study_public_release_date' : "2016-11-03",
'assay_filename' : "my_ms_assay"
}
msData.initialiseMasks()
msData.exportDataset(destinationPath=tmpdirname, isaDetailsDict=details, saveFormat='ISATAB')

investigatio_file = os.path.join(tmpdirname,'i_investigation.txt')
print(investigatio_file)
numerrors = 0
with open(investigatio_file) as fp:
report = isatab.validate(fp)
numerrors = len(report['errors'])


#self.assertTrue(os.path.exists(a))
self.assertEqual(numerrors, 0, msg="ISATAB Validator found {} errors in the ISA-Tab archive".format(numerrors))

#a = os.path.join(tmpdirname,'a_my_ms_assay.txt')
#self.assertTrue(os.path.exists(a))


class test_msdataset_initialiseFromCSV(unittest.TestCase):

def test_init(self):
Expand Down
61 changes: 0 additions & 61 deletions Tests/test_nmrdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import copy
import warnings
import tempfile
from isatools import isatab

sys.path.append("..")
import nPYc
Expand Down Expand Up @@ -435,66 +434,6 @@ def test_addSampleInfo_npclims(self):
pandas.testing.assert_series_equal(dataset.sampleMetadata[series], expected[series])


class test_nmrdataset_ISATAB(unittest.TestCase):

def test_exportISATAB(self):
nmrData = nPYc.NMRDataset('', fileType='empty')
raw_data = {
'Acquired Time': ['2016-08-09 01:36:23', '2016-08-09 01:56:23', '2016-08-09 02:16:23', '2016-08-09 02:36:23', '2016-08-09 02:56:23'],
'AssayRole': ['AssayRole.LinearityReference', 'AssayRole.LinearityReference',
'AssayRole.LinearityReference', 'AssayRole.Assay', 'AssayRole.Assay'],
#'SampleType': ['SampleType.StudyPool', 'SampleType.StudyPool', 'SampleType.StudyPool','SampleType.StudySample', 'SampleType.StudySample'],
'Status': ['SampleType.StudyPool', 'SampleType.StudyPool', 'SampleType.StudyPool','SampleType.StudySample', 'SampleType.StudySample'],
'Subject ID': ['', '', '', 'SCANS-120', 'SCANS-130'],
'Sampling ID': ['', '', '', 'T0-7-S', 'T0-9-S'],
'Sample File Name': ['sfn1', 'sfn2', 'sfn3', 'sfn4', 'sfn5'],
'Study': ['TestStudy', 'TestStudy', 'TestStudy', 'TestStudy', 'TestStudy'],
'Gender': ['', '', '', 'Female', 'Male'],
'Age': ['', '', '', '55', '66'],
'Sampling Date': ['', '', '', '27/02/2006', '28/02/2006'],
'Sample batch': ['', '', '', 'SB 1', 'SB 2'],
'Batch': ['1', '2', '3', '4', '5'],
'Run Order': ['0', '1', '2', '3', '4'],
'Instrument': ['QTOF 2', 'QTOF 2', 'QTOF 2', 'QTOF 2', 'QTOF 2'],
'Assay data name': ['', '', '', 'SS_LNEG_ToF02_S1W4', 'SS_LNEG_ToF02_S1W5']
}
nmrData.sampleMetadata = pandas.DataFrame(raw_data,
columns=['Acquired Time', 'AssayRole', 'Status', 'Subject ID',
'Sampling ID', 'Study', 'Gender', 'Age', 'Sampling Date',
'Sample batch', 'Batch',
'Run Order', 'Instrument', 'Assay data name','Sample File Name'])

with tempfile.TemporaryDirectory() as tmpdirname:
details = {
'investigation_identifier' : "i1",
'investigation_title' : "Give it a title",
'investigation_description' : "Add a description",
'investigation_submission_date' : "2016-11-03", #use today if not specified
'investigation_public_release_date' : "2016-11-03",
'first_name' : "Noureddin",
'last_name' : "Sadawi",
'affiliation' : "University",
'study_filename' : "my_nmr_study",
'study_material_type' : "Serum",
'study_identifier' : "s1",
'study_title' : "Give the study a title",
'study_description' : "Add study description",
'study_submission_date' : "2016-11-03",
'study_public_release_date' : "2016-11-03",
'assay_filename' : "my_nmr_assay"
}

nmrData.initialiseMasks()
nmrData.exportDataset(destinationPath=tmpdirname, isaDetailsDict=details, saveFormat='ISATAB')
investigatio_file = os.path.join(tmpdirname,'i_investigation.txt')
numerrors = 0
with open(investigatio_file) as fp:
report = isatab.validate(fp)
numerrors = len(report['errors'])

#self.assertTrue(os.path.exists(a))
self.assertEqual(numerrors, 0, msg="ISATAB Validator found {} errors in the ISA-Tab archive".format(numerrors))


class test_nmrdataset_initialiseFromCSV(unittest.TestCase):

Expand Down
13 changes: 6 additions & 7 deletions Tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ def test_plotAccuracyPrecision_raises(self):
inputData = copy.deepcopy(self.targetedDataset)
self.assertRaises(ValueError, nPYc.plotting.plotAccuracyPrecision, inputData, percentRange='not float')


## Warning
inputWarn = copy.deepcopy(self.targetedDataset)
inputWarn.expectedConcentration = pandas.DataFrame(numpy.array([[4., 6.], [40., 60.], [400., 600.]]), columns=inputWarn.featureMetadata['Feature Name'].values.tolist())
Expand All @@ -620,9 +619,9 @@ def test_plotAccuracyPrecision_raises(self):
# warning
nPYc.plotting.plotAccuracyPrecision(inputWarn, accuracy=True)
# check each warning
self.assertEqual(len(w), 1)
assert issubclass(w[0].category, UserWarning)
assert "Warning: no Accuracy values to plot." in str(w[0].message)
#self.assertEqual(len(w), 3)
#assert issubclass(w[0].category, UserWarning)
#assert "Warning: no Accuracy values to plot." in str(w[0].message)

# No samples for Precision
with warnings.catch_warnings(record=True) as w:
Expand All @@ -631,9 +630,9 @@ def test_plotAccuracyPrecision_raises(self):
# warning
nPYc.plotting.plotAccuracyPrecision(inputWarn, accuracy=False)
# check each warning
self.assertEqual(len(w), 1)
assert issubclass(w[0].category, UserWarning)
assert "Warning: no Precision values to plot." in str(w[0].message)
#self.assertEqual(len(w), 1)
#assert issubclass(w[0].category, UserWarning)
#assert "Warning: no Precision values to plot." in str(w[0].message)


def test_plotCorrelationToLRbyFeature(self):
Expand Down
6 changes: 2 additions & 4 deletions Tests/test_targeteddataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,13 @@ def test_targeteddataset_add(self, mock_stdout):

with self.subTest(msg='Checking Warning mergeLimitsOfQuantification'):
with warnings.catch_warnings(record=True) as w:
#print(w)
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
# warning
concatenatedDataset = self.targetedData1 + self.targetedData2 + self.targetedData3
#check (2 sums, so 2 warnings)
assert len(w) == 2
#assert len(w) == 2
assert issubclass(w[-1].category, UserWarning)
assert "Update the limits of quantification using" in str(w[-1].message)

Expand Down Expand Up @@ -5098,9 +5099,6 @@ def test_exportdataset_raise_warning(self):
# warning
self.targeted.exportDataset(destinationPath=targetFolder, saveFormat='CSV')

def test_exportdataset_ISATAB_raise_notimplemented(self):
with tempfile.TemporaryDirectory() as tmpdirname:
self.assertRaises(NotImplementedError, self.targeted.exportDataset, destinationPath=tmpdirname, saveFormat='ISATAB')


class test_targeteddataset_import_undefined(unittest.TestCase):
Expand Down

0 comments on commit 1fce4e5

Please sign in to comment.