Skip to content

Commit

Permalink
test: add tests of multiple result files with mzML loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jcharkow committed Oct 7, 2024
1 parent 78d08d8 commit fa12249
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 12 deletions.
2 changes: 2 additions & 0 deletions massdash/loaders/MzMLDataLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self.dataAccess = [MzMLDataAccess(f, 'ondisk', verbose=self.verbose) for f in self.dataFiles]
self.has_im = np.all([d.has_im for d in self.dataAccess])
if self.libraryAccess is None:
raise ValueError("If .osw file is not supplied, library file is required for MzMLDataLoader to perform targeted extraction")

def loadTransitionGroups(self, pep_id: str, charge: int, config: TargetedDIAConfig) -> Dict[str, TransitionGroup]:
'''
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
61 changes: 61 additions & 0 deletions test/loaders/__snapshots__/test_ResultsLoader.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
'test_raw_1',
])
# ---
# name: test_inferRunNames[dreamdia]
list([
'test_raw_1',
'test_raw_2',
])
# ---
# name: test_inferRunNames[openswath]
list([
'test_raw_1',
Expand Down Expand Up @@ -60,6 +66,24 @@
}),
})
# ---
# name: test_loadIdentifiedPeptides[dreamdia]
dict({
'DreamDIA': dict({
'test_raw_1.mzML': set({
'AGAANIVPNSTGAAK',
'DYASIDAAPEER',
'IEDQLGEVAQYK',
'KVVITAPGGNDVK',
}),
'test_raw_2.mzML': set({
'AGAANIVPNSTGAAK',
'DYASIDAAPEER',
'IEDQLGEVAQYK',
'KVVITAPGGNDVK',
}),
}),
})
# ---
# name: test_loadIdentifiedPeptides[openswath]
dict({
'OpenSWATH': dict({
Expand Down Expand Up @@ -207,6 +231,22 @@
}),
})
# ---
# name: test_loadIdentifiedProteins[dreamdia]
dict({
'DreamDIA': dict({
'test_raw_1.mzML': set({
'Spyo_Exp3652_DDB_SeqID_514830',
'Spyo_Exp3652_DDB_SeqID_514851',
'Spyo_Exp3652_DDB_SeqID_515131',
}),
'test_raw_2.mzML': set({
'Spyo_Exp3652_DDB_SeqID_514830',
'Spyo_Exp3652_DDB_SeqID_514851',
'Spyo_Exp3652_DDB_SeqID_515131',
}),
}),
})
# ---
# name: test_loadIdentifiedProteins[openswath]
dict({
'OpenSWATH': dict({
Expand Down Expand Up @@ -242,6 +282,14 @@
}),
})
# ---
# name: test_loadNumIdentifiedPeptides[dreamdia]
dict({
'DreamDIA': dict({
'test_raw_1.mzML': 4,
'test_raw_2.mzML': 4,
}),
})
# ---
# name: test_loadNumIdentifiedPeptides[openswath]
dict({
'OpenSWATH': dict({
Expand Down Expand Up @@ -296,6 +344,14 @@
}),
})
# ---
# name: test_loadNumIdentifiedProteins[dreamdia]
dict({
'DreamDIA': dict({
'test_raw_1.mzML': 3,
'test_raw_2.mzML': 3,
}),
})
# ---
# name: test_loadNumIdentifiedProteins[openswath]
dict({
'OpenSWATH': dict({
Expand All @@ -315,6 +371,11 @@
'DIA-NN',
])
# ---
# name: test_loadSoftware[dreamdia]
list([
'DreamDIA',
])
# ---
# name: test_loadSoftware[openswath]
list([
'OpenSWATH',
Expand Down
36 changes: 24 additions & 12 deletions test/loaders/test_MzMLDataLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,51 @@ def config():
c.rt_window = 5
return c

@pytest.fixture
@pytest.fixture(params=['openswath', 'diann', 'combined'])
def mzml_data_loader(request):
if request.param == 'osw':
dataFilesPrefix = f'{TEST_PATH}/test_data/example_dia/raw/'
dataFiles = [f"{dataFilesPrefix}/test_raw_1.mzML", f"{dataFilesPrefix}/test_raw_2.mzML"]
libFile = None

if request.param == 'openswath':
rsltsFile = f'{TEST_PATH}/test_data/example_dia/openswath/osw/test.osw'
elif request.param == 'diann':
rsltsFile = f'{TEST_PATH}/test_data/example_dia/diann/report/test_diann_report_combined.tsv'
libFile = f'{TEST_PATH}/test_data/example_dia/diann/lib/test_1_lib.tsv'
elif request.param == 'combined': # note: if two results files are specified, the first one will be used for extraction
rsltsFile = [f'{TEST_PATH}/test_data/example_dia/diann/report/test_diann_report_combined.tsv',
f'{TEST_PATH}/test_data/example_dia/openswath/osw/test.osw']
else:
raise ValueError(f"Invalid parameter: {request.param}")

dataFilesPrefix = f'{TEST_PATH}/test_data/example_dia/raw/'
dataFiles = [f"{dataFilesPrefix}/test_raw_1.mzML", f"{dataFilesPrefix}/test_raw_2.mzML"]
return MzMLDataLoader(rsltsFile=rsltsFile, dataFiles=dataFiles)
return MzMLDataLoader(rsltsFile=rsltsFile, dataFiles=dataFiles, libraryFile=libFile, verbose=False, mode='module')

def test_init_error():
# if library file is not provided, an error should be raised when only DIA-NN report files are supplied
with pytest.raises(ValueError):
MzMLDataLoader(rsltsFile=f"{TEST_PATH}/test_data/example_dia/diann/report/test_diann_report_combined.tsv", dataFiles=f'{TEST_PATH}/test_data/example_dia/raw/test_raw_1.mzML', libraryFile=None, verbose=False, mode='module')

'''
@pytest.mark.parametrize('mzml_data_loader,pep,charge', [('osw', 'AGAANIVPNSTGAAK', 2)], indirect=['mzml_data_loader'])
@pytest.mark.parametrize('pep,charge', [('DYASIDAAPEER', 2)])
def test_loadTopTransitionGroupFeatureDf(mzml_data_loader, pep, charge, snapshot_pandas):
df = mzml_data_loader.loadTopTransitionGroupFeatureDf(pep, charge)
assert snapshot_pandas == df

