ModiFinder

Base class for ModiFinder.

This class is used to create a ModiFinder object. The object can be used to get information about unknown compounds in the network using the known compounds.

class modifinder.classes.ModiFinder.ModiFinder(knownCompond: Compound | None = None, unknownCompound: Compound | None = None, edgeDetail: EdgeDetail | None = None, helpers: list = [], network: DiGraph | None = None, networkUnknowns: list | None = None, should_align: bool = True, alignmentEngine: AlignmentEngine | None = None, should_annotate: bool = True, annotationEngine: AnnotationEngine | None = None, ppm_tolerance: float = 40, **kwargs)[source]

Bases: object

Base class for compound network.

ModiFinder Can be used in two scenarios 1. between a known and an unknown compound. 2. in a network consisting of known and unknown compounds.

In both scenarios, the ModiFinder object stores a directed graph where the nodes are compounds (known and unknown) and edges are directed (from smaller compound to the larger compound) holding the relationships between the pair (alignment, similarity, etc). The object also stores the unknown compounds in the network. The object can be used to get information about the unknown compound.

Parameters:
  • network (nx.DiGraph) – A networkx graph object with the nodes are identified by the compound ids and the “compound” attibute of a node is a Compound object. The edges are the relationships between the compounds and the “edgedetail” attribute of an edge is an EdgeDetail object.

  • unknowns (list) – A list of compound ids that are unknown in the network.

See also

Compound, EdgeDetail, Engines

Examples

add_adjusted_edge(u, v, edgeDetail: EdgeDetail | None = None, **kwargs)[source]

Add an edge between two compounds.

The method will add an edge between two compounds. If the edgeDetail is not passed, the method will align the spectra of the compounds using the alignment engine. If the edgeDetail is passed, It has to be from the smaller compound to the larger compound.

Parameters:
  • u (str) – The id of the first compound.

  • v (str) – The id of the second compound.

  • edgeDetail (EdgeDetail) – The edge detail between the compounds.

  • kwargs (dict) – Additional parameters to pass to the alignment engine.

add_neighbor(compound: Compound, neighbor: str, edgeDetail: EdgeDetail | None = None, **kwargs)[source]

Add a neighbor to a compound.

The method will add a neighbor to a compound. If the edgeDetail is not passed, the method will align the spectra of the compound and the neighbor using the alignment engine. If the edgeDetail is passed, It has to be from the smaller compound to the larger compound.

Parameters:
  • compound (Compound) – The compound to add the neighbor to.

  • neighbor (str) – The id of the neighbor compound.

  • edgeDetail (EdgeDetail) – The edge detail between the compound and the neighbor.

  • kwargs (dict) – Additional parameters to pass to the alignment engine.

draw_alignment(id1, id2, **kwargs)[source]

Draw the alignment between two compounds.

The method will draw the alignment between two compounds. The compounds must be in the network and connected by an edge.

See also

visualizer.draw_alignment

Parameters:
  • id1 (str) – The id of the first compound.

  • id2 (str) – The id of the second compound.

  • kwargs (dict) – Additional parameters to pass to the visualizer.

draw_prediction(probabilities, known_id, **kwargs)[source]
generate_probabilities(known_id=None, unknown_id=None, shifted_only=False, CI=False, CPA=True, CFA=True, CPE=True)[source]
get_edge_detail(id1, id2)[source]

Returns the edge detail between two compounds. If the backward edge exists, the matching data is replaced

Parameters:
  • id1 (str) – The id of the first compound.

  • id2 (str) – The id of the second compound.

Returns:

The edge detail between the two compounds.

Return type:

EdgeDetail

Raises:

ValueError – If the compounds are not connected in the network.

re_align(alignmentEngine: AlignmentEngine, **kwargs)[source]

Re-align the network. For each edge in the network, the method will re-align the edges using the alignment engine.

Parameters:
  • alignmentEngine (AlignmentEngine) – The alignment engine to use to align the unknown compound with the known compounds in the network.

  • kwargs (dict) – Additional parameters to pass to the alignment engine.

re_annotate(annotationEngine: AnnotationEngine, **kwargs)[source]

Annotate the network. For each node (Compound) in the network, the method will annotate the node using the annotation engine.

Parameters:
  • annotationEngine (AnnotationEngine) – The annotation engine to use to annotate the compounds in the network.

  • kwargs (dict) – Additional parameters to pass to the annotation engine.

solve(unknown: str, **kwargs)[source]

Solve the network.

The method will solve the network for an unknown compound

Parameters:
  • unknown (str) – The id of the unknown compound in the network.

  • alignmentEngine (AlignmentEngine) – The alignment engine to use to align the unknown compound with the known compounds in the network.

  • kwargs (dict) – Additional parameters.

Returns:

A dictionary with the following keys: - probabilities: the probabilities of the atoms in the unknown compound.

Return type:

dict

update_edge(u, v, edgeDetail: EdgeDetail | None = None, **kwargs)[source]

Update the edge between two compounds.

The method will update the edge between two compounds.