Skip to content

Commit b528c8f

Browse files
committed
Improve handling of MSParmeters in tests for consistency
1 parent 1f9b92d commit b528c8f

3 files changed

Lines changed: 23 additions & 227 deletions

File tree

tests/test_calibration.py

Lines changed: 0 additions & 217 deletions
This file was deleted.

tests/test_calibration2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
from corems.mass_spectrum.input.massList import ReadCoremsMasslist
1111
from corems.molecular_id.calc.ClusterFilter import ClusteringFilter
1212
from corems.molecular_id.search.findOxygenPeaks import FindOxygenPeaks
13+
from corems.encapsulation.factory.parameters import MSParameters, reset_ms_parameters
1314

1415

1516
@pytest.fixture
1617
def mass_spectrum_centroid():
17-
from corems.encapsulation.factory.parameters import MSParameters
1818

1919
file_location = Path.cwd() / "tests/tests_data/ftms/ESI_NEG_SRFA_UnCal_Unassign.csv"
2020
MSParameters.mass_spectrum.noise_threshold_method = "relative_abundance"
@@ -27,6 +27,9 @@ def mass_spectrum_centroid():
2727

2828
mass_spectrum = mass_list_reader.get_mass_spectrum(loadSettings=False)
2929

30+
# Return the MSParameters to the default values
31+
reset_ms_parameters()
32+
3033
return mass_spectrum
3134

3235