@pytest.mark.parametrize('mzml_data_loader,pep,charge', [('osw', 'AGAANIVPNSTGAAK', 2)], indirect=['mzml_data_loader'])
@pytest.mark.parametrize('pep,charge', [('DYASIDAAPEER', 2)])
def test_loadTransitionGroupFeaturesDf(mzml_data_loader, pep, charge, snapshot_pandas):
df = mzml_data_loader.loadTransitionGroupFeaturesDf(pep, charge)
assert snapshot_pandas == df
'''

@pytest.mark.parametrize('mzml_data_loader,pep,charge', [('osw', 'AGAANIVPNSTGAAK', 2)], indirect=['mzml_data_loader'])
@pytest.mark.parametrize('pep,charge', [('DYASIDAAPEER', 2)])
def test_loadTransitionGroups(mzml_data_loader, config, pep, charge, snapshot_pandas):
groups = mzml_data_loader.loadTransitionGroups(pep, charge, config)
assert snapshot_pandas == groups.toPandasDf()

@pytest.mark.parametrize('mzml_data_loader,pep,charge', [('osw', 'AGAANIVPNSTGAAK', 2)], indirect=['mzml_data_loader'])
@pytest.mark.parametrize('pep,charge', [('DYASIDAAPEER', 2)])
def test_loadTransitionGroupsDf(mzml_data_loader, config, pep, charge, snapshot_pandas):
df = mzml_data_loader.loadTransitionGroupsDf(pep, charge, config)
assert snapshot_pandas == df

@pytest.mark.parametrize('mzml_data_loader,pep,charge', [('osw', 'AGAANIVPNSTGAAK', 2)], indirect=['mzml_data_loader'])
@pytest.mark.parametrize('pep,charge', [('DYASIDAAPEER', 2)])
def test_loadFeatureMaps(mzml_data_loader, config, pep, charge, snapshot_pandas):
feature_maps = mzml_data_loader.loadFeatureMaps(pep, charge, config)

Expand Down
1 change: 1 addition & 0 deletions test/loaders/test_ResultsLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def snapshot_pandas(snapshot):

#f"{TEST_PATH}/test_data/example_dia/dreamdia/test_dreamdia_report.tsv",
#[f"{TEST_PATH}/test_data/example_dia/diann/report/test_diann_report_combined.tsv", f"{TEST_PATH}/test_data/example_dia/dreamdia/test_dreamdia_report.tsv"]
# NOTE: with this PR dreamDIA is not supported
@pytest.fixture(params=['openswath', 'diann1', 'combined'])
def resultsLoader(request):
if request.param == 'openswath':
Expand Down

0 comments on commit fa12249

Please sign in to comment.