Utilities
nplinker.metabolomics.utils
¶
add_annotation_to_spectrum
¶
Add annotations to the Spectrum.gnps_annotations
attribute for input spectra.
It is possible that some spectra don't have annotations.
Note
The input spectra
list is changed in place.
Parameters:
-
annotations
(Mapping[str, dict]
) –A dictionary of GNPS annotations, where the keys are spectrum ids and the values are GNPS annotations.
-
spectra
(Sequence[Spectrum]
) –A list of Spectrum objects.
Source code in src/nplinker/metabolomics/utils.py
add_strains_to_spectrum
¶
add_strains_to_spectrum(
strains: StrainCollection, spectra: Sequence[Spectrum]
) -> tuple[list[Spectrum], list[Spectrum]]
Add Strain
objects to the Spectrum.strains
attribute for input spectra.
Note
The input spectra
list is changed in place.
Parameters:
-
strains
(StrainCollection
) –A collection of strain objects.
-
spectra
(Sequence[Spectrum]
) –A list of Spectrum objects.
Returns:
-
tuple[list[Spectrum], list[Spectrum]]
–A tuple of two lists of Spectrum objects,
- the first list contains Spectrum objects that are updated with Strain objects;
- the second list contains Spectrum objects that are not updated with Strain objects because no Strain objects are found.
Source code in src/nplinker/metabolomics/utils.py
add_spectrum_to_mf
¶
add_spectrum_to_mf(
spectra: Sequence[Spectrum],
mfs: Sequence[MolecularFamily],
) -> tuple[
list[MolecularFamily],
list[MolecularFamily],
dict[MolecularFamily, set[str]],
]
Add Spectrum objects to MolecularFamily objects.
The attribute MolecularFamily.spectra_ids
contains the ids of Spectrum
objects.
These ids are used to find Spectrum
objects from the input spectra
list. The found Spectrum
objects are added to the MolecularFamily.spectra
attribute.
It is possible that some spectrum ids are not found in the input spectra
list, and so their
Spectrum
objects are missing in the MolecularFamily
object.
Note
The input mfs
list is changed in place.
Parameters:
-
spectra
(Sequence[Spectrum]
) –A list of Spectrum objects.
-
mfs
(Sequence[MolecularFamily]
) –A list of MolecularFamily objects.
Returns:
-
tuple[list[MolecularFamily], list[MolecularFamily], dict[MolecularFamily, set[str]]]
–A tuple of three elements,
- the first list contains
MolecularFamily
objects that are updated withSpectrum
objects - the second list contains
MolecularFamily
objects that are not updated withSpectrum
objects (allSpectrum
objects are missing). - the third is a dictionary containing
MolecularFamily
objects as keys and a set of ids of missingSpectrum
objects as values.
- the first list contains
Source code in src/nplinker/metabolomics/utils.py
extract_mappings_strain_id_ms_filename
¶
extract_mappings_strain_id_ms_filename(
podp_project_json_file: str | PathLike,
) -> dict[str, set[str]]
Extract mappings "strain_id <-> MS_filename".
Parameters:
Returns:
Notes
The podp_project_json_file
is the project JSON file downloaded from
PODP platform. For example, for project MSV000079284, its json file is
https://pairedomicsdata.bioinformatics.nl/api/projects/4b29ddc3-26d0-40d7-80c5-44fb6631dbf9.4.
See Also
- podp_generate_strain_mappings: Generate strain mappings JSON file for PODP pipeline.
Source code in src/nplinker/metabolomics/utils.py
extract_mappings_ms_filename_spectrum_id
¶
extract_mappings_ms_filename_spectrum_id(
gnps_file_mappings_file: str | PathLike,
) -> dict[str, set[str]]
Extract mappings "MS_filename <-> spectrum_id".
Parameters:
Returns:
Notes
The gnps_file_mappings_file
is downloaded from GNPS website and named as
GNPS_FILE_MAPPINGS_TSV or
GNPS_FILE_MAPPINGS_CSV.
For more details, see GNPS data.
See Also
- GNPSFileMappingLoader: Load GNPS file mappings file.
- podp_generate_strain_mappings: Generate strain mappings JSON file for PODP pipeline.
Source code in src/nplinker/metabolomics/utils.py
get_mappings_strain_id_spectrum_id
¶
get_mappings_strain_id_spectrum_id(
mappings_strain_id_ms_filename: Mapping[str, set[str]],
mappings_ms_filename_spectrum_id: Mapping[
str, set[str]
],
) -> dict[str, set[str]]
Get mappings "strain_id <-> spectrum_id".
Parameters:
-
mappings_strain_id_ms_filename
(Mapping[str, set[str]]
) –Mappings "strain_id <-> MS_filename".
-
mappings_ms_filename_spectrum_id
(Mapping[str, set[str]]
) –Mappings "MS_filename <-> spectrum_id".
Returns:
See Also
extract_mappings_strain_id_ms_filename
: Extract mappings "strain_id <-> MS_filename".extract_mappings_ms_filename_spectrum_id
: Extract mappings "MS_filename <-> spectrum_id".- podp_generate_strain_mappings: Generate strain mappings JSON file for PODP pipeline.