| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
checkNeo4j: Checks the health of the Neo4j server and returns aHealthCheckstructure indicating the server status.fetchReaction: Retrieves details of a reaction by itsReactionID. Returns a tuple containingRawReactionDetailsand an optionalMechanismNode.createReaction: Creates a new reaction in the database using the providedRawReactionDetailsMask. Returns the createdReactionNode.removeReaction: Removes a reaction and its associated nodes from the database based on the providedReactionID. Returns the ID of the removed reaction.findPath: Finds the shortest path between two molecules specified by their IDs. Returns aPathrepresenting the shortest path.fetchMechanism: Fetches mechanism details by its identifier from the Neo4j database. Returns aRawMechanismDetailsstructure representing the mechanism and its stages.withNeo4j: Executes a givenBoltActionTaction within a Neo4j database context, handling connection opening and closing.
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
- findPath :: MoleculeID -> MoleculeID -> BoltActionT IO Path
- withNeo4j :: forall b. BoltActionT IO b -> IO b
- checkNeo4j :: BoltActionT IO HealthCheck
- fetchReaction :: ReactionID -> BoltActionT IO (RawReactionDetails, Maybe MechanismNode)
- createReaction :: RawReactionDetailsMask -> BoltActionT IO ReactionNode
- removeReaction :: ReactionID -> BoltActionT IO ReactionID
- fetchMechanism :: MechanismID -> BoltActionT IO RawMechanismDetails
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
Pathrepresenting the shortest path between the two molecules.
Exceptions:
GraphElemErrorif 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:
BoltErrorif 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:
- A
HealthCheckstructure indicating server status.
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:
GraphElemErrorif 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:
RawReactionDetailsMask- containing the details for the new reaction.
Returns:
- The created
ReactionNode.
Exceptions:
GraphElemErrorif 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:
MechanismID- the unique identifier of the mechanism.
Returns:
- A
RawMechanismDetailsrepresenting the mechanism and its stages.
Exceptions:
GraphElemErrorif the expected nodes or relationships are not found.BoltError