java.lang.Object
de.uni_halle.informatik.biodata.mp.db.bigg.BiGGDB

public class BiGGDB extends Object
This class provides a connection to the BiGG database.
  • Constructor Details

    • BiGGDB

      public BiGGDB()
  • Method Details

    • init

      public static void init(DBParameters parameters)
    • init

      public static void init(String host, Integer port, String user, String passwd, String dbName)
    • getBiGGVersion

      public Optional<Date> getBiGGVersion() throws SQLException
      Retrieves the version date of the BiGG database. This method queries the database to fetch the date and time of the last update from the DATABASE_VERSION table. It returns an Optional containing the date if the query is successful and the date exists, otherwise it returns an empty Optional.
      Returns:
      Optional<Date> The date of the last database update, or an empty Optional if not available.
      Throws:
      SQLException
    • getSubsystems

      public List<String> getSubsystems(String modelBiGGid, String reactionBiGGid) throws SQLException
      Retrieves a list of distinct subsystems associated with a specific model and reaction BiGG IDs. This method executes a SQL query to fetch subsystems from the database where both the model and reaction match the provided BiGG IDs. Only subsystems with a non-zero length are considered.
      Parameters:
      modelBiGGid - The BiGG ID of the model.
      reactionBiGGid - The BiGG ID of the reaction.
      Returns:
      A List of subsystem names as strings. Returns an empty list if no subsystems are found or if an error occurs.
      Throws:
      SQLException
    • getSubsystemsForReaction

      public List<String> getSubsystemsForReaction(String reactionBiGGid) throws SQLException
      Retrieves a list of distinct subsystems associated with a specific reaction BiGG ID. This method executes a SQL query to fetch subsystems from the database where the reaction matches the provided BiGG ID. Only subsystems with a non-zero length are considered.
      Parameters:
      reactionBiGGid - The BiGG ID of the reaction for which subsystems are to be retrieved.
      Returns:
      A List of subsystem names as strings. Returns an empty list if no subsystems are found or if an error occurs.
      Throws:
      SQLException
    • getChemicalFormulaByCompartment

      public Optional<String> getChemicalFormulaByCompartment(String componentId, String compartmentId) throws SQLException
      Retrieves the unique chemical formula for a given component within a specific compartment. This method queries the database to find the distinct chemical formula associated with the specified component and compartment IDs. It ensures that the formula is unique for the given parameters. If multiple distinct formulas are found, it logs a warning indicating ambiguity.
      Parameters:
      componentId - The BiGG ID of the component for which the chemical formula is to be retrieved.
      compartmentId - The BiGG ID of the compartment where the component is located.
      Returns:
      An Optional containing the chemical formula if exactly one unique formula is found, otherwise an empty Optional if none or multiple formulas are found.
      Throws:
      SQLException
    • getChemicalFormula

      public Optional<String> getChemicalFormula(String componentId, String modelId) throws SQLException
      Retrieves the chemical formula for a given component within a specific model in the BiGG database. This method executes a SQL query to find distinct chemical formulas associated with the component and model IDs provided. If exactly one unique formula is found, it is returned. If none or multiple formulas are found, an empty Optional is returned. In case of multiple formulas, a log entry is made indicating the ambiguity.
      Parameters:
      componentId - The BiGG ID of the component for which the formula is being retrieved.
      modelId - The BiGG ID of the model in which the component is present.
      Returns:
      An Optional<String> containing the chemical formula if exactly one is found, otherwise empty.
      Throws:
      SQLException
    • getCompartmentName

      public Optional<String> getCompartmentName(BiGGId biggId) throws SQLException
      Retrieves the name of the compartment associated with the given BiGG ID from the database. This method constructs a SQL query to select the compartment name where the BiGG ID matches and the name is not an empty string.
      Parameters:
      biggId - The BiGGId object containing the abbreviation of the compartment.
      Returns:
      An Optional<String> containing the name of the compartment if found, otherwise empty.
      Throws:
      SQLException
    • singleParamStatement

      public Optional<String> singleParamStatement(String query, String param) throws SQLException
      Executes a SQL query with a single parameter and returns the result as an Optional. This method is designed to handle queries that are expected to return a single result. If multiple results are found, a severe log is recorded indicating the issue.
      Parameters:
      query - The SQL query to be executed. It should contain exactly one placeholder for the parameter.
      param - The parameter value to be used in the SQL query.
      Returns:
      An Optional<String> containing the result if exactly one result is found, otherwise empty.
      Throws:
      SQLException
    • getComponentName

      public Optional<String> getComponentName(BiGGId biggId) throws SQLException
      Retrieves the name of the component associated with the given BiGG ID from the database. This method constructs a SQL query to select the component name where the BiGG ID matches and the name is not an empty string.
      Parameters:
      biggId - The BiGGId object containing the abbreviation of the component.
      Returns:
      An Optional<String> containing the name of the component if found, otherwise empty.
      Throws:
      SQLException
    • getComponentType

      public Optional<String> getComponentType(BiGGId biggId) throws SQLException
      Retrieves the type of the component associated with the given BiGG ID from the database. This method constructs a SQL query to select the component type where the BiGG ID matches and the name field is not an empty string.
      Parameters:
      biggId - The BiGGId object containing the abbreviation of the component.
      Returns:
      An Optional<String> containing the type of the component if found, otherwise empty.
      Throws:
      SQLException
    • getGeneIds

      public TreeSet<IdentifiersOrgURI> getGeneIds(String label) throws SQLException
      Retrieves all possible MIRIAM-compliant gene identifiers from the database based on a given label. This method queries the database for gene identifiers that match the provided label and are compliant with MIRIAM standards. Non-compliant entries are ignored.
      Parameters:
      label - The label used to query gene identifiers.
      Returns:
      A TreeSet containing unique, sorted MIRIAM-compliant gene identifiers.
      Throws:
      SQLException
    • getGeneName

      public Optional<String> getGeneName(String label) throws SQLException
      Retrieves the gene name from the database based on a given label. This method constructs a SQL query to fetch the synonym of a gene that matches the given label, ensuring that the gene is associated with a valid data source and genome region, and that the synonym is not empty. The query specifically looks for entries where the data source's BIGG ID matches the REFSEQ naming convention.
      Parameters:
      label - The label used to query the gene name, typically a BIGG ID.
      Returns:
      An Optional containing the gene name if found, otherwise an empty Optional.
      Throws:
      SQLException
    • getGeneReactionRule

      public List<String> getGeneReactionRule(String reactionId, String modelId) throws SQLException
      Retrieves formatted gene reaction rules for a specific reaction and model from the database. This method constructs a SQL query to fetch and format the gene reaction rules associated with the given reaction ID and model ID. The formatting includes replacing logical operators 'or' and 'and' with || and &&, respectively, and substituting certain characters to comply with SBML standards.
      Parameters:
      reactionId - The ID of the reaction for which gene reaction rules are to be retrieved.
      modelId - The ID of the model associated with the reaction.
      Returns:
      A list of formatted gene reaction rules as strings.
      Throws:
      SQLException
    • getReactionRules

      public List<String> getReactionRules(String query, String reactionId, String modelId) throws SQLException
      Executes a provided SQL query to retrieve gene reaction rules from the database. This method prepares a statement with the given query, setting the specified reactionId and modelId as parameters. It then executes the query and collects the results into a list of strings.
      Parameters:
      query - The SQL query string that retrieves gene reaction rules, expecting two placeholders for parameters.
      reactionId - The ID of the reaction to be used as the first parameter in the SQL query.
      modelId - The ID of the model to be used as the second parameter in the SQL query.
      Returns:
      A list of strings where each string is a gene reaction rule retrieved based on the given IDs.
      Throws:
      SQLException
    • getOrganism

      public Optional<String> getOrganism(String abbreviation) throws SQLException
      Retrieves the organism associated with a given BiGG model abbreviation from the database. This method constructs and executes a SQL query that joins the GENOME and MODEL tables to find the organism corresponding to the specified model abbreviation.
      Parameters:
      abbreviation - The abbreviation of the model for which the organism is to be retrieved.
      Returns:
      An Optional containing the organism name if found, otherwise an empty Optional.
      Throws:
      SQLException
    • getPublications

      public List<Publication> getPublications(String abbreviation) throws SQLException
      Retrieves a list of publications associated with a given BiGG model abbreviation from the database. This method constructs and executes a SQL query that joins the PUBLICATION, PUBLICATION_MODEL, and MODEL tables to find the publications related to the specified model abbreviation.
      Parameters:
      abbreviation - The abbreviation of the model for which the publications are to be retrieved.
      Returns:
      A list of pairs where each pair consists of a publication type and its corresponding ID.
      Throws:
      SQLException
    • getReactionName

      public Optional<String> getReactionName(String abbreviation) throws SQLException
      Retrieves the name of a reaction based on its BiGG ID abbreviation, ensuring the name is not empty. This method constructs and executes a SQL query that selects the reaction name from the REACTION table where the BIGG_ID matches the specified abbreviation and the name is not an empty string.
      Parameters:
      abbreviation - The abbreviation of the reaction for which the name is to be retrieved.
      Returns:
      An Optional containing the reaction name if found and not empty, otherwise an empty Optional.
      Throws:
      SQLException
    • getResources

      public Set<IdentifiersOrgURI> getResources(BiGGId biggId, boolean includeAnyURI, boolean isReaction) throws SQLException
      Retrieves a set of resource URLs for a given BiGG ID, optionally filtering to include only those containing 'identifiers.org'. This method constructs and executes a SQL query to fetch URLs from the database based on the type of BiGG ID (reaction or component). It then filters these URLs based on the 'includeAnyURI' parameter.
      Parameters:
      biggId - The BiGG ID object containing the abbreviation of the model component or reaction.
      includeAnyURI - If true, all URLs are included; if false, only URLs containing 'identifiers.org' are included.
      isReaction - If true, the BiGG ID is treated as a reaction; if false, it is treated as a component.
      Returns:
      A sorted set of URLs as strings, potentially filtered by the 'identifiers.org' domain.
      Throws:
      SQLException
    • getTaxonId

      public Optional<Integer> getTaxonId(String abbreviation) throws SQLException
      Retrieves the taxonomic identifier (taxon ID) for a given model based on its abbreviation. This method queries the database to find the taxon ID associated with the model's abbreviation. If multiple taxon IDs are found for the same abbreviation, a severe log message is generated.
      Parameters:
      abbreviation - The abbreviation of the model for which the taxon ID is being queried.
      Returns:
      An Optional containing the taxon ID if found; otherwise, an empty Optional.
      Throws:
      SQLException
    • getGenomeAccesion

      public String getGenomeAccesion(String id) throws SQLException
      Retrieves the genome accession for a given model ID from the BiGG database. The accession can be used to construct URLs for accessing genomic data from various sources. The URLs can be formed using the accession ID with the following patterns: - https://identifiers.org/refseq:{$id} - https://www.ncbi.nlm.nih.gov/nuccore/{$id} - https://www.ncbi.nlm.nih.gov/assembly/{$id}
      Parameters:
      id - The model ID present in BiGG.
      Returns:
      The accession string which can be appended to the base URLs mentioned above. If the query fails or no accession is found, an empty string is returned.
      Throws:
      SQLException
    • getAllBiggIds

      public Set<String> getAllBiggIds(String table) throws SQLException
      Retrieves a set of unique BiGG IDs from a specified table in the database. This method queries the database for all unique BiGG IDs in the specified table and returns them as a set. The IDs are ordered by their natural ordering in the database.
      Parameters:
      table - The name of the database table from which to retrieve BiGG IDs.
      Returns:
      A Set of strings containing unique BiGG IDs from the specified table. If an SQL error occurs, the returned set will be empty.
      Throws:
      SQLException
    • getChargeByCompartment

      public Optional<Integer> getChargeByCompartment(String componentId, String compartmentId) throws SQLException
      Retrieves the charge associated with a specific component in a given compartment when the model ID is unknown. This method executes a SQL query to find a distinct charge value for a component based on its BiGG ID and the compartment's BiGG ID. The method ensures that the charge value is not empty and returns it if it is unique.
      Parameters:
      componentId - The BiGG ID of the component.
      compartmentId - The BiGG ID of the compartment.
      Returns:
      An Optional containing the charge if it is unique and present; otherwise, an empty Optional. If multiple unique charge values are found, a warning is logged.
      Throws:
      SQLException
    • getCharge

      public Optional<Integer> getCharge(String componentId, String modelId) throws SQLException
      Retrieves the charge for a given component and model from the database. This method executes a SQL query to select distinct charge values associated with the specified component ID and model ID. It ensures that the charge value is not null.
      Parameters:
      componentId - The BiGG ID of the component.
      modelId - The BiGG ID of the model.
      Returns:
      An Optional containing the charge if exactly one distinct charge is found, otherwise an empty Optional. If multiple distinct charges are found, a warning is logged.
      Throws:
      SQLException
    • isPseudoreaction

      public boolean isPseudoreaction(String reactionId) throws SQLException
      Determines if a given reaction ID corresponds to a pseudoreaction in the database. A pseudoreaction is typically used to represent non-biochemical data flows such as biomass accumulation, demand reactions, or exchange reactions.
      Parameters:
      reactionId - The BiGG ID of the reaction to be checked.
      Returns:
      true if the reaction is a pseudoreaction, false otherwise.
      Throws:
      SQLException
    • getBiggIdFromSynonym

      public Optional<BiGGId> getBiggIdFromSynonym(String dataSourceId, String synonym, String type)
      Retrieves the BiGG ID associated with a given synonym and type from the specified data source. This method constructs a SQL query based on the type of biological entity (species, reaction, or gene product) and executes it to fetch the corresponding BiGG ID from the database.
      Parameters:
      dataSourceId - The ID of the data source where the synonym is registered.
      synonym - The synonym used to identify the entity in the data source.
      type - The type of the entity, which can be species, reaction, or gene product.
      Returns:
      An Optional containing the BiGG ID if exactly one unique ID is found, otherwise an empty Optional.
    • getBiggIdsForReactionForeignId

      public Collection<BiGGDB.ForeignReaction> getBiggIdsForReactionForeignId(RegistryURI uri)
      Retrieves a collection of ForeignReaction objects for a given synonym and data source ID. This method queries the database to find reactions and their associated compartment details based on the provided synonym and data source ID. The term "foreign" indicates that the reactions are identified using external data sources, which are then mapped to corresponding entities in the BiGG database.
      Returns:
      A collection of ForeignReaction objects containing the reaction and compartment details.
    • isCompartment

      public boolean isCompartment(String id) throws SQLException
      Throws:
      SQLException
    • isDataSource

      public boolean isDataSource(String id) throws SQLException
      Throws:
      SQLException
    • isMetabolite

      public boolean isMetabolite(String id) throws SQLException
      Throws:
      SQLException
    • isModel

      public boolean isModel(String id) throws SQLException
      Throws:
      SQLException
    • isReaction

      public boolean isReaction(String id) throws SQLException
      Throws:
      SQLException