chemist-preprocessor-0.1.0.0: Chemist Raw Data Preprocessor
Safe HaskellSafe-Inferred
LanguageHaskell2010

Infrastructure.Database

Description

This module provides functions for interacting with a Neo4j graph database. It includes operations for fetching, creating, and removing reactions and mechanisms, as well as checking the health of the Neo4j server.

Functions

Error Handling

This module defines a custom exception type GraphElemError to handle errors related to missing nodes or relationships. The function headIO safely retrieves the head element from a list, throwing an exception if the list is empty.

Synopsis

Documentation

findPath :: MoleculeID -> MoleculeID -> BoltActionT IO Path #

Finds the shortest path between two molecules based on their IDs. The path consists of reactions and relationships between products and reagents.

Parameters:

  • MoleculeID - the unique identifier of the starting molecule.
  • MoleculeID - the unique identifier of the ending molecule.

Returns:

  • A Path representing the shortest path between the two molecules.

Exceptions:

  • GraphElemError if no path is found between the two molecules.
  • BoltError

withNeo4j :: forall b. BoltActionT IO b -> IO b #

Executes a given BoltActionT action within a Neo4j database context. Automatically handles connection opening and closing.

Parameters:

  • BoltActionT IO b - the action to execute.

Returns:

  • IO b - the result of the executed action.

Exceptions:

  • BoltError if the connection to the database fails or if the action encounters an error.

checkNeo4j :: BoltActionT IO HealthCheck #

Check the health of the Neo4j server by running a simple query.

Returns:

fetchReaction :: ReactionID -> BoltActionT IO (RawReactionDetails, Maybe MechanismNode) #

Fetches reaction details by its identifier from the Neo4j database. Returns a tuple containing RawReactionDetails and optionally MechanismNode.

Parameters:

  • ReactionID - the unique identifier of the reaction.

Returns:

  • `BoltActionT IO (RawReactionDetails, Maybe MechanismNode)`.

Exceptions:

  • GraphElemError if the expected nodes or relationships are not found.
  • BoltError

createReaction :: RawReactionDetailsMask -> BoltActionT IO ReactionNode #

Creates a new reaction in the Neo4j database using the provided details. Generates a query to insert a reaction node and related entities.

Parameters:

Returns:

Exceptions:

  • GraphElemError if the reaction creation fails.
  • BoltError

removeReaction :: ReactionID -> BoltActionT IO ReactionID #

Removes a reaction and its associated nodes from the Neo4j database based on the provided ReactionID.

Parameters:

  • ReactionID - the unique identifier of the reaction to remove.

Returns:

  • The ID of the removed reaction.

Exceptions:

  • BoltError

fetchMechanism :: MechanismID -> BoltActionT IO RawMechanismDetails #

Fetches mechanism details by its identifier from the Neo4j database. Retrieves the mechanism, its stages, participants, and relationships.

Parameters:

Returns:

Exceptions:

  • GraphElemError if the expected nodes or relationships are not found.
  • BoltError