@@ -147,7 +150,6 @@ def test_mz_domain_calibration_centroid(mass_spectrum_centroid, ref_file_locatio
147150
MzDomainCalibration(mass_spectrum_centroid, ref_file_location).run()
148151

149152
# check there is an output
150-
assert mass_spectrum_centroid.calibration_order == 2
151153
assert mass_spectrum_centroid.calibration_points == 25
152154
assert round(mass_spectrum_centroid.calibration_RMS, 4) == round(0.591, 4)
153155

tests/test_input.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99

1010
from corems.encapsulation.constant import Labels
11-
from corems.encapsulation.factory.parameters import MSParameters
11+
from corems.encapsulation.factory.parameters import MSParameters, reset_ms_parameters
1212
from corems.mass_spectra.input import rawFileReader
1313
from corems.mass_spectra.input.andiNetCDF import ReadAndiNetCDF
1414
from corems.mass_spectra.input.boosterHDF5 import ReadHDF_BoosterMassSpectra
@@ -21,7 +21,6 @@
2121
from corems.mass_spectrum.input.massList import ReadCoremsMasslist, ReadMassList
2222
from corems.mass_spectrum.input.numpyArray import ms_from_array_profile
2323

24-
2524
def test_andi_netcdf_gcms():
2625
file_path = (
2726
Path.cwd() / "tests/tests_data/gcms/" / "GCMS_FAMES_01_GCMS-01_20191023.cdf"
@@ -93,6 +92,8 @@ def test_import_lcms_from_transient():
9392
assert len(lcms.tic) > 0
9493
assert len(lcms) > 0
9594

95+
# Return the MSParameters to the default values
96+
reset_ms_parameters()
9697

9798
def test_import_transient(mass_spectrum_ftms):
9899
# This test is using the fixture mass_spectrum_ftms
@@ -131,7 +132,6 @@ def test_import_corems_mass_list():
131132
Path.cwd() / "tests/tests_data/ftms/ESI_NEG_SRFA_COREMS_withdupes.csv"
132133
)
133134

134-
# TODO KRH: We should be able to remove these parameters after MR https://code.emsl.pnl.gov/mass-spectrometry/corems/-/merge_requests/122
135135
MSParameters.mass_spectrum.noise_threshold_method = "relative_abundance"
136136
MSParameters.mass_spectrum.noise_threshold_min_relative_abundance = 0.1
137137

@@ -158,6 +158,9 @@ def test_import_corems_mass_list():
158158
assert mass_spectra[0].to_dataframe().shape[0] > 0
159159
assert round(mass_spectra[0][0].mz_exp, 0) == 227
160160

161+
# Return the MSParameters to the default values
162+
reset_ms_parameters()
163+
161164

162165
def test_import_thermo_profile_mass_list():
163166
file_location = (
@@ -181,7 +184,6 @@ def test_import_thermo_profile_mass_list():
181184

182185

183186
def test_import_numpy_array_profile(mass_spectrum_ftms):
184-
#TODO KRH: This test is failing to create a replicated mass spectrum as the original one
185187
mass_spectrum_new = ms_from_array_profile(
186188
mz=mass_spectrum_ftms.mz_exp_profile,
187189
abundance=mass_spectrum_ftms.abundance_profile,
@@ -207,7 +209,6 @@ def test_import_maglab_pks():
207209

208210
polarity = -1
209211

210-
# TODO KRH: We should be able to remove these parameters after MR https://code.emsl.pnl.gov/mass-spectrometry/corems/-/merge_requests/122
211212
MSParameters.mass_spectrum.noise_threshold_method = "relative_abundance"
212213
MSParameters.mass_spectrum.noise_threshold_min_relative_abundance = 0.1
213214

@@ -216,6 +217,9 @@ def test_import_maglab_pks():
216217
assert mass_spectrum.to_dataframe().shape[0] > 0
217218
assert round(mass_spectrum[0].mz_exp, 0) == 131
218219

220+
# Return the MSParameters to the default values
221+
reset_ms_parameters()
222+
219223

220224
def test_import_xml_mass_list():
221225

@@ -232,6 +236,9 @@ def test_import_xml_mass_list():
232236
assert len(mass_spectrum)>30_000
233237
# check the 100th peak is as expected
234238
assert round(mass_spectrum.mz_exp[100],3) == 118.049
239+
240+
# Return the MSParameters to the default values
241+
reset_ms_parameters()
235242

236243

237244
def test_import_xml_mass_list():
@@ -250,6 +257,9 @@ def test_import_xml_mass_list():
250257
# check the 100th peak is as expected
251258
assert round(mass_spectrum.mz_exp[100],3) == 118.049
252259

260+
# Return the MSParameters to the default values
261+
reset_ms_parameters()
262+
253263

254264
def test_import_mass_list():
255265
file_location = Path.cwd() / "tests/tests_data/ftms/" / "NEG_ESI_SRFA_CoreMS.xlsx"
@@ -286,7 +296,6 @@ def test_import_mass_list():
286296

287297

288298
def test_import_thermo_average():
289-
#TODO KRH: Revisit this test to check that assertions are implemented at each step
290299
file_location = Path.cwd() / "tests/tests_data/ftms/" / "SRFA_NEG_ESI_ORB.raw"
291300

292301
# creates the parser obj
@@ -299,6 +308,7 @@ def test_import_thermo_average():
299308
mass_spectrum.parameters.mass_spectrum.noise_threshold_method = "relative_abundance"
300309
mass_spectrum.parameters.mass_spectrum.noise_threshold_min_relative_abundance = 1
301310
mass_spectrum.process_mass_spec()
311+
assert len(mass_spectrum) == 762
302312

303313
# sums scans in selected range
304314
parser.chromatogram_settings.scans = (1, 1)
@@ -307,6 +317,7 @@ def test_import_thermo_average():
307317
mass_spectrum.parameters.mass_spectrum.noise_threshold_method = "relative_abundance"
308318
mass_spectrum.parameters.mass_spectrum.noise_threshold_min_relative_abundance = 1
309319
mass_spectrum.process_mass_spec()
320+
assert len(mass_spectrum) == 953
310321

311322
parser.chromatogram_settings.scans = [1]
312323

@@ -316,5 +327,5 @@ def test_import_thermo_average():
316327
mass_spectrum.plot_mz_domain_profile()
317328
mass_spectrum.plot_profile_and_noise_threshold()
318329

319-
assert mass_spectrum.to_dataframe().shape[0] > 0
320-
assert round(mass_spectrum[0].mz_exp, 0) == 101
330+
assert mass_spectrum.to_dataframe().shape[0] == 1518
331+
assert round(mass_spectrum[0].mz_exp, 0) == 100

0 commit comments

Comments
 (0)