Defines an enumeration for regex patterns that are used to categorize reactions based on their ID strings.
Each enum constant represents a specific type of reaction and is associated with a regex pattern that matches
reaction IDs corresponding to that type.
@@ -153,12 +153,12 @@ geneReactionRules = bigg.getGeneReactionRule(abbreviation, reaction.getModel().getId());
for (String geneReactionRule : geneReactionRules) {
- GPRParser.parseGPR(reaction, geneReactionRule, sboParameters.addGenericTerms());
+ GPRParser.setGeneProductAssociation(reaction, geneReactionRule, sboParameters.addGenericTerms());
}
}
diff --git a/src/main/java/edu/ucsd/sbrg/annotation/bigg/BiGGSBMLAnnotator.java b/src/main/java/edu/ucsd/sbrg/annotation/bigg/BiGGSBMLAnnotator.java
index 4e5c3554..30788089 100644
--- a/src/main/java/edu/ucsd/sbrg/annotation/bigg/BiGGSBMLAnnotator.java
+++ b/src/main/java/edu/ucsd/sbrg/annotation/bigg/BiGGSBMLAnnotator.java
@@ -8,7 +8,7 @@
import edu.ucsd.sbrg.parameters.BiGGAnnotationParameters;
import edu.ucsd.sbrg.parameters.SBOParameters;
import edu.ucsd.sbrg.annotation.AnnotationsSorter;
-import edu.ucsd.sbrg.annotation.bigg.fbc.BiGGFBCAnnotator;
+import edu.ucsd.sbrg.annotation.bigg.ext.fbc.BiGGFBCAnnotator;
import edu.ucsd.sbrg.reporting.ProgressObserver;
import edu.ucsd.sbrg.resolver.Registry;
import org.sbml.jsbml.Model;
diff --git a/src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGFBCAnnotator.java b/src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGFBCAnnotator.java
similarity index 97%
rename from src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGFBCAnnotator.java
rename to src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGFBCAnnotator.java
index 9db7d7c2..76db4305 100644
--- a/src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGFBCAnnotator.java
+++ b/src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGFBCAnnotator.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.annotation.bigg.fbc;
+package edu.ucsd.sbrg.annotation.bigg.ext.fbc;
import edu.ucsd.sbrg.annotation.IAnnotateSBases;
import edu.ucsd.sbrg.parameters.BiGGAnnotationParameters;
diff --git a/src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGGeneProductAnnotator.java b/src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGGeneProductAnnotator.java
similarity index 99%
rename from src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGGeneProductAnnotator.java
rename to src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGGeneProductAnnotator.java
index cd44429e..fa308818 100644
--- a/src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGGeneProductAnnotator.java
+++ b/src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGGeneProductAnnotator.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.annotation.bigg.fbc;
+package edu.ucsd.sbrg.annotation.bigg.ext.fbc;
import de.zbit.util.ResourceManager;
import edu.ucsd.sbrg.annotation.IAnnotateSBases;
diff --git a/src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGGeneProductReferencesAnnotator.java b/src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGGeneProductReferencesAnnotator.java
similarity index 98%
rename from src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGGeneProductReferencesAnnotator.java
rename to src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGGeneProductReferencesAnnotator.java
index 325f5565..1b78d9cf 100644
--- a/src/main/java/edu/ucsd/sbrg/annotation/bigg/fbc/BiGGGeneProductReferencesAnnotator.java
+++ b/src/main/java/edu/ucsd/sbrg/annotation/bigg/ext/fbc/BiGGGeneProductReferencesAnnotator.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.annotation.bigg.fbc;
+package edu.ucsd.sbrg.annotation.bigg.ext.fbc;
import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Reaction;
diff --git a/src/main/java/edu/ucsd/sbrg/db/bigg/BiGGId.java b/src/main/java/edu/ucsd/sbrg/db/bigg/BiGGId.java
index 6445dbca..22b19150 100644
--- a/src/main/java/edu/ucsd/sbrg/db/bigg/BiGGId.java
+++ b/src/main/java/edu/ucsd/sbrg/db/bigg/BiGGId.java
@@ -102,13 +102,7 @@ public BiGGId(String prefix, String abbreviation, String compartmentCode, String
parseBiGGId(id);
}
- /**
- * Creates a BiGG ID for a metabolite based on the provided string identifier.
- * This method handles the correction and standardization of the metabolite ID according to BiGG database standards.
- *
- * @param id The raw metabolite ID string.
- * @return An Optional containing the BiGGId if the ID is non-empty and valid, or an empty Optional otherwise.
- */
+
public static BiGGId createMetaboliteId(String id) {
// Fix the compartment code in the ID
id = fixCompartmentCode(id);
@@ -139,18 +133,6 @@ public static BiGGId createMetaboliteId(String id) {
}
- /**
- * Creates a BiGG ID for a gene, with an option to correct the ID to conform to BiGG standards.
- *
- * This method first checks if the provided ID is empty, returning an empty Optional if true.
- * If the 'correct' parameter is true, the ID is processed to conform to BiGG standards:
- * - Leading underscores are removed.
- * - The prefix "g_" is replaced with "G_" to standardize the gene ID format.
- * - If the ID does not start with "G_", the prefix "G_" is prepended.
- *
- * @param id The raw gene ID string.
- * @return An Optional containing the BiGGId if the ID is non-empty and valid, or an empty Optional otherwise.
- */
public static BiGGId createGeneId(String id) {
id = makeBiGGConform(id);
if (id.startsWith("_")) {
@@ -164,14 +146,7 @@ public static BiGGId createGeneId(String id) {
return new BiGGId(id);
}
- /**
- * Creates a BiGG ID for a reaction based on the provided string identifier.
- * This method handles the prefix stripping and checks if the reaction is a pseudo-reaction.
- * Depending on these checks, it delegates to the overloaded createReactionId method with appropriate flags.
- *
- * @param id The raw reaction ID string.
- * @return An Optional containing the BiGGId if the ID is non-empty and valid, or an empty Optional otherwise.
- */
+
public static BiGGId createReactionId(String id) {
String prefixStripped = "";
// Strip the prefix if it starts with 'R_' or 'r_'
@@ -250,8 +225,12 @@ private static String makeBiGGConform(String id) {
id = "_" + id;
}
// Replace problematic characters with specific strings
- id = id.replaceAll("[-/]", "__").replaceAll("\\.", "__SBML_DOT__").replaceAll("\\(", "_LPAREN_")
- .replaceAll("\\)", "_RPAREN_").replaceAll("\\[", "_LBRACKET_").replaceAll("]", "_RBRACKET_");
+ id = id.replaceAll("[-/]", "__")
+ .replaceAll("\\.", "__SBML_DOT__")
+ .replaceAll("\\(", "_LPAREN_")
+ .replaceAll("\\)", "_RPAREN_")
+ .replaceAll("\\[", "_LBRACKET_")
+ .replaceAll("]", "_RBRACKET_");
// Extract and reformat compartment codes enclosed in parentheses
Pattern parenCompartment = Pattern.compile("_LPAREN_(?.*?)_RPAREN_");
Matcher parenMatcher = parenCompartment.matcher(id);
@@ -353,13 +332,13 @@ private void parseBiGGId(String id) {
*/
private void handleNormalId(Matcher matcher) {
String prefix = matcher.group("prefix");
- setPrefix(prefix);
+ this.setPrefix(prefix);
String abbreviation = matcher.group("abbreviation");
- setAbbreviation(abbreviation);
+ this.setAbbreviation(abbreviation);
String compartment = matcher.group("compartment");
- setCompartmentCode(compartment);
+ this.setCompartmentCode(compartment);
String tissueCode = matcher.group("tissueCode");
- setTissueCode(tissueCode);
+ this.setTissueCode(tissueCode);
}
@@ -380,17 +359,17 @@ private void handleSpecialCases(String id) {
id = id.replaceAll("^([Rr]_?)?[Ee][Xx]", "EX");
id = id.replaceAll("^([Rr]_?)?[Dd][Mm]", "DM");
id = id.replaceAll("^([Rr]_?)?[Ss]([Ii][Nn])?[Kk]", "SK");
- setAbbreviation(id);
+ this.setAbbreviation(id);
} else if (biomassMatcher.matches()) {
id = id.replaceAll("^([Rr]_?)?[Bb][Ii][Oo][Mm][Aa][Ss][Ss]", "BIOMASS");
- setAbbreviation(id);
+ this.setAbbreviation(id);
} else if (atpmMatcher.matches()) {
- setAbbreviation("ATPM");
+ this.setAbbreviation("ATPM");
} else if (compartmentMatcher.matches()) {
- setAbbreviation(id);
+ this.setAbbreviation(id);
} else {
logger.info(format(MESSAGES.getString("BIGGID_CONVERSION_FAIL"), id));
- setAbbreviation(id);
+ this.setAbbreviation(id);
}
}
diff --git a/src/main/java/edu/ucsd/sbrg/io/parsers/cobra/MatlabParser.java b/src/main/java/edu/ucsd/sbrg/io/parsers/cobra/MatlabParser.java
index b8c5998a..674ba119 100644
--- a/src/main/java/edu/ucsd/sbrg/io/parsers/cobra/MatlabParser.java
+++ b/src/main/java/edu/ucsd/sbrg/io/parsers/cobra/MatlabParser.java
@@ -219,7 +219,7 @@ private void parseGPRs(Model model) {
if (model.getReaction(i) == null) {
logger.info(format(MESSAGES.getString("CREATE_GPR_FAILED"), i));
} else {
- GPRParser.parseGPR(model.getReaction(i), geneReactionRule, sboParameters.addGenericTerms());
+ GPRParser.setGeneProductAssociation(model.getReaction(i), geneReactionRule, sboParameters.addGenericTerms());
}
}
});
diff --git a/src/main/java/edu/ucsd/sbrg/io/parsers/json/JSONParser.java b/src/main/java/edu/ucsd/sbrg/io/parsers/json/JSONParser.java
index 64a3f828..5a328436 100644
--- a/src/main/java/edu/ucsd/sbrg/io/parsers/json/JSONParser.java
+++ b/src/main/java/edu/ucsd/sbrg/io/parsers/json/JSONParser.java
@@ -365,7 +365,7 @@ public void parseReaction(ModelBuilder builder, Reaction reaction, String id) {
setReactionStoichiometry(reaction, model, r);
String geneReactionRule = reaction.getGeneReactionRule();
if (!geneReactionRule.isEmpty()) {
- GPRParser.parseGPR(r, geneReactionRule, false);
+ GPRParser.setGeneProductAssociation(r, geneReactionRule, false);
}
createSubsystem(model, reaction, r);
setObjectiveCoefficient(reaction, model, r);
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/ModelPolisher.java b/src/main/java/edu/ucsd/sbrg/polishing/ModelPolisher.java
index b8acbfbe..8aad8cda 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/ModelPolisher.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ModelPolisher.java
@@ -17,7 +17,7 @@
import de.zbit.util.ResourceManager;
import edu.ucsd.sbrg.parameters.PolishingParameters;
import edu.ucsd.sbrg.parameters.SBOParameters;
-import edu.ucsd.sbrg.polishing.fbc.FBCPolisher;
+import edu.ucsd.sbrg.polishing.ext.fbc.FBCPolisher;
import edu.ucsd.sbrg.reporting.ProgressObserver;
import edu.ucsd.sbrg.resolver.Registry;
import org.sbml.jsbml.*;
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/ReactionsPolisher.java b/src/main/java/edu/ucsd/sbrg/polishing/ReactionsPolisher.java
index 418a4d72..0c79cdcd 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/ReactionsPolisher.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ReactionsPolisher.java
@@ -1,170 +1,173 @@
-package edu.ucsd.sbrg.polishing;
-
-import edu.ucsd.sbrg.parameters.PolishingParameters;
-import edu.ucsd.sbrg.parameters.SBOParameters;
-import edu.ucsd.sbrg.db.bigg.BiGGId;
-import edu.ucsd.sbrg.resolver.Registry;
-import edu.ucsd.sbrg.reporting.ProgressObserver;
-import edu.ucsd.sbrg.util.ReactionNamePatterns;
-import org.sbml.jsbml.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-
-/**
- * This class provides methods to polish and validate SBML reactions according to specific rules and patterns.
- * It includes functionality to:
- * - Check and set SBO terms based on reaction ID patterns.
- * - Polish species references and compartments.
- * - Validate and set flux bounds and objectives.
- * - Convert gene associations from reaction notes to FBCv2 format.
- * - Check mass and atom balance of reactions.
- *
- * The class operates on an SBML {@link Reaction} object and modifies it to conform to standards and conventions
- * used in systems biology models, particularly those related to flux balance constraints.
- */
-public class ReactionsPolisher extends AbstractPolisher implements IPolishSBases {
-
- private static final Logger logger = LoggerFactory.getLogger(ReactionsPolisher.class);
-
- private final SBOParameters sboParameters;
-
- public ReactionsPolisher(PolishingParameters polishingParameters,
- SBOParameters sboParameters,
- Registry registry) {
- super(polishingParameters, registry);
- this.sboParameters = sboParameters;
- }
+ package edu.ucsd.sbrg.polishing;
- public ReactionsPolisher(PolishingParameters polishingParameters,
- SBOParameters sboParameters,
- Registry registry,
- List observers) {
- super(polishingParameters, registry, observers);
- this.sboParameters = sboParameters;
- }
+ import edu.ucsd.sbrg.parameters.PolishingParameters;
+ import edu.ucsd.sbrg.parameters.SBOParameters;
+ import edu.ucsd.sbrg.db.bigg.BiGGId;
+ import edu.ucsd.sbrg.resolver.Registry;
+ import edu.ucsd.sbrg.reporting.ProgressObserver;
+ import edu.ucsd.sbrg.util.ReactionNamePatterns;
+ import org.sbml.jsbml.*;
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
- @Override
- public void polish(List reactions) {
- logger.debug("Polish Reactions");
+ import java.util.List;
+ import java.util.Objects;
+ import java.util.Optional;
+ import java.util.stream.Collectors;
- for (var reaction : reactions) {
- statusReport("Polishing Reactions (5/9) ", reaction);
- polish(reaction);
- }
- }
/**
- * Polishes the reaction by applying various checks and modifications to ensure it conforms to
- * the expected standards and conventions. This includes setting SBO terms, checking compartments,
- * and ensuring proper setup of reactants and products.
+ * This class provides methods to polish and validate SBML reactions according to specific rules and patterns.
+ * It includes functionality to:
+ * - Check and set SBO terms based on reaction ID patterns.
+ * - Polish species references and compartments.
+ * - Validate and set flux bounds and objectives.
+ * - Convert gene associations from reaction notes to FBCv2 format.
+ * - Check mass and atom balance of reactions.
+ *
+ * The class operates on an SBML {@link Reaction} object and modifies it to conform to standards and conventions
+ * used in systems biology models, particularly those related to flux balance constraints.
*/
- @Override
- public void polish(Reaction reaction) {
- var originalReaction = reaction.clone();
- // Process any external resources linked via annotations in the reaction
- new AnnotationPolisher(polishingParameters, registry).polish(reaction.getAnnotation());
+ public class ReactionsPolisher extends AbstractPolisher implements IPolishSBases {
- setMetaId(reaction);
+ private static final Logger logger = LoggerFactory.getLogger(ReactionsPolisher.class);
- if (sboParameters.addGenericTerms()) {
- if (reaction.isSetListOfReactants()) {
- new SpeciesReferencesPolisher(SBO.getReactant()).polish(reaction.getListOfReactants());
- }
- if (reaction.isSetListOfProducts()) {
- new SpeciesReferencesPolisher(SBO.getProduct()).polish(reaction.getListOfProducts());
+ private final SBOParameters sboParameters;
+
+ public ReactionsPolisher(PolishingParameters polishingParameters,
+ SBOParameters sboParameters,
+ Registry registry) {
+ super(polishingParameters, registry);
+ this.sboParameters = sboParameters;
+ }
+
+ public ReactionsPolisher(PolishingParameters polishingParameters,
+ SBOParameters sboParameters,
+ Registry registry,
+ List observers) {
+ super(polishingParameters, registry, observers);
+ this.sboParameters = sboParameters;
+ }
+
+ @Override
+ public void polish(List reactions) {
+ logger.debug("Polish Reactions");
+
+ for (var reaction : reactions) {
+ statusReport("Polishing Reactions (5/9) ", reaction);
+ polish(reaction);
}
}
- setCompartmentFromReactionParticipants(reaction);
+ /**
+ * Polishes the reaction by applying various checks and modifications to ensure it conforms to
+ * the expected standards and conventions. This includes setting SBO terms, checking compartments,
+ * and ensuring proper setup of reactants and products.
+ */
+ @Override
+ public void polish(Reaction reaction) {
+ var originalReaction = reaction.clone();
+ // Process any external resources linked via annotations in the reaction
+ new AnnotationPolisher(polishingParameters, registry).polish(reaction.getAnnotation());
+
+ setMetaId(reaction);
+
+ if (sboParameters.addGenericTerms()) {
+ if (reaction.isSetListOfReactants()) {
+ new SpeciesReferencesPolisher(SBO.getReactant()).polish(reaction.getListOfReactants());
+ }
+ if (reaction.isSetListOfProducts()) {
+ new SpeciesReferencesPolisher(SBO.getProduct()).polish(reaction.getListOfProducts());
+ }
+ }
- removeCopySuffix(reaction);
+ setCompartmentFromReactionParticipants(reaction);
- setSBOTerm(reaction);
- }
+ removeCopySuffix(reaction);
- private void setMetaId(Reaction reaction) {
- if (!reaction.isSetMetaId() && (reaction.getCVTermCount() > 0)) {
- reaction.setMetaId(reaction.getId());
+ setSBOTerm(reaction);
}
- }
- private void setCompartmentFromReactionParticipants(Reaction reaction) {
- if (reaction.getCompartment() == null || reaction.getCompartment().isEmpty()) {
- var reactantsCompartment = getCommonCompartmentCode(reaction.getListOfReactants());
- var productsCompartment = getCommonCompartmentCode(reaction.getListOfProducts());
- if (reactantsCompartment.isEmpty() && productsCompartment.isPresent()) {
- reaction.setCompartment(productsCompartment.get());
- }
- else if (reactantsCompartment.isPresent() && productsCompartment.isEmpty()) {
- reaction.setCompartment(reactantsCompartment.get());
+ private void setMetaId(Reaction reaction) {
+ if (!reaction.isSetMetaId() && (reaction.getCVTermCount() > 0)) {
+ reaction.setMetaId(reaction.getId());
}
- else if (reactantsCompartment.isPresent()
- && reactantsCompartment.get().equals(productsCompartment.get())) {
- reaction.setCompartment(reactantsCompartment.get());
+ }
+
+ private void setCompartmentFromReactionParticipants(Reaction reaction) {
+ if (reaction.getCompartment() == null || reaction.getCompartment().isEmpty()) {
+ var reactantsCompartment = getCommonCompartmentCode(reaction.getListOfReactants());
+ var productsCompartment = getCommonCompartmentCode(reaction.getListOfProducts());
+ if (reactantsCompartment.isEmpty() && productsCompartment.isPresent()) {
+ reaction.setCompartment(productsCompartment.get());
+ }
+ else if (reactantsCompartment.isPresent() && productsCompartment.isEmpty()) {
+ reaction.setCompartment(reactantsCompartment.get());
+ }
+ else if (reactantsCompartment.isPresent()
+ && reactantsCompartment.get().equals(productsCompartment.get())) {
+ reaction.setCompartment(reactantsCompartment.get());
+ }
}
}
- }
- private Optional getCommonCompartmentCode(ListOf speciesReferences) {
- // Attempt to identify a common compartment for all species references
- if (null != speciesReferences) {
- var modelSpecies = speciesReferences.stream()
- .map(SpeciesReference::getSpeciesInstance)
- .map(Species::getCompartmentInstance)
- .map(Compartment::getId)
- .collect(Collectors.toSet());
- return modelSpecies.size() == 1 ? modelSpecies.stream().findFirst() : Optional.empty();
+ private Optional getCommonCompartmentCode(ListOf speciesReferences) {
+ // Attempt to identify a common compartment for all species references
+ if (null != speciesReferences) {
+ var modelSpecies = speciesReferences.stream()
+ .map(SpeciesReference::getSpeciesInstance)
+ .filter(Objects::nonNull)
+ .map(Species::getCompartmentInstance)
+ .filter(Objects::nonNull )
+ .map(Compartment::getId)
+ .collect(Collectors.toSet());
+ return modelSpecies.size() == 1 ? modelSpecies.stream().findFirst() : Optional.empty();
+ }
+ return Optional.empty();
}
- return Optional.empty();
- }
- private void removeCopySuffix(Reaction reaction) {
- String rName = reaction.getName();
- if (rName.matches(".*_copy\\d*")) {
- rName = rName.substring(0, rName.lastIndexOf('_'));
- reaction.setName(rName);
+ private void removeCopySuffix(Reaction reaction) {
+ String rName = reaction.getName();
+ if (rName.matches(".*_copy\\d*")) {
+ rName = rName.substring(0, rName.lastIndexOf('_'));
+ reaction.setName(rName);
+ }
}
- }
- private void setSBOTerm(Reaction reaction) {
- setSBOTermFromPattern(reaction, BiGGId.createReactionId(reaction.getId()));
+ private void setSBOTerm(Reaction reaction) {
+ setSBOTermFromPattern(reaction, BiGGId.createReactionId(reaction.getId()));
- if (!reaction.isSetSBOTerm()) {
- if (reaction.getReactantCount() != 0 && reaction.getProductCount() == 0 && !reaction.isReversible()) {
- reaction.setSBOTerm(632);
- }
- else if (reaction.getReactantCount() == 0 && reaction.getProductCount() != 0 && !reaction.isReversible()) {
- reaction.setSBOTerm(628);
+ if (!reaction.isSetSBOTerm()) {
+ if (reaction.getReactantCount() != 0 && reaction.getProductCount() == 0 && !reaction.isReversible()) {
+ reaction.setSBOTerm(632);
+ }
+ else if (reaction.getReactantCount() == 0 && reaction.getProductCount() != 0 && !reaction.isReversible()) {
+ reaction.setSBOTerm(628);
+ }
}
}
- }
- /**
- * Sets the Systems Biology Ontology (SBO) term for a reaction based on the abbreviation of its BiGG ID.
- * The method matches the abbreviation against predefined patterns to determine the appropriate SBO term.
- *
- * @param id The BiGGId object containing the abbreviation to be checked.
- */
- private void setSBOTermFromPattern(Reaction reaction, BiGGId id) {
- String abbrev = id.getAbbreviation();
- if (ReactionNamePatterns.BIOMASS_CASE_INSENSITIVE.getPattern().matcher(abbrev).matches()) {
- reaction.setSBOTerm(629); // Set SBO term for biomass production
- } else if (ReactionNamePatterns.DEMAND_REACTION.getPattern().matcher(abbrev).matches()) {
- reaction.setSBOTerm(628); // Set SBO term for demand reaction
- } else if (ReactionNamePatterns.EXCHANGE_REACTION.getPattern().matcher(abbrev).matches()) {
- reaction.setSBOTerm(627); // Set SBO term for exchange reaction
- } else if (ReactionNamePatterns.ATP_MAINTENANCE.getPattern().matcher(abbrev).matches()) {
- reaction.setSBOTerm(630); // Set SBO term for ATP maintenance
- } else if (ReactionNamePatterns.SINK_REACTION.getPattern().matcher(abbrev).matches()) {
- reaction.setSBOTerm(632); // Set SBO term for sink reaction
+ /**
+ * Sets the Systems Biology Ontology (SBO) term for a reaction based on the abbreviation of its BiGG ID.
+ * The method matches the abbreviation against predefined patterns to determine the appropriate SBO term.
+ *
+ * @param id The BiGGId object containing the abbreviation to be checked.
+ */
+ private void setSBOTermFromPattern(Reaction reaction, BiGGId id) {
+ String abbrev = id.getAbbreviation();
+ if (ReactionNamePatterns.BIOMASS_CASE_INSENSITIVE.getPattern().matcher(abbrev).matches()) {
+ reaction.setSBOTerm(629); // Set SBO term for biomass production
+ } else if (ReactionNamePatterns.DEMAND_REACTION.getPattern().matcher(abbrev).matches()) {
+ reaction.setSBOTerm(628); // Set SBO term for demand reaction
+ } else if (ReactionNamePatterns.EXCHANGE_REACTION.getPattern().matcher(abbrev).matches()) {
+ reaction.setSBOTerm(627); // Set SBO term for exchange reaction
+ } else if (ReactionNamePatterns.ATP_MAINTENANCE.getPattern().matcher(abbrev).matches()) {
+ reaction.setSBOTerm(630); // Set SBO term for ATP maintenance
+ } else if (ReactionNamePatterns.SINK_REACTION.getPattern().matcher(abbrev).matches()) {
+ reaction.setSBOTerm(632); // Set SBO term for sink reaction
+ }
}
- }
-}
+ }
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/fbc/FBCPolisher.java b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/FBCPolisher.java
similarity index 98%
rename from src/main/java/edu/ucsd/sbrg/polishing/fbc/FBCPolisher.java
rename to src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/FBCPolisher.java
index 89d47056..7fd9f3bb 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/fbc/FBCPolisher.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/FBCPolisher.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.polishing.fbc;
+package edu.ucsd.sbrg.polishing.ext.fbc;
import de.zbit.util.ResourceManager;
import edu.ucsd.sbrg.parameters.SBOParameters;
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisher.java b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/FBCReactionPolisher.java
similarity index 91%
rename from src/main/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisher.java
rename to src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/FBCReactionPolisher.java
index 6c9ec004..9e52c9a0 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisher.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/FBCReactionPolisher.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.polishing.fbc;
+package edu.ucsd.sbrg.polishing.ext.fbc;
import edu.ucsd.sbrg.parameters.PolishingParameters;
import edu.ucsd.sbrg.parameters.SBOParameters;
@@ -33,7 +33,7 @@ public FBCReactionPolisher(FBCModelPlugin fbcPlugin,
this.gpaProcessor = new GeneProductAssociationsProcessor();
}
- public FBCReactionPolisher(FBCModelPlugin fbcPlugin,
+ public FBCReactionPolisher(FBCModelPlugin fbcPlugin,
PolishingParameters polishingParameters,
SBOParameters sboParameters,
Registry registry,
@@ -67,7 +67,7 @@ private void fluxObjectiveFromLocalParameter(Reaction reaction) {
Objective obj = fbcPlugin.getActiveObjectiveInstance();
// Check if a flux objective associated with the reaction already exists
- boolean foExists = obj.getListOfFluxObjectives().stream()
+ boolean foExists = obj.getListOfFluxObjectives().stream()
.anyMatch(fo -> fo.getReactionInstance().equals(reaction));
if (foExists) {
return;
@@ -86,11 +86,7 @@ private void fluxObjectiveFromLocalParameter(Reaction reaction) {
}
}
- /**
- * This method extracts gene associations from the notes of a reaction and converts them into
- * the FBCv2 GeneProductAssociation format. It specifically looks for notes tagged with "GENE_ASSOCIATION:"
- * and processes them to set the gene product association for the reaction if it has not been set already.
- */
+
private void associationFromNotes(Reaction reaction) {
// Obtain the FBC plugin for the reaction to handle FBC-specific features.
var reactionPlugin = (FBCReactionPlugin) reaction.getPlugin(FBCConstants.shortLabel);
@@ -115,7 +111,7 @@ private void associationFromNotes(Reaction reaction) {
String association = splits[1];
if (!association.isEmpty()) {
// Parse the gene product association and apply it to the reaction.
- GPRParser.parseGPR(reaction, association, sboParameters.addGenericTerms());
+ GPRParser.setGeneProductAssociation(reaction, association, sboParameters.addGenericTerms());
}
}
}
@@ -201,7 +197,7 @@ public void setFluxBoundSBOTerm(Parameter bound) {
* Retrieves a local parameter from a reaction's kinetic law based on the specified parameter name.
* This method specifically looks for parameters that define either the lower or upper flux bounds.
*
- * @param r The reaction from which the kinetic law and the parameter are to be retrieved.
+ * @param r The reaction from which the kinetic law and the parameter are to be retrieved.
* @param parameterName The name of the parameter to retrieve, expected to be either "LOWER_BOUND" or "UPPER_BOUND".
* @return The local parameter if found, or {@code null} if the kinetic law is not defined or the parameter does not exist.
*/
@@ -219,8 +215,8 @@ private Parameter getBoundFromKineticLawParameters(Reaction r, String parameterN
* If the bound value matches a specific threshold, the ID is set to a corresponding default value.
* Otherwise, the ID is customized using the reaction's ID combined with the original bound's ID.
*
- * @param r The {@link Reaction} instance from which the model and parameter are derived.
- * @param bound The {@link Parameter} instance representing either a lower or upper bound.
+ * @param r The {@link Reaction} instance from which the model and parameter are derived.
+ * @param bound The {@link Parameter} instance representing either a lower or upper bound.
* @param boundValue The numeric value of the bound, which determines how the {@link Parameter}'s ID is set.
*/
private void setBoundId(Reaction r, Parameter bound, double boundValue) {
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/fbc/GeneProductAssociationsProcessor.java b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/GeneProductAssociationsProcessor.java
similarity index 59%
rename from src/main/java/edu/ucsd/sbrg/polishing/fbc/GeneProductAssociationsProcessor.java
rename to src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/GeneProductAssociationsProcessor.java
index 278f5f2a..e53ad943 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/fbc/GeneProductAssociationsProcessor.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/GeneProductAssociationsProcessor.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.polishing.fbc;
+package edu.ucsd.sbrg.polishing.ext.fbc;
import de.zbit.util.ResourceManager;
import edu.ucsd.sbrg.db.bigg.BiGGId;
@@ -19,61 +19,43 @@ public class GeneProductAssociationsProcessor {
private static final Logger logger = LoggerFactory.getLogger(GeneProductAssociationsProcessor.class);
private static final ResourceBundle MESSAGES = ResourceManager.getBundle("edu.ucsd.sbrg.polisher.Messages");
- /**
- * Mapping holding geneAssociations from model annotations
- */
- private Map oldGeneAssociations;
+ private final Map oldGeneAssociations = new HashMap<>();
- /**
- * Converts gene product associations from a given reaction to the FBC v2 format.
- * This method processes the non-RDF annotations of the reaction's model to update or create
- * gene product associations according to the FBC v2 specification.
- *
- * @param reaction The reaction whose gene product associations are to be converted.
- * @param omitGenericTerms A boolean flag indicating whether to omit generic terms (SBO terms) in the association.
- */
- public void convertAssociationsToFBCV2(Reaction reaction, boolean omitGenericTerms) {
- Model model = reaction.getModel();
- Annotation annotation = model.getAnnotation();
- XMLNode node = annotation.getNonRDFannotation();
- if (node == null) {
- return;
- }
- if (oldGeneAssociations == null) {
- oldGeneAssociations = new HashMap<>();
- for (int i = 0; i < node.getChildCount(); i++) {
- XMLNode current = node.getChild(i);
- if (current.getName().equals("geneAssociation")) {
- String reactionId = current.getAttributes().getValue("reaction");
- oldGeneAssociations.put(reactionId, node.getChild(i));
- node.removeChild(i);
- }
- }
- }
+ public void convertAssociationsToFBCV2(Reaction reaction, boolean addGenericTerms) {
+ var model = reaction.getModel();
String id = reaction.getId();
XMLNode ga = oldGeneAssociations.getOrDefault(id, null);
if (ga != null) {
- FBCReactionPlugin plugin = (FBCReactionPlugin) reaction.getPlugin(FBCConstants.shortLabel);
- GeneProductAssociation gpa = new GeneProductAssociation(reaction.getLevel(), reaction.getVersion());
- List associations = processAssociation(ga, model, omitGenericTerms);
+ var reactionPlugin = (FBCReactionPlugin) reaction.getPlugin(FBCConstants.shortLabel);
+ var gpa = new GeneProductAssociation(reaction.getLevel(), reaction.getVersion());
+ List associations = processAssociation(ga, model, addGenericTerms);
if (associations.size() == 1) {
gpa.setAssociation(associations.get(0));
- plugin.setGeneProductAssociation(gpa);
+ reactionPlugin.setGeneProductAssociation(gpa);
+ }
+ }
+ }
+
+ // TODO: das war extrahiert aus convertAssociationsToFBCV2 und muss aufgerufen werden noch
+ private boolean processNonRDFGeneAssociationAnnotations(Model model) {
+ var annotation = model.getAnnotation();
+ XMLNode node = annotation.getNonRDFannotation();
+ if (node == null) {
+ return true;
+ }
+ for (int i = 0; i < node.getChildCount(); i++) {
+ XMLNode current = node.getChild(i);
+ if (current.getName().equals("geneAssociation")) {
+ String reactionId = current.getAttributes().getValue("reaction");
+ oldGeneAssociations.put(reactionId, node.getChild(i));
+ node.removeChild(i);
}
}
+ return false;
}
- /**
- * Processes an XMLNode representing a gene product association and converts it into a list of Association objects.
- * This method handles the logical operators "and" and "or", as well as gene product references.
- *
- * @param association The XMLNode representing the gene product association.
- * @param model The SBML model to which the association belongs.
- * @param omitGenericTerms A boolean flag indicating whether to omit generic terms (SBO terms) in the association.
- * @return A list of Association objects representing the processed gene product association.
- */
- private List processAssociation(XMLNode association, Model model, boolean omitGenericTerms) {
+ private List processAssociation(XMLNode association, Model model, boolean addGenericTerms) {
int level = model.getLevel(), version = model.getVersion();
List associations = new ArrayList<>();
for (int i = 0; i < association.getChildCount(); i++) {
@@ -81,20 +63,20 @@ private List processAssociation(XMLNode association, Model model, b
switch (current.getName()) {
case "and":
And and = new And(level, version);
- if (!omitGenericTerms) {
+ if (addGenericTerms) {
and.setSBOTerm(173); // AND
}
- and.addAllAssociations(processAssociation(current, model, omitGenericTerms));
+ and.addAllAssociations(processAssociation(current, model, addGenericTerms));
if (and.isSetListOfAssociations()) {
associations.add(and);
}
break;
case "or":
Or or = new Or(level, version);
- if (!omitGenericTerms) {
+ if (!addGenericTerms) {
or.setSBOTerm(174); // OR
}
- or.addAllAssociations(processAssociation(current, model, omitGenericTerms));
+ or.addAllAssociations(processAssociation(current, model, addGenericTerms));
if (or.isSetListOfAssociations()) {
associations.add(or);
}
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/fbc/GeneProductsPolisher.java b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/GeneProductsPolisher.java
similarity index 98%
rename from src/main/java/edu/ucsd/sbrg/polishing/fbc/GeneProductsPolisher.java
rename to src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/GeneProductsPolisher.java
index 192c1657..c821190e 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/fbc/GeneProductsPolisher.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/GeneProductsPolisher.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.polishing.fbc;
+package edu.ucsd.sbrg.polishing.ext.fbc;
import edu.ucsd.sbrg.polishing.AbstractPolisher;
import edu.ucsd.sbrg.polishing.AnnotationPolisher;
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisher.java b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/ObjectivesPolisher.java
similarity index 98%
rename from src/main/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisher.java
rename to src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/ObjectivesPolisher.java
index 1a23701d..6683d6a8 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisher.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/ObjectivesPolisher.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.polishing.fbc;
+package edu.ucsd.sbrg.polishing.ext.fbc;
import edu.ucsd.sbrg.polishing.AbstractPolisher;
import edu.ucsd.sbrg.parameters.PolishingParameters;
diff --git a/src/main/java/edu/ucsd/sbrg/polishing/fbc/StrictnessPredicate.java b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/StrictnessPredicate.java
similarity index 99%
rename from src/main/java/edu/ucsd/sbrg/polishing/fbc/StrictnessPredicate.java
rename to src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/StrictnessPredicate.java
index 12fefafd..498fd54a 100644
--- a/src/main/java/edu/ucsd/sbrg/polishing/fbc/StrictnessPredicate.java
+++ b/src/main/java/edu/ucsd/sbrg/polishing/ext/fbc/StrictnessPredicate.java
@@ -1,4 +1,4 @@
-package edu.ucsd.sbrg.polishing.fbc;
+package edu.ucsd.sbrg.polishing.ext.fbc;
import org.sbml.jsbml.*;
import org.sbml.jsbml.ext.fbc.*;
diff --git a/src/main/java/edu/ucsd/sbrg/reporting/DiffListener.java b/src/main/java/edu/ucsd/sbrg/reporting/DiffListener.java
new file mode 100644
index 00000000..e9a8b40b
--- /dev/null
+++ b/src/main/java/edu/ucsd/sbrg/reporting/DiffListener.java
@@ -0,0 +1,46 @@
+package edu.ucsd.sbrg.reporting;
+
+import edu.ucsd.sbrg.io.parsers.json.mapping.Compartments;
+import org.sbml.jsbml.SBase;
+import org.sbml.jsbml.Species;
+import org.sbml.jsbml.util.TreeNodeChangeListener;
+import org.sbml.jsbml.util.TreeNodeRemovedEvent;
+import org.sbml.jsbml.util.TreeNodeWithChangeSupport;
+
+import javax.swing.tree.TreeNode;
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DiffListener implements TreeNodeChangeListener {
+
+
+ private final List removedIds;
+
+ public DiffListener() {
+ removedIds = new ArrayList<>();
+ }
+{}
+ @Override
+ public void nodeAdded(TreeNode node) {
+
+ }
+
+ @Override
+ public void nodeRemoved(TreeNodeRemovedEvent event) {
+ if(event.getSource() instanceof SBase) {
+ removedIds.add(((SBase) event.getSource()).getId());
+ }
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
+ if (propertyChangeEvent.getSource().getClass().equals(Species.class)) {
+
+ } else if (propertyChangeEvent.getSource().getClass().equals(Species.class)) {
+
+ } else if (propertyChangeEvent.getSource().getClass().equals(Species.class)) {
+
+ }
+ }
+}
diff --git a/src/main/java/edu/ucsd/sbrg/util/ext/fbc/GPRParser.java b/src/main/java/edu/ucsd/sbrg/util/ext/fbc/GPRParser.java
index 56a655b4..acc814f1 100644
--- a/src/main/java/edu/ucsd/sbrg/util/ext/fbc/GPRParser.java
+++ b/src/main/java/edu/ucsd/sbrg/util/ext/fbc/GPRParser.java
@@ -28,84 +28,55 @@
import static java.text.MessageFormat.format;
-/**
- * The {@code GPRParser} class provides methods to parse gene product associations (GPRs) from gene reaction rules
- * and integrate them into SBML models using JSBML. It supports converting textual gene reaction rules into structured
- * {@link Association} objects, handling logical operators, and merging associations into existing models.
- * It also includes utilities for converting associations to the FBC v2 format and managing gene product references.
- *
- * This class is designed to be used in scenarios where gene reaction rules need to be parsed from various formats
- * and integrated into computational models in a structured and standardized form. It provides comprehensive support
- * for handling complex logical structures in gene product associations, such as nested AND/OR conditions.
- *
- * Utility methods in this class are static, allowing direct invocation without needing an instance of {@code GPRParser}.
- * This class heavily relies on the JSBML library to manipulate elements of SBML files, particularly those related to
- * the FBC (Flux Balance Constraints) package.
- */
+
public class GPRParser {
private static final Logger logger = LoggerFactory.getLogger(GPRParser.class);
private static final ResourceBundle MESSAGES = ResourceManager.getBundle("edu.ucsd.sbrg.polisher.Messages");
- /**
- * Parses the gene product association (GPR) from a gene reaction rule string and associates it with a given reaction.
- * This method first converts the gene reaction rule string into an Association object using a formula parser.
- * If the conversion is successful and the Association object is not null, it further processes the association
- * by parsing it into the reaction's gene product association.
- *
- * @param r The reaction to which the gene product association will be linked.
- * @param geneReactionRule The gene reaction rule string representing the association of gene products.
- * @param omitGenericTerms Flag indicating whether to omit generic terms (e.g., SBO terms) in the association.
- */
- public static void parseGPR(Reaction r, String geneReactionRule, boolean omitGenericTerms) {
- ASTNode ast = null;
+ public static void setGeneProductAssociation(Reaction r, String geneReactionRule, boolean addGenericTerms) {
try {
- ast = ASTNode.parseFormula(
+ ASTNode ast = ASTNode.parseFormula(
geneReactionRule,
new CobraFormulaParser(new StringReader("")));
+
Association association = convertToAssociation(
ast,
- r.getId(),
r.getModel(),
- omitGenericTerms);
- parseGPR(r, association, omitGenericTerms);
+ addGenericTerms);
+
+ var reactionPlugin = (FBCReactionPlugin) r.getPlugin(FBCConstants.shortLabel);
+ if (!reactionPlugin.isSetGeneProductAssociation()) {
+ var gpa = new GeneProductAssociation(r.getLevel(), r.getVersion());
+ gpa.setAssociation(association);
+ reactionPlugin.setGeneProductAssociation(gpa);
+ } else if (!areEqual(association, reactionPlugin.getGeneProductAssociation().getAssociation())) {
+ mergeAssociation(r, association, reactionPlugin, addGenericTerms);
+ }
} catch (ParseException e) {
logger.info(format(MESSAGES.getString("PARSE_GPR_ERROR"), geneReactionRule, Utils.getMessage(e)));
}
}
- /**
- * Converts an ASTNode representing a gene product association into an Association object.
- * This method handles the logical structure of the gene product association, creating appropriate
- * logical operators (AND, OR) based on the ASTNode type. It also manages the inclusion of SBO terms
- * if they are not omitted.
- *
- * @param ast The ASTNode to be converted, representing the logical structure of the gene product association.
- * @param reactionId The ID of the reaction associated with this gene product association.
- * @param model The SBML model to which the reaction belongs, used to determine the level and version for new elements.
- * @param omitGenericTerms A boolean flag indicating whether to omit SBO terms in the resulting Association.
- * @return An Association object representing the gene product association, which could be a LogicalOperator or a direct GeneProductRef.
- */
- public static Association convertToAssociation(ASTNode ast, String reactionId, Model model,
- boolean omitGenericTerms) {
+ private static Association convertToAssociation(ASTNode ast, Model model, boolean addGenericTerms) {
int level = model.getLevel(), version = model.getVersion();
if (ast.isLogical()) {
LogicalOperator operator;
if (ast.getType() == ASTNode.Type.LOGICAL_AND) {
operator = new And(level, version);
- if (!omitGenericTerms) {
+ if (addGenericTerms) {
operator.setSBOTerm(173); // AND
}
} else {
operator = new Or(level, version);
- if (!omitGenericTerms) {
+ if (addGenericTerms) {
operator.setSBOTerm(174); // OR
}
}
for (ASTNode child : ast.getListOfNodes()) {
- Association tmp = convertToAssociation(child, reactionId, model, omitGenericTerms);
+ Association tmp = convertToAssociation(child, model, addGenericTerms);
if (tmp.getClass().equals(operator.getClass())) {
// Flatten binary trees to compact representation
LogicalOperator lo = (LogicalOperator) tmp;
@@ -118,50 +89,30 @@ public static Association convertToAssociation(ASTNode ast, String reactionId, M
}
return operator;
}
- return createGPR(ast.toString(), reactionId, model);
+ return createGPR(ast.toString(), model);
}
- /**
- * Creates a GeneProductRef instance for a given identifier within a specific reaction context in the model.
- * This method first checks if the identifier exists in the model, either with or without a "G_" prefix.
- * If the identifier does not exist, it attempts to create a new GeneProduct in the model.
- * If the identifier exists, it updates the existing GeneProduct's ID.
- *
- * @param identifier The identifier for the gene product, which may or may not start with "G_".
- * @param reactionId The ID of the reaction associated with this gene product.
- * @param model The SBML model containing the reaction and potentially the gene product.
- * @return A GeneProductRef object linked to the gene product identified or created.
- */
- public static GeneProductRef createGPR(String identifier, String reactionId, Model model) {
+ private static GeneProductRef createGPR(String astString, Model model) {
// Determine the SBML document level and version for creating new elements.
int level = model.getLevel(), version = model.getVersion();
- GeneProductRef gpr = new GeneProductRef(level, version);
+ var gpr = new GeneProductRef(level, version);
// Normalize the identifier to include "G_" prefix if missing.
- String oldId = identifier.startsWith("G_") ? identifier : "G_" + identifier;
+ String oldId = astString.startsWith("G_") ? astString : "G_" + astString;
boolean containsOldId = !model.containsUniqueNamedSBase(oldId);
// Attempt to create or find the GeneProduct using a standardized identifier.
- var id = BiGGId.createGeneId(identifier).toBiGGId();
+ var id = BiGGId.createGeneId(astString).toBiGGId();
if (!model.containsUniqueNamedSBase(id)) {
- GeneProduct gp;
// Check if the old ID exists, if so, retrieve the GeneProduct, otherwise use the new ID.
if (containsOldId) {
- gp = (GeneProduct) model.findUniqueNamedSBase(oldId);
+ var gp = (GeneProduct) model.findUniqueNamedSBase(oldId);
+ gp.setId(id);
} else {
- gp = (GeneProduct) model.findUniqueNamedSBase(id);
- }
- // If the GeneProduct does not exist, create a new one and log a warning.
- if (gp == null) {
- logger.info(format(MESSAGES.getString("CREATE_MISSING_GPR"), id, reactionId));
- FBCModelPlugin fbcPlug = (FBCModelPlugin) model.getPlugin(FBCConstants.shortLabel);
- gp = fbcPlug.createGeneProduct(id);
+ var fbcPlug = (FBCModelPlugin) model.getPlugin(FBCConstants.shortLabel);
+ var gp = fbcPlug.createGeneProduct(id);
gp.setLabel(id);
- } else {
- // If the GeneProduct exists, update its ID and log the update.
- logger.info(format(MESSAGES.getString("UPDATE_GP_ID"), gp.getId(), id));
- gp.setId(id);
}
}
// Set the GeneProduct reference in the GeneProductRef.
@@ -170,47 +121,80 @@ public static GeneProductRef createGPR(String identifier, String reactionId, Mod
}
- /**
- * Parses the Gene Product Representation (GPR) for a given reaction and updates the reaction's gene product association.
- * If the reaction does not have an existing gene product association, a new one is created and set.
- * If an association already exists and it is not equivalent to the provided association, the associations are merged.
- *
- * @param r The reaction for which the GPR is being parsed.
- * @param association The association to be parsed and potentially merged into the reaction's gene product association.
- * @param omitGenericTerms A boolean flag indicating whether generic terms should be omitted during the merging process.
- */
- private static void parseGPR(Reaction r, Association association, boolean omitGenericTerms) {
- var reactionPlugin = (FBCReactionPlugin) r.getPlugin(FBCConstants.shortLabel);
- if (!reactionPlugin.isSetGeneProductAssociation()) {
- var gpa = new GeneProductAssociation(r.getLevel(), r.getVersion());
- gpa.setAssociation(association);
- reactionPlugin.setGeneProductAssociation(gpa);
- } else if (!areEqual(association, reactionPlugin.getGeneProductAssociation().getAssociation())) {
- mergeAssociation(r, association, reactionPlugin, omitGenericTerms);
+ private static void mergeAssociation(Reaction r,
+ Association association,
+ FBCReactionPlugin reactionPlugin,
+ boolean addGenericTerms) {
+ // get current association to replace
+ var oldGpa = reactionPlugin.getGeneProductAssociation().getAssociation();
+ var gpa = new GeneProductAssociation(r.getLevel(), r.getVersion());
+ // link all GPRs fetched with or
+ LogicalOperator or = new Or(r.getLevel(), r.getVersion());
+ if (addGenericTerms) {
+ or.setSBOTerm(174); // OR
+ }
+ if (oldGpa instanceof And) {
+ or.addAssociation(oldGpa);
+ or.addAssociation(association);
+ Set gprs = new HashSet<>();
+ for (int i = 0; i < or.getChildCount(); i++) {
+ Association current = (Association) or.getChildAt(i);
+ if (current instanceof GeneProductRef) {
+ String geneProduct = ((GeneProductRef) current).getGeneProduct();
+ if (gprs.contains(geneProduct)) {
+ if (!or.removeAssociation(current)) {
+ logger.info(format("Failed to unset duplicate GeneProductReference {0} for reaction {1}",
+ geneProduct, r.getId()));
+ }
+ } else {
+ gprs.add(geneProduct);
+ }
+ }
+ }
+ gpa.setAssociation(or);
+ } else if (oldGpa instanceof GeneProductRef) {
+ if (association instanceof Or) {
+ or = (Or) association;
+ } else {
+ or.addAssociation(association);
+ }
+ or.addAssociation(oldGpa);
+ gpa.setAssociation(or);
+ } else { // OR
+ if (association instanceof Or) {
+ for (int idx = 0; idx < association.getChildCount(); idx++) {
+ Association child = (Association) association.getChildAt(idx);
+ ((Or) association).removeAssociation(idx);
+ ((LogicalOperator) oldGpa).addAssociation(child);
+ }
+ } else {
+ ((LogicalOperator) oldGpa).addAssociation(association);
+ }
+ gpa.setAssociation(oldGpa);
}
+ reactionPlugin.setGeneProductAssociation(gpa);
}
-
- private static boolean areEqual(Association gpa1, Association gpa2) {
- if (gpa1.isLeaf() && gpa2.isLeaf()) {
+ private static boolean areEqual(Association association1, Association association2) {
+ if (association1.isLeaf() && association2.isLeaf()) {
return true;
- } else if (gpa1 instanceof Or && gpa2 instanceof Or) {
- if (((Or) gpa1).getNumChildren() != ((Or) gpa2).getNumChildren()) {
+ } else if (association1 instanceof Or && association2 instanceof Or) {
+ if (((Or) association1).getNumChildren() != ((Or) association2).getNumChildren()) {
return false;
} else {
boolean childrenEqual = true;
- for (int i = 0; i < ((Or) gpa1).getNumChildren(); i++) {
- childrenEqual &= areEqual((Association) gpa1.getChildAt(i), (Association) gpa2.getChildAt(i));
+ for (int i = 0; i < ((Or) association1).getNumChildren(); i++) {
+ childrenEqual &= areEqual((Association) association1.getChildAt(i), (Association) association2.getChildAt(i));
}
return childrenEqual;
}
- } else if (gpa1 instanceof And && gpa2 instanceof And) {
- if (((And) gpa1).getNumChildren() != ((And) gpa2).getNumChildren()) {
+ } else if (association1 instanceof And && association2 instanceof And) {
+ if (((And) association1).getNumChildren() != ((And) association2).getNumChildren()) {
return false;
} else {
boolean childrenEqual = true;
- for (int i = 0; i < ((And) gpa1).getNumChildren(); i++) {
- childrenEqual &= areEqual((Association) gpa1.getChildAt(i), (Association) gpa2.getChildAt(i));
+ for (int i = 0; i < ((And) association1).getNumChildren(); i++) {
+ childrenEqual &= areEqual((Association) association1.getChildAt(i), (Association) association2.getChildAt(i));
}
return childrenEqual;
}
@@ -219,14 +203,6 @@ private static boolean areEqual(Association gpa1, Association gpa2) {
}
- /**
- * Converts an Association object into a human-readable string representation.
- * This method handles different types of associations including GeneProductRef, And, and Or.
- * For And and Or associations, it recursively calls itself to handle nested associations.
- *
- * @param association The Association object to be converted into a string.
- * @return A string representation of the Association object.
- */
public static String stringify(Association association) {
if (association instanceof GeneProductRef) {
// Directly return the gene product identifier for GeneProductRef instances.
@@ -255,68 +231,6 @@ public static String stringify(Association association) {
}
- /**
- * Merges a new association into an existing gene product association for a reaction.
- * This method handles the merging of associations by considering different types of associations (AND, OR, GeneProductRef).
- * It ensures that duplicate gene products are not added and maintains the logical structure of the association.
- *
- * @param r The reaction for which the gene product association is being merged.
- * @param association The new association to merge into the existing gene product association.
- * @param plugin The FBCReactionPlugin instance associated with the reaction.
- * @param omitGenericTerms Flag indicating whether to omit generic terms in the association.
- */
- private static void mergeAssociation(Reaction r, Association association, FBCReactionPlugin plugin,
- boolean omitGenericTerms) {
- // get current association to replace
- Association old_association = plugin.getGeneProductAssociation().getAssociation();
- plugin.getGeneProductAssociation().unsetAssociation();
- GeneProductAssociation gpa = new GeneProductAssociation(r.getLevel(), r.getVersion());
- // link all GPRs fetched with or
- LogicalOperator or = new Or(r.getLevel(), r.getVersion());
- if (!omitGenericTerms) {
- or.setSBOTerm(174); // OR
- }
- if (old_association instanceof And) {
- or.addAssociation(old_association);
- or.addAssociation(association);
- Set gprs = new HashSet<>();
- for (int i = 0; i < or.getChildCount(); i++) {
- Association current = (Association) or.getChildAt(i);
- if (current instanceof GeneProductRef) {
- String geneProduct = ((GeneProductRef) current).getGeneProduct();
- if (gprs.contains(geneProduct)) {
- if (!or.removeAssociation(current)) {
- logger.info(format("Failed to unset duplicate GeneProductReference {0} for reaction {1}",
- geneProduct, r.getId()));
- }
- } else {
- gprs.add(geneProduct);
- }
- }
- }
- gpa.setAssociation(or);
- } else if (old_association instanceof GeneProductRef) {
- if (association instanceof Or) {
- or = (Or) association;
- } else {
- or.addAssociation(association);
- }
- or.addAssociation(old_association);
- gpa.setAssociation(or);
- } else { // OR
- if (association instanceof Or) {
- for (int idx = 0; idx < association.getChildCount(); idx++) {
- Association child = (Association) association.getChildAt(idx);
- ((Or) association).removeAssociation(idx);
- ((LogicalOperator) old_association).addAssociation(child);
- }
- } else {
- ((LogicalOperator) old_association).addAssociation(association);
- }
- gpa.setAssociation(old_association);
- }
- plugin.setGeneProductAssociation(gpa);
- }
diff --git a/src/test/java/edu/ucsd/sbrg/polishing/ReactionsPolisherTest.java b/src/test/java/edu/ucsd/sbrg/polishing/ReactionsPolisherTest.java
index b122b791..62a30b4a 100644
--- a/src/test/java/edu/ucsd/sbrg/polishing/ReactionsPolisherTest.java
+++ b/src/test/java/edu/ucsd/sbrg/polishing/ReactionsPolisherTest.java
@@ -2,15 +2,10 @@
import edu.ucsd.sbrg.parameters.PolishingParameters;
import edu.ucsd.sbrg.parameters.SBOParameters;
-import edu.ucsd.sbrg.polishing.fbc.StrictnessPredicate;
+import edu.ucsd.sbrg.polishing.ext.fbc.StrictnessPredicate;
import edu.ucsd.sbrg.resolver.identifiersorg.IdentifiersOrg;
import org.junit.jupiter.api.Test;
import org.sbml.jsbml.Model;
-import org.sbml.jsbml.Species;
-import org.sbml.jsbml.SpeciesReference;
-
-import java.util.Set;
-import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisherTest.java b/src/test/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisherTest.java
index 301c73ed..de1d2370 100644
--- a/src/test/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisherTest.java
+++ b/src/test/java/edu/ucsd/sbrg/polishing/fbc/FBCReactionPolisherTest.java
@@ -2,6 +2,7 @@
import edu.ucsd.sbrg.parameters.PolishingParameters;
import edu.ucsd.sbrg.parameters.SBOParameters;
+import edu.ucsd.sbrg.polishing.ext.fbc.FBCReactionPolisher;
import edu.ucsd.sbrg.resolver.identifiersorg.IdentifiersOrg;
import org.junit.jupiter.api.Test;
import org.sbml.jsbml.Model;
diff --git a/src/test/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisherTest.java b/src/test/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisherTest.java
index d0a30ae7..de33523b 100644
--- a/src/test/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisherTest.java
+++ b/src/test/java/edu/ucsd/sbrg/polishing/fbc/ObjectivesPolisherTest.java
@@ -2,16 +2,14 @@
import edu.ucsd.sbrg.parameters.FluxObjectivesPolishingParameters;
import edu.ucsd.sbrg.parameters.PolishingParameters;
+import edu.ucsd.sbrg.polishing.ext.fbc.ObjectivesPolisher;
import edu.ucsd.sbrg.resolver.identifiersorg.IdentifiersOrg;
import org.junit.jupiter.api.Test;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.fbc.FBCConstants;
import org.sbml.jsbml.ext.fbc.FBCModelPlugin;
-import org.sbml.jsbml.ext.fbc.FluxObjective;
import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;