# 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 test-case, see pytest documentation.

Tests are stored in tests/ folder.

## Isotopic clusters¶

Test the calculation of low-resolution 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 low-resolution 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 high-resolution 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 brute-force 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.

isocor.tests.test_isotopic_cluster_HighRes.test_isoclust_against_bruteforce(formula, data_iso, usr_tolerance)[source]

Check the high-resolution isotopic clusters generation against a brute force implementation.

## 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 low-resolution 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 low-resolution 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 13C-tracer experiment.

Test high-resolution 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 high-resolution 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 high-resolution 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 high-resolution 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 high-resolution and low-resolution correction matrices should be the same.

The high-resolution correction matrix calculated by IsoCor is compared to

1. a theoretical correction matrix (with algebraic equations provided in the code for manual check), and
2. 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 high-resolution MS data where none of the isotopic species are resolved from the tracer isotopologues, i.e. the high-resolution correction algorithm should provides the same correction matrix as the one computed using the low-resolution correction algorithm.

## Correction process examples¶

Test the entire low-resolution correction process at low-resolution.

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 non-tracer elements depending on resolution and formula.

Measured values should be corrected for the incorporation of natural isotopes of non-tracers 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 high-resolution correction process at high-resolution.

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 non-tracer elements depending on resolution and formula.

Measured values should be corrected for the incorporation of natural isotopes of non-tracers 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 high-resolution 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 high-resolution 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 pre-defined 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.

isocor.tests.conftest.data_iso()[source]

Typical isotopic data object.

isocor.tests.conftest.usr_tolerance()[source]

Platform-dependent tolerance.