Unit tests¶
Isotope correction is a complex task and we use (some) unit tests to make sure that critical features are not compromised during development.
A total of 318 tests has been designed to test IsoCor from individual steps (e.g. calculation of theoretical mass fractions or correction matrices) to the entire correction process. Importantly, most of the tests compare intermediate (e.g. correction matrix) or final (e.g. isotopologue distribution) calculations of IsoCor to theoretical results, with algebraic equations provided in the code for manual check.
All situations that may be encountered (e.g. in terms of tracer, metabolite or MS resolution) should be covered by these tests.
You can run all tests by calling pytest
in the shell at project’s root directory
(it must be installed beforehand):
pytest
To add a new testcase, see pytest documentation.
Tests are stored in tests/
folder.
Isotopic clusters¶
Test the calculation of lowresolution isotopic clusters (for metabolites with different number of elements and isotopes) against a brute force implementation.

isocor.tests.test_isotopic_cluster_LowRes.
get_isoclust_bruteforce
(formula, data_iso)[source]¶ Return the lowresolution isotopic cluster of a compound using convolution.

isocor.tests.test_isotopic_cluster_LowRes.
test_isoclust_against_bruteforce
(formula, data_iso, usr_tolerance)[source]¶ Check the low resolution isotopic clusters generation against a simple implementation.
Test the calculation of highresolution isotopic clusters (for metabolites with different number of elements and isotopes) against a brute force implementation.

isocor.tests.test_isotopic_cluster_HighRes.
get_isoclust_bruteforce
(formula, data_iso)[source]¶ Return the isotopic cluster for a compound using a bruteforce method.
This method is based on systematic computation of all isotopic species of the molecule. It should be easier to understand than the optimized version but is much slower.
Minimal mass difference to distinguish two isotopic species¶
Test calculation of the minimal mass difference required to resolve two isotopic species of a labeled chemical.
The minimal mass difference required to separate two isotopic species of a labeled chemical correspond to the minimal difference of mz to distinguish two MS peaks at the operating resolution multiplied by the charge. The minimal mz difference is calculated at the operating resolution using ‘resolution_formula’ ‘constant’ at the mz of the labeled chemical.

isocor.tests.test_m_min_constant.
test_m_min_constant
(data, data_iso)[source]¶ Calculation of the minimal mass difference (m_min) required to resolve two isotopic species of a labeled chemical at different resolution (10000, 100000) & charge (1, 2) for ‘constant’ resolution. m_min calculated by IsoCor is compared to the expected value (provided in the fixture) and to the theoretical value (equation provided in the code). This is checked for correctors instantiated through the Factory or directly as HighResMetaboliteCorrector.
Test calculation of the minimal mass difference required to resolve two isotopic species of a labeled chemical.
The minimal mass difference required to separate two isotopic species of a labeled chemical correspond to the minimal difference of mz to distinguish two MS peaks at the operating resolution multiplied by the charge. The minimal mz difference is calculated at the operating resolution using ‘resolution_formula’ of orbitrap (Su et al., 2017) at the mz of the labeled chemical.

isocor.tests.test_m_min_orbitrap.
test_m_min_orbitrap
(data, data_iso)[source]¶ Calculation of the minimal mass difference (m_min) required to resolve two isotopic species of a labeled chemical at different resolution (10000, 100000) & charge (1, 2) on an Orbitrap. m_min calculated by IsoCor is compared to the expected value (provided in the fixture) and to the theoretical value (equation provided in the code). This is checked for correctors instantiated through the Factory or directly as HighResMetaboliteCorrector.
Correction matrix¶
Test lowresolution correction matrix when no isotopic species are resolved from the tracer isotopologues.
In this situation, the contribution of all elements and isotopes should be removed. The lowresolution correction matrix calculated by IsoCor is compared to a theoretical correction matrix (with algebraic equations provided in the code for manual check).

isocor.tests.test_correction_matrix_LowRes.
test_low_res_cor_matrix
(data, data_iso, usr_tolerance)[source]¶ Correction of low resolution MS data.
Test simulates the correction of C2 compounds in a 13Ctracer experiment.
Test highresolution correction matrix when some or all isotopic species are resolved from the tracer isotopologues.
In this situation, the contribution of only some isotopic species should be removed, depending on the resolution. The highresolution correction matrix calculated by IsoCor is compared to a theoretical correction matrix (with algebraic equations provided in the code for manual check).

isocor.tests.test_correction_matrix_HighRes_resolved.
test_high_res_cor_matrix
(data, data_iso, usr_tolerance)[source]¶ Correction of highresolution MS data.
Test calculates the correction matrix of labeled metabolites containing C, H, N and O elements, and compares this matrix to a theoretical matrix.
Test highresolution correction matrix when no isotopic species are resolved from the tracer isotopologues.
In this situation, the contribution of all elements and isotopes should be removed, hence the highresolution and lowresolution correction matrices should be the same.
The highresolution correction matrix calculated by IsoCor is compared to
 a theoretical correction matrix (with algebraic equations provided in the code for manual check), and
 the low resolution correction matrix.

isocor.tests.test_correction_matrix_HighRes_unresolved.
test_high_res_cor_matrix_unresolved
(data, data_iso, usr_tolerance)[source]¶ Correction of high resolution MS data.
This test is designed to evaluate the correction of highresolution MS data where none of the isotopic species are resolved from the tracer isotopologues, i.e. the highresolution correction algorithm should provides the same correction matrix as the one computed using the lowresolution correction algorithm.
Correction process examples¶
Test the entire lowresolution correction process at lowresolution.
Compare mass fractions corrected by IsoCor to theoretical isotopologues distributions (with algebraic equations provided in the code for manual check).

isocor.tests.test_correction_process_LowRes.
test_low_res_correction
(data, data_iso, usr_tolerance)[source]¶ Correction of nontracer elements depending on resolution and formula.
Measured values should be corrected for the incorporation of natural isotopes of nontracers elements if the resolution was not high enough to distinguish them. The resolution depends on m/z ratio and thus the formula of the metabolite. The higher the mass, the higher the resolution should be used to distinguish all isotopomers and avoid to need correction.
Test the entire highresolution correction process at highresolution.
Comparison of mass fractions corrected by IsoCor to theoretical isotopologues distributions (with algebraic equations provided in the code for manual check).

isocor.tests.test_correction_process_HighRes.
test_high_res_correction
(data, data_iso)[source]¶ Correction of nontracer elements depending on resolution and formula.
Measured values should be corrected for the incorporation of natural isotopes of nontracers elements if the resolution was not high enough to distinguish them. The resolution depends on m/z ratio and thus the formula of the metabolite. The higher the mass, the higher the resolution should be used to distinguish all isotopomers and avoid to need correction.
Test the entire correction process at low and highresolution to cover all the situations that can be encountered.
This aims to verify that no error will be raised during normal usage. This set of tests correct a measurement vector (set to unity, i.e. [1,1,1,1] for a compound with 3 atoms of the tracer element) in all the possible combinations of the following situations:
 formulas: C1, C2, O1, O2, O3P3N3H3C3
 tracer elements: 13C, 17O, 18O
 derivative: H, H2, O, O2
 purity: 100%
 resolution (for highresolution correction only): 10000, 100000, 1000000
 correct NA: True, False
Total number of tests: 240

isocor.tests.test_all_cases.
test_correction_process_misc
(data, data_iso)[source]¶ Tests the entire correction process at high resolution.
 Combination of all the following situations:
 formulas: O3P3N3H3C3, C1, O1, O2, C2, O1
 tracer elements: 13C (2 isotopes), 17O (3 isotopes), 18O (3 isotopes)
 derivative: H, H2, O, O2
 purity: 100%
 resolution: 10000, 100000, 1000000
 correct NA: True, False
Total number of tests: 240
Misc.¶
Test the MetaboliteCorrectorFactory.

isocor.tests.test_factory.
test_MetaboliteCorrectorFactory
(data_iso)[source]¶ Test that the Factory can be instanciated safely.

isocor.tests.test_factory.
test_badinput
(kwargs, data_iso)[source]¶ Test a wrong type of parameter value (Factory).

isocor.tests.test_factory.
test_isotopedata
(bad_dataiso)[source]¶ Tests expected to fail because of a badly formatted data_isotopes.

isocor.tests.test_factory.
test_typo_factory
(data_iso)[source]¶ Test a typo in the name of one of the parameters (Factory).

isocor.tests.test_factory.
test_typo_parameter
(data_iso)[source]¶ Test a typo in the name of one of the parameters (LowRes).
Configuration variables for the tests
Shared predefined parameters The return value of fixture function will be available as a predefined parameter for all test functions. The test’s parameter name must be the same as the fixture function’s name.