Compound

Overview

class modifinder.classes.Compound(incoming_data=None, **kwargs)[source]

A class to represent a compound

The compound always has spectrum data. If the compound structure is known, it also has a structure property.

Known Compound Attributes

id (str) : The id of the compound

spectrum (Spectrum) : Spectrum Tuple representing mz, intensity, Precursor mass and Charge for mass spectrumetry data

Known Compound Attributes

structure (Chem.Mol): The structure of the compound

distances (dict): A dictionary of distances between every pair of atoms in the compound

peak_fragments_map (dict): A dictionary mapping peaks to fragments

Other Attributes

adduct_mass (float): The adduct mass, derived from the Adduct

is_known (bool): A boolean indicating whether the compound is known, derived from the structure

usi (str): The USI of the compound

name (str): The name of the compound

accession (str): The accession of the compound

library_membership (str): The GNPS library membership of the compound

exact_mass (float): The exact mass of the compound

Examples

Create a compound by providing the necessary information:

>>> compound = Compound(id="CCMSLIB00005435812", peaks=[[110.066925,38499.089844],[138.060638,412152.093750],[195.079575,6894530.000000],[195.200180,480874.812500],[196.082092,43027.628906]], precursor_mz=195.087, precursor_charge=1, adduct="[M+H]+", smiles="CN1C=NC2=C1C(=O)N(C(=O)N2C)C")

Alternatively, you can create a compound by providing a dictionary of data:

>>> data = {
...     "id": "CCMSLIB00005435812",
...     "peaks": [[110.066925,38499.089844],[138.060638,412152.093750],[195.079575,6894530.000000],[195.200180,480874.812500],[196.082092,43027.628906]],
...     "precursor_mz": 195.087,
...     "charge": 1,
...     "adduct": "[M+H]+",
...     "smiles": "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"
... }
>>> compound = Compound(data)

You can also create a compound by providing a usi:

>>> usi = "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00005435812"
>>> compound = Compound(usi)

or with an accession:

>>> accession = "CCMSLIB00005435812"
>>> compound = Compound(accession)
__init__(incoming_data=None, **kwargs)[source]

Initialize the Compound class

The compound class can be initialized in three different ways: 1. By providing a dictionary of data to the data parameter that contains all the necessary information 2. By providing a usi to the data parameter to retrieve the necessary information from GNPS 3. By providing the necessary information as parameter

If both the data and the parameters are provided, the parameters will override the data.

If of the incoming data and kwargs are provided, an empty instance of the class will be created.

Parameters:
  • incoming_data (input data (optional, default: None)) – The data to initialize the class with, can be a dictionary of data, a usi, or a compound object. If not provided, the class will be initialized with the provided keyword arguments. If provided, the keyword arguments will still override the data.

  • kwargs (keyword arguments (optional, default: No attributes)) – Attributes to initialize the class with, if provided, they will override the attributes from the data

Methods

calculate_annotation_entropy([peaks])

Calculate the entropy of the annotation

calculate_contribution_atom_in_peak(atom, ...)

Calculates the contribution of an atom to a peak

calculate_contributions(peakids[, CI, CPA, ...])

input: peakids: list of peak ids CI: (Consider_Intensity) bool, if True, the intensity of the peaks is considered (default: False) CPA: (Consider_Peak_Ambiguity) bool, if True, the peak ambiguity (number of fragments assigned to a peak) is considered (default: True) CFA: (Consider_Fragment_Ambiguity) bool, if True, the fragment ambiguity (number of atoms in fragment) is considered (default: True) CPA: (Consider_Peak_Entropy) bool, if True, the peak entropy (how ambiguis the fragments are) is considered (default: True

calculate_peak_annotation_ambiguity([peaks])

Calculate the peak annotation ambiguity

clear()

Clear the compound data and reset all the attributes to None

copy()

Return a copy of the compound

filter_fragments_by_atoms(atoms[, peaks])

Filter the fragments by the atoms, remove fragments that do not contain at least one of the atoms :param atoms: :type atoms: a list of atoms to filter the fragments :param peaks: :type peaks: a list of peaks to filter their fragments, if None, use all peaks

find_existance(peakids)

For each atom, and for each peak in the list, find the fragments that the atom is part of

get_meta_data()

Get the meta data of the compound

print_peaks_to_fragments_map([peaks])

Print the peaks to fragments map

update([structure, id, spectrum, usi, ...])

Update the attributes of the class