-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_features_api.py
More file actions
368 lines (286 loc) · 18 KB
/
Copy pathtest_features_api.py
File metadata and controls
368 lines (286 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# coding: utf-8
"""
SIRIUS Nightsky API
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import os
import unittest
import json
from PySirius import *
class TestFeaturesApi(unittest.TestCase):
"""FeaturesApi unit test stubs"""
def setUp(self) -> None:
self.api = SiriusSDK().attach_to_sirius(sirius_port=8080)
self.project_id = "test_features_api"
path_to_demo_data = os.environ.get('HOME') + "/sirius-client-openAPI/.updater/clientTests/Data"
self.preproc_ms2_file_1 = path_to_demo_data + "/Kaempferol.ms"
self.preproc_ms2_file_2 = path_to_demo_data + "/laudanosine.mgf"
self.path_to_project = path_to_demo_data + "/tomato_small.sirius"
# check if test project already open -> allows to run tests in independent calls.
if self.api.projects().get_project_without_preload_content(self.project_id).status == 404:
self.project_info = self.api.projects().open_project(self.project_id, self.path_to_project)
# the single ID with MSNovelist AND spectral library search results computed
self.aligned_feature_id = "586487310566638367"
self.formula_candidates = self.api.features().get_formula_candidates(self.project_id, self.aligned_feature_id)
self.formula_id = self.formula_candidates[0].formula_id
def tearDown(self) -> None:
self.api.projects().close_project(self.project_id)
def test_add_aligned_features(self) -> None:
"""Test case for add_aligned_features
Import (aligned) features into the project.
"""
project_info = self.api.projects().create_project(project_id="delete-project")
project_id = project_info.project_id
try:
simple_peak_json = {
"mz": 1.23,
"intensity": 1.23
}
basic_spectrum_json = {
"precursorMz": 1.23,
"peaks": [
simple_peak_json
]
}
feature_import_json = {
"name": "testfeature",
"featureId": "testfeature",
"ionMass": 1.23,
"charge": 1,
"adduct": "[M+?]+",
"ms1Spectra": [
basic_spectrum_json
],
"ms2Spectra": [
basic_spectrum_json
]
}
feature_import_instance = FeatureImport.from_json(json.dumps(feature_import_json))
feature_import = [feature_import_instance]
response = self.api.features().add_aligned_features(project_id, feature_import)
self.api.features().delete_aligned_feature(project_id, response[0].aligned_feature_id)
self.assertIsInstance(response, list)
self.assertIsInstance(response[0], AlignedFeature)
finally:
self.api.projects().close_project(project_id)
os.remove(project_info.location)
def test_delete_aligned_feature(self) -> None:
"""Test case for delete_aligned_feature
Delete feature (aligned over runs) with the given identifier from the specified project-space.
"""
project_info = self.api.projects().create_project(project_id="delete-feature-project")
project_id = project_info.project_id
try:
input_files = [self.preproc_ms2_file_1, self.preproc_ms2_file_2]
import_result = self.api.projects().import_preprocessed_data(project_id, input_files=input_files)
feature_ids = import_result.affected_aligned_feature_ids
response_before = self.api.features().get_aligned_features(project_id)
self.api.features().delete_aligned_feature(project_id, feature_ids[0])
self.api.features().delete_aligned_feature(project_id, feature_ids[1])
response_after = self.api.features().get_aligned_features(project_id)
self.assertIsInstance(response_before, list)
self.assertIsInstance(response_before[0], AlignedFeature)
self.assertIsInstance(response_after, list)
self.assertEqual(len(response_after), 0)
self.assertEqual(len(response_before) - len(response_after), 2)
finally:
self.api.projects().close_project(project_id)
os.remove(project_info.location)
def test_delete_aligned_features(self) -> None:
"""Test case for delete_aligned_features
Delete feature (aligned over runs) with the given identifier from the specified project-space.
"""
project_info = self.api.projects().create_project(project_id="delete-features-project")
project_id = project_info.project_id
try:
input_files = [self.preproc_ms2_file_1, self.preproc_ms2_file_2]
import_result = self.api.projects().import_preprocessed_data(project_id, input_files=input_files)
feature_ids = import_result.affected_aligned_feature_ids
response_before = self.api.features().get_aligned_features(project_id)
self.api.features().delete_aligned_features(project_id, feature_ids)
response_after = self.api.features().get_aligned_features(project_id)
self.assertIsInstance(response_before, list)
self.assertIsInstance(response_before[0], AlignedFeature)
self.assertIsInstance(response_after, list)
self.assertEqual(len(response_after), 0)
self.assertEqual(len(response_before) - len(response_after), 2)
finally:
self.api.projects().close_project(project_id)
os.remove(project_info.location)
def test_get_aligned_feature(self) -> None:
"""Test case for get_aligned_feature
Get feature (aligned over runs) with the given identifier from the specified project-space.
"""
response = self.api.features().get_aligned_feature(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, AlignedFeature)
def test_get_aligned_features(self) -> None:
"""Test case for get_aligned_features
Get all available features (aligned over runs) in the given project-space.
"""
response = self.api.features().get_aligned_features(self.project_id)
self.assertIsInstance(response, list)
self.assertIsInstance(response[0], AlignedFeature)
def test_get_aligned_features_paged(self) -> None:
"""Test case for get_aligned_features_paged
Get all available features (aligned over runs) in the given project-space.
"""
response = self.api.features().get_aligned_features_paged(self.project_id)
self.assertIsInstance(response, PagedModelAlignedFeature)
def test_get_best_matching_compound_classes(self) -> None:
"""Test case for get_best_matching_compound_classes
Best matching compound classes, Set of the highest scoring compound classes (CANOPUS) on each hierarchy level of the ClassyFire and NPC ontology,
"""
response = self.api.features().get_best_matching_compound_classes(self.project_id, self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, CompoundClasses)
def test_get_canopus_prediction(self) -> None:
"""Test case for get_canopus_prediction
All predicted compound classes (CANOPUS) from ClassyFire and NPC and their probabilities,
"""
response = self.api.features().get_canopus_prediction(self.project_id, self.aligned_feature_id, self.formula_id)
self.assertIsInstance(response, CanopusPrediction)
def test_get_de_novo_structure_candidates_by_formula(self) -> None:
"""Test case for get_de_novo_structure_candidates_by_formula
List of de novo structure candidates (e.g. generated by MsNovelist) ranked by CSI:FingerID score for the given 'formulaId' with minimal information. StructureCandidates can be enriched with molecular fingerprint.
"""
response = self.api.features().get_de_novo_structure_candidates_by_formula(self.project_id,
self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, list)
self.assertIsInstance(response[0], StructureCandidateScored)
def test_get_de_novo_structure_candidates_by_formula_paged(self) -> None:
"""Test case for get_de_novo_structure_candidates_by_formula_paged
Page of de novo structure candidates (e.g. generated by MsNovelist) ranked by CSI:FingerID score for the given 'formulaId' with minimal information. StructureCandidates can be enriched with molecular fingerprint.
"""
response = self.api.features().get_de_novo_structure_candidates_by_formula_paged(self.project_id,
self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, PagedModelStructureCandidateScored)
def test_get_de_novo_structure_candidates_paged(self) -> None:
"""Test case for get_de_novo_structure_candidates_paged
Page of de novo structure candidates (e.g. generated by MsNovelist) ranked by CSI:FingerID score for the given 'alignedFeatureId' with minimal information. StructureCandidates can be enriched with molecular fingerprint.
"""
response = self.api.features().get_de_novo_structure_candidates_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PagedModelStructureCandidateFormula)
def test_get_fingerprint_prediction(self) -> None:
"""Test case for get_fingerprint_prediction
Returns predicted fingerprint (CSI:FingerID) for the given formula result identifier This fingerprint is used to perform structure database search and predict compound classes.
"""
response = self.api.features().get_fingerprint_prediction(self.project_id, self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, list)
def test_get_formula_annotated_ms_ms_data(self) -> None:
"""Test case for get_formula_annotated_ms_ms_data
Returns MS/MS Spectrum (Merged MS/MS and measured MS/MS) which is annotated with fragments and losses for the given formula result identifier These annotations are only available if a fragmentation tree and the structure candidate are available.
"""
response = self.api.features().get_formula_annotated_ms_ms_data(self.project_id, self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, AnnotatedMsMsData)
def test_get_formula_annotated_spectrum(self) -> None:
"""Test case for get_formula_annotated_spectrum
Returns a fragmentation spectrum (e.g. Merged MS/MS) which is annotated with fragments and losses for the given formula result identifier These annotations are only available if a fragmentation tree is available.
"""
response = self.api.features().get_formula_annotated_spectrum(self.project_id, self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, AnnotatedSpectrum)
def test_get_formula_candidate(self) -> None:
"""Test case for get_formula_candidate
FormulaResultContainers for the given 'formulaId' with minimal information.
"""
response = self.api.features().get_formula_candidate(self.project_id, self.aligned_feature_id, self.formula_id)
self.assertIsInstance(response, FormulaCandidate)
def test_get_formula_candidates(self) -> None:
"""Test case for get_formula_candidates
List of FormulaResultContainers available for this feature with minimal information.
"""
self.assertIsInstance(self.formula_candidates, list)
self.assertIsInstance(self.formula_candidates[0], FormulaCandidate)
def test_get_formula_candidates_paged(self) -> None:
"""Test case for get_formula_candidates_paged
Page of FormulaResultContainers available for this feature with minimal information.
"""
response = self.api.features().get_formula_candidates_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PagedModelFormulaCandidate)
def test_get_frag_tree(self) -> None:
"""Test case for get_frag_tree
Returns fragmentation tree (SIRIUS) for the given formula result identifier This tree is used to rank formula candidates (treeScore).
"""
response = self.api.features().get_frag_tree(self.project_id, self.aligned_feature_id, self.formula_id)
self.assertIsInstance(response, FragmentationTree)
def test_get_isotope_pattern_annotation(self) -> None:
"""Test case for get_isotope_pattern_annotation
Returns Isotope pattern information (simulated isotope pattern, measured isotope pattern, isotope pattern highlighting) for the given formula result identifier.
"""
response = self.api.features().get_isotope_pattern_annotation(self.project_id, self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, IsotopePatternAnnotation)
def test_get_lipid_annotation(self) -> None:
"""Test case for get_lipid_annotation
Returns Lipid annotation (ElGordo) for the given formula result identifier.
"""
response = self.api.features().get_lipid_annotation(self.project_id, self.aligned_feature_id, self.formula_id)
self.assertIsInstance(response, LipidAnnotation)
def test_get_ms_data(self) -> None:
"""Test case for get_ms_data
Mass Spec data (input data) for the given 'alignedFeatureId' .
"""
response = self.api.features().get_ms_data(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, MsData)
def test_get_spectral_library_match(self) -> None:
"""Test case for get_spectral_library_match
List of spectral library matches for the given 'alignedFeatureId'.
"""
match_id = self.api.features().get_spectral_library_matches(self.project_id, self.aligned_feature_id)[0].spec_match_id
response = self.api.features().get_spectral_library_match(self.project_id, self.aligned_feature_id, match_id)
self.assertIsInstance(response, SpectralLibraryMatch)
def test_get_spectral_library_matches(self) -> None:
"""Test case for get_spectral_library_matches
List of spectral library matches for the given 'alignedFeatureId'.
"""
response = self.api.features().get_spectral_library_matches(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, list)
self.assertIsInstance(response[0], SpectralLibraryMatch)
def test_get_spectral_library_matches_paged(self) -> None:
"""Test case for get_spectral_library_matches_paged
Page of spectral library matches for the given 'alignedFeatureId'.
"""
response = self.api.features().get_spectral_library_matches_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PagedModelSpectralLibraryMatch)
def test_get_spectral_library_matches_summary(self) -> None:
"""Test case for get_spectral_library_matches_summary
Summarize matched reference spectra for the given 'alignedFeatureId'.
"""
response = self.api.features().get_spectral_library_matches_summary(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, SpectralLibraryMatchSummary)
def test_get_structure_candidates(self) -> None:
"""Test case for get_structure_candidates
List of structure database search candidates ranked by CSI:FingerID score for the given 'alignedFeatureId' with minimal information.
"""
response = self.api.features().get_structure_candidates(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, list)
self.assertIsInstance(response[0], StructureCandidateFormula)
def test_get_structure_candidates_by_formula(self) -> None:
"""Test case for get_structure_candidates_by_formula
List of CSI:FingerID structure database search candidates for the given 'formulaId' with minimal information.
"""
response = self.api.features().get_structure_candidates_by_formula(self.project_id, self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, list)
self.assertIsInstance(response[0], StructureCandidateScored)
def test_get_structure_candidates_by_formula_paged(self) -> None:
"""Test case for get_structure_candidates_by_formula_paged
Page of CSI:FingerID structure database search candidates for the given 'formulaId' with minimal information.
"""
response = self.api.features().get_structure_candidates_by_formula_paged(self.project_id,
self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, PagedModelStructureCandidateScored)
def test_get_structure_candidates_paged(self) -> None:
"""Test case for get_structure_candidates_paged
Page of structure database search candidates ranked by CSI:FingerID score for the given 'alignedFeatureId' with minimal information.
"""
response = self.api.features().get_structure_candidates_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PagedModelStructureCandidateFormula)
if __name__ == '__main__':
unittest.main()