1010from corems .mass_spectrum .input .massList import ReadCoremsMasslist
1111from corems .molecular_id .calc .ClusterFilter import ClusteringFilter
1212from corems .molecular_id .search .findOxygenPeaks import FindOxygenPeaks
13- from corems .molecular_id .search .molecularFormulaSearch import SearchMolecularFormulas
1413
15- #TODO KRH: Revisit all tests in this file
1614
1715@pytest .fixture
1816def mass_spectrum_centroid ():
17+ from corems .encapsulation .factory .parameters import MSParameters
18+
1919 file_location = Path .cwd () / "tests/tests_data/ftms/ESI_NEG_SRFA_UnCal_Unassign.csv"
20+ MSParameters .mass_spectrum .noise_threshold_method = "relative_abundance"
21+ MSParameters .mass_spectrum .noise_threshold_min_relative_abundance = 0.1
2022
21- #load any type of mass list file, change the delimeter to read another type of file, i.e : "," for csv, "\t" for tabulated mass list, etc
22- mass_list_reader = ReadCoremsMasslist (file_location , analyzer = 'ICR' , instrument_label = '12T' )
23+ # load any type of mass list file, change the delimeter to read another type of file, i.e : "," for csv, "\t" for tabulated mass list, etc
24+ mass_list_reader = ReadCoremsMasslist (
25+ file_location , analyzer = "ICR" , instrument_label = "12T"
26+ )
2327
24- mass_spectrum = mass_list_reader .get_mass_spectrum (
25- loadSettings = False
26- )
27- mass_spectrum .settings .noise_threshold_method = "relative_abundance"
28- mass_spectrum .settings .noise_threshold_min_relative_abundance = 0.1
28+ mass_spectrum = mass_list_reader .get_mass_spectrum (loadSettings = False )
2929
3030 return mass_spectrum
3131
32+
3233def test_mz_domain_calibration (mass_spectrum_ftms , ref_file_location ):
3334 print ("test_mz_domain_calibration" )
3435 mass_spectrum_ftms .settings .min_calib_ppm_error = - 10
@@ -43,6 +44,7 @@ def test_mz_domain_calibration(mass_spectrum_ftms, ref_file_location):
4344 # Check that the calibration was successful
4445 assert mass_spectrum_ftms .calibration_RMS < 2
4546
47+
4648def test_autorecalibration (mass_spectrum_ftms , ref_file_location ):
4749 mass_spectrum_ftms .filter_by_noise_threshold ()
4850
@@ -61,6 +63,7 @@ def test_autorecalibration(mass_spectrum_ftms, ref_file_location):
6163 # Check that the calibration was successful
6264 assert mass_spectrum_ftms .calibration_RMS < 2
6365
66+
6467def test_segmentedmzcalibration (mass_spectrum_ftms , ref_file_location ):
6568 # Tests profile mode recalibration
6669 mass_spectrum_ftms .filter_by_noise_threshold ()
@@ -75,11 +78,12 @@ def test_segmentedmzcalibration(mass_spectrum_ftms, ref_file_location):
7578 # Check that the calibration was successful
7679 assert mass_spectrum_ftms .calibration_RMS < 2
7780
81+
7882def test_old_calibration (mass_spectrum_ftms ):
79- usedatoms = {'C' : (1 ,100 ) , 'H' : (4 ,200 ), 'O' : (1 ,10 )}
83+ usedatoms = {"C" : (1 , 100 ), "H" : (4 , 200 ), "O" : (1 , 10 )}
8084
81- mass_spectrum_ftms .molecular_search_settings .url_database = ''
82- mass_spectrum_ftms .molecular_search_settings .error_method = ' None'
85+ mass_spectrum_ftms .molecular_search_settings .url_database = ""
86+ mass_spectrum_ftms .molecular_search_settings .error_method = " None"
8387 mass_spectrum_ftms .molecular_search_settings .min_ppm_error = - 5
8488 mass_spectrum_ftms .molecular_search_settings .max_ppm_error = 5
8589 mass_spectrum_ftms .molecular_search_settings .mz_error_range = 1
@@ -94,7 +98,7 @@ def test_old_calibration(mass_spectrum_ftms):
9498 find_formula_thread .run ()
9599
96100 mspeaks_results = find_formula_thread .get_list_found_peaks ()
97-
101+
98102 calibrate = FreqDomain_Calibration (mass_spectrum_ftms , mspeaks_results )
99103 calibrate .linear ()
100104 calibrate .step_fit ()
@@ -103,41 +107,34 @@ def test_old_calibration(mass_spectrum_ftms):
103107
104108 # Check that the calibration was successful
105109 assert set (mass_spectrum_ftms .mz_cal ) != {None }
106-
107- mass_spectrum_ftms .molecular_search_settings .error_method = ' symmetrical'
108- mass_spectrum_ftms .molecular_search_settings .min_ppm_error = - 3
110+
111+ mass_spectrum_ftms .molecular_search_settings .error_method = " symmetrical"
112+ mass_spectrum_ftms .molecular_search_settings .min_ppm_error = - 3
109113 mass_spectrum_ftms .molecular_search_settings .max_ppm_error = 3
110114 mass_spectrum_ftms .molecular_search_settings .mz_error_range = 1
111115 mass_spectrum_ftms .molecular_search_settings .mz_error_average = 0
112- mass_spectrum_ftms .molecular_search_settings .min_abun_error = - 30 # percentage
113- mass_spectrum_ftms .molecular_search_settings .max_abun_error = 70 # percentage
114- mass_spectrum_ftms .molecular_search_settings .isProtonated = True
115- mass_spectrum_ftms .molecular_search_settings .isRadical = True
116-
117- mass_spectrum_ftms .molecular_search_settings .usedAtoms = {'C' : (1 , 100 ),
118- 'H' : (4 , 200 ),
119- 'O' : (0 , 20 ),
120- 'N' : (0 , 1 ),
121- 'S' : (0 , 0 ),
122- 'P' : (0 , 0 ),
123- }
124-
116+ mass_spectrum_ftms .molecular_search_settings .min_abun_error = - 30 # percentage
117+ mass_spectrum_ftms .molecular_search_settings .max_abun_error = 70 # percentage
118+ mass_spectrum_ftms .molecular_search_settings .isProtonated = True
119+ mass_spectrum_ftms .molecular_search_settings .isRadical = True
120+
121+ mass_spectrum_ftms .molecular_search_settings .usedAtoms = {
122+ "C" : (1 , 100 ),
123+ "H" : (4 , 200 ),
124+ "O" : (0 , 20 ),
125+ "N" : (0 , 1 ),
126+ "S" : (0 , 0 ),
127+ "P" : (0 , 0 ),
128+ }
129+
125130 og_len = len (mass_spectrum_ftms )
126131 ClusteringFilter ().filter_kendrick (mass_spectrum_ftms )
127132
128- # Check that the mass spectrum has been filtered
129- assert len (mass_spectrum_ftms ) != og_len
130-
131- #TODO KRH: This should move to a different test
132- #SearchMolecularFormulas(mass_spectrum_ftms).run_worker_mass_spectrum()
133- #ClusteringFilter().remove_assignment_by_mass_error(mass_spectrum_ftms)
133+ # Check that the mass spectrum has not filtered anything (i.e. the length is the same)
134+ assert len (mass_spectrum_ftms ) == og_len
134135
135- def test_mz_domain_calibration_centroid ():
136- pass
137- """
138- # This test is failing because the way that the centroided mass spectrum is created is not correct,
139- # see https://code.emsl.pnl.gov/mass-spectrometry/corems/-/issues/152 and associated MR: https://code.emsl.pnl.gov/mass-spectrometry/corems/-/merge_requests/122
140136
137+ def test_mz_domain_calibration_centroid (mass_spectrum_centroid , ref_file_location ):
141138 mass_spectrum_centroid .settings .min_calib_ppm_error = - 10
142139 mass_spectrum_centroid .settings .max_calib_ppm_error = 10
143140 mass_spectrum_centroid .calib_pol_order = 1
@@ -150,17 +147,12 @@ def test_mz_domain_calibration_centroid():
150147 MzDomainCalibration (mass_spectrum_centroid , ref_file_location ).run ()
151148
152149 # check there is an output
153- assert mass_spectrum_centroid.calibration_order == 1
154- assert(mass_spectrum_centroid.calibration_points == 25)
155- assert(round(mass_spectrum_centroid.calibration_RMS, 4) == round(0.8690388563830891, 4))
156- """
150+ assert mass_spectrum_centroid .calibration_order == 2
151+ assert mass_spectrum_centroid .calibration_points == 25
152+ assert round (mass_spectrum_centroid .calibration_RMS , 4 ) == round (0.591 , 4 )
157153
158- def test_auto_calibration_centroid ():
159- pass
160- """
161- # This test is failing because the way that the centroided mass spectrum is created is not correct,
162- # see https://code.emsl.pnl.gov/mass-spectrometry/corems/-/issues/152 and associated MR: https://code.emsl.pnl.gov/mass-spectrometry/corems/-/merge_requests/122
163154
155+ def test_auto_calibration_centroid (mass_spectrum_centroid , ref_file_location ):
164156 mass_spectrum_centroid .filter_by_noise_threshold ()
165157
166158 # Check that mass_spectrum_centroid has not been calibrated
@@ -177,21 +169,19 @@ def test_auto_calibration_centroid():
177169
178170 # Check that the calibration was successful
179171 assert mass_spectrum_centroid .calibration_RMS < 0.6
180- """
181172
182- def test_segmentedmzcalibration_centroid ():
183- pass
184- """
185- # This test is failing because the way that the centroided mass spectrum is created is not correct,
186- # see https://code.emsl.pnl.gov/mass-spectrometry/corems/-/issues/152 and associated MR: https://code.emsl.pnl.gov/mass-spectrometry/corems/-/merge_requests/122
187173
174+ def test_segmentedmzcalibration_centroid (mass_spectrum_centroid , ref_file_location ):
188175 mass_spectrum_centroid .filter_by_noise_threshold ()
176+ mass_spectrum_centroid .settings .min_calib_ppm_error = - 10
177+ mass_spectrum_centroid .settings .max_calib_ppm_error = 10
189178
190179 # Check that mass_spectrum_centroid has not been calibrated
191180 assert set (mass_spectrum_centroid .mz_cal ) == {None }
192181
193- MzDomainCalibration(mass_spectrum_centroid, ref_file_location, mzsegment=(0, 300)).run()
182+ MzDomainCalibration (
183+ mass_spectrum_centroid , ref_file_location , mzsegment = (0 , 300 )
184+ ).run ()
194185
195186 # Check that the calibration was successful
196187 assert mass_spectrum_centroid .calibration_RMS < 0.6
197- """
0 commit comments