From a9a8ca36b8f192b5a26a8adf234c78fdf24720a9 Mon Sep 17 00:00:00 2001 From: lcottret <ludovic.cottret@inrae.fr> Date: Thu, 31 Oct 2024 11:16:13 +0100 Subject: [PATCH] fix protein/gene names in sbml reading --- .../jsbml/reader/plugin/FBCParser.java | 715 +++++++++--------- .../met4j_io/jsbml/reader/SbmlDocMock.java | 8 +- .../jsbml/reader/plugin/FBCParserTest.java | 34 +- 3 files changed, 385 insertions(+), 372 deletions(-) diff --git a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParser.java b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParser.java index 91985cfb7..f31e44f40 100644 --- a/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParser.java +++ b/met4j-io/src/main/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParser.java @@ -37,12 +37,12 @@ package fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.plugin; import fr.inrae.toulouse.metexplore.met4j_core.biodata.*; +import fr.inrae.toulouse.metexplore.met4j_core.utils.StringUtils; import fr.inrae.toulouse.metexplore.met4j_io.annotations.network.NetworkAttributes; import fr.inrae.toulouse.metexplore.met4j_io.annotations.reaction.Flux; import fr.inrae.toulouse.metexplore.met4j_io.annotations.reaction.ReactionAttributes; import fr.inrae.toulouse.metexplore.met4j_io.jsbml.dataTags.PrimaryDataTag; import fr.inrae.toulouse.metexplore.met4j_io.jsbml.errors.GeneSetException; -import fr.inrae.toulouse.metexplore.met4j_io.jsbml.errors.JSBMLPackageReaderException; import fr.inrae.toulouse.metexplore.met4j_io.jsbml.fbc.*; import fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.Met4jSbmlReaderException; import fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.plugin.tags.ReaderSBML3Compatible; @@ -52,18 +52,7 @@ import org.sbml.jsbml.Model; import org.sbml.jsbml.Parameter; import org.sbml.jsbml.Reaction; import org.sbml.jsbml.Species; -import org.sbml.jsbml.ext.fbc.And; -import org.sbml.jsbml.ext.fbc.Association; -import org.sbml.jsbml.ext.fbc.FBCModelPlugin; -import org.sbml.jsbml.ext.fbc.FBCReactionPlugin; -import org.sbml.jsbml.ext.fbc.FBCSpeciesPlugin; -import org.sbml.jsbml.ext.fbc.FluxObjective; -import org.sbml.jsbml.ext.fbc.GeneProduct; -import org.sbml.jsbml.ext.fbc.GeneProductRef; -import org.sbml.jsbml.ext.fbc.Objective; -import org.sbml.jsbml.ext.fbc.Or; - -import fr.inrae.toulouse.metexplore.met4j_core.utils.StringUtils; +import org.sbml.jsbml.ext.fbc.*; import java.util.ArrayList; @@ -74,230 +63,229 @@ import java.util.ArrayList; */ public class FBCParser implements PackageParser, PrimaryDataTag, ReaderSBML3Compatible { - /** - * The sbml namespace of the FBC version 2 package - */ - private String PackageNamespace = "http://www.sbml.org/sbml/level3/version1/fbc/version2"; + /** + * The Flux Network created by this parser + * + * @see FluxNetwork + */ + public FluxNetwork flxNet; + /** + * The SBML fbc model plugin + */ + public FBCModelPlugin fbcModel; + /** + * Indicates if the genes are parsed or not + */ + public Boolean parseGenes = true; + /** + * The sbml namespace of the FBC version 2 package + */ + private String PackageNamespace = "http://www.sbml.org/sbml/level3/version1/fbc/version2"; + + public FBCParser(Boolean parseGenes) { + + this.parseGenes = parseGenes; + } - /** - * The Flux Network created by this parser - * - * @see FluxNetwork - */ - public FluxNetwork flxNet; + public FBCParser() { + + this.parseGenes = true; + } - /** - * The SBML fbc model plugin - */ - public FBCModelPlugin fbcModel; + /** + * {@inheritDoc} + */ + @Override + public String getAssociatedPackageName() { + return "fbc"; + } - /** - * Indicates if the genes are parsed or not - */ - public Boolean parseGenes = true; + /** + * {@inheritDoc} + */ + @Override + public boolean isPackageUseableOnModel(Model model) { + return model.isPackageURIEnabled(PackageNamespace); + } - /** {@inheritDoc} */ - @Override - public String getAssociatedPackageName() { - return "fbc"; - } + /** + * {@inheritDoc} + * <p> + * Parse the new object introduced by the SBML FBC version 2 package and + * some of the objects introduced by the FBC version 1 package: + * <ul> + * <li>The list of flux bounds, (introduced in fbc v1 but now present in the + * list of Global Parameters) + * <li>The list of flux Objectives (introduced in fbc v1) + * <li>The list of Gene Product (introduced in fbc v2) + * <li>The additional attributes present in the Species elements (introduced + * in fbc v1) + * <li>The additional attributes present in the Reaction elements + * (introduced in fbc v2) including the GeneAssociation Objects + * </ul> + */ + public void parseModel(Model model, BioNetwork bionetwork) throws Met4jSbmlReaderException { + + this.setFlxNet(new FluxNetwork(bionetwork)); + this.setFbcModel((FBCModelPlugin) model.getPlugin("fbc")); + System.err.println("Starting " + this.getAssociatedPackageName() + " version " + + this.getFbcModel().getPackageVersion() + " plugin..."); + + this.setStrictFromFbcModel(); + + this.parseParameters(); + + if (parseGenes) { + this.parseListOfGeneProducts(); + } + try { + this.parseFluxReactions(); + } catch (GeneSetException | Met4jSbmlReaderException e) { + e.printStackTrace(); + throw new Met4jSbmlReaderException(e.getMessage()); + } + + /** + * Same Methods as FBC1 parser. + */ + this.parseFluxSpecies(); + this.parseListOfFluxObjectives(); - /** {@inheritDoc} */ - @Override - public boolean isPackageUseableOnModel(Model model) { - return model.isPackageURIEnabled(PackageNamespace); - } + } + /** + * Get FBC data only present in the SBML Model object, ie the fbc:strict + * attribute + * + * @see FluxNetwork#setFbcStrict(boolean) + */ + private void setStrictFromFbcModel() { - public FBCParser(Boolean parseGenes) { + this.getFlxNet().setFbcStrict(this.getFbcModel().isSetStrict() ? this.getFbcModel().getStrict() : false); + } - this.parseGenes = parseGenes; + /** + * Retrieves the list of global parameters of this model. This list includes + * all the possible flux bounds values of the reactions in this model. + */ + private void parseParameters() { + + if (this.getFbcModel().getParent().getListOfParameters().size() > 0) { + BioUnitDefinitionCollection udList = NetworkAttributes.getUnitDefinitions(this.flxNet.getUnderlyingBionet()); + if (udList == null) { + System.err.println("[Warning] No unit definition in the SBML file, default one selected"); + udList = new BioUnitDefinitionCollection(); + this.flxNet.getUnderlyingBionet().setAttribute(NetworkAttributes.UNIT_DEFINITIONS, udList); + } + + for (Parameter gParam : this.getFbcModel().getParent().getListOfParameters()) { + Flux bioParam = new Flux(gParam.getId()); + bioParam.setConstant(gParam.getConstant()); + bioParam.value = gParam.getValue(); + + String unit = gParam.getUnits(); + + if (unit != "") { + BioUnitDefinition unitDefinition = udList.get(gParam.getUnits()); + if (unitDefinition == null) { + System.err.println("[Warning] Unit definition " + gParam.getUnits() + " not defined in the SBML : we add it"); + unitDefinition = new BioUnitDefinition(gParam.getUnits(), gParam.getUnits()); + udList.add(unitDefinition); + } + bioParam.unitDefinition = unitDefinition; + } + + this.flxNet.addFluxBound(bioParam); + } + } } - public FBCParser() { - - this.parseGenes = true; - } - - /** - * {@inheritDoc} - * - * Parse the new object introduced by the SBML FBC version 2 package and - * some of the objects introduced by the FBC version 1 package: - * <ul> - * <li>The list of flux bounds, (introduced in fbc v1 but now present in the - * list of Global Parameters) - * <li>The list of flux Objectives (introduced in fbc v1) - * <li>The list of Gene Product (introduced in fbc v2) - * <li>The additional attributes present in the Species elements (introduced - * in fbc v1) - * <li>The additional attributes present in the Reaction elements - * (introduced in fbc v2) including the GeneAssociation Objects - * </ul> - */ - public void parseModel(Model model, BioNetwork bionetwork) throws Met4jSbmlReaderException { - - this.setFlxNet(new FluxNetwork(bionetwork)); - this.setFbcModel((FBCModelPlugin) model.getPlugin("fbc")); - System.err.println("Starting " + this.getAssociatedPackageName() + " version " - + this.getFbcModel().getPackageVersion() + " plugin..."); - - this.setStrictFromFbcModel(); - - this.parseParameters(); - - if(parseGenes) { - this.parseListOfGeneProducts(); - } - try { - this.parseFluxReactions(); - } catch (GeneSetException | Met4jSbmlReaderException e) { - e.printStackTrace(); - throw new Met4jSbmlReaderException(e.getMessage()); - } - - /** - * Same Methods as FBC1 parser. - */ - this.parseFluxSpecies(); - this.parseListOfFluxObjectives(); - - } - - /** - * Get FBC data only present in the SBML Model object, ie the fbc:strict - * attribute - * - * @see FluxNetwork#setFbcStrict(boolean) - */ - private void setStrictFromFbcModel() { - - this.getFlxNet().setFbcStrict(this.getFbcModel().isSetStrict() ? this.getFbcModel().getStrict() : false); - } - - /** - * Retrieves the list of global parameters of this model. This list includes - * all the possible flux bounds values of the reactions in this model. - */ - private void parseParameters() { - - if(this.getFbcModel().getParent().getListOfParameters().size() > 0) { - BioUnitDefinitionCollection udList = NetworkAttributes.getUnitDefinitions(this.flxNet.getUnderlyingBionet()); - if(udList == null) { - System.err.println("[Warning] No unit definition in the SBML file, default one selected"); - udList = new BioUnitDefinitionCollection(); - this.flxNet.getUnderlyingBionet().setAttribute(NetworkAttributes.UNIT_DEFINITIONS, udList); - } - - for (Parameter gParam : this.getFbcModel().getParent().getListOfParameters()) { - Flux bioParam = new Flux(gParam.getId()); - bioParam.setConstant(gParam.getConstant()); - bioParam.value = gParam.getValue(); - - String unit = gParam.getUnits(); - - if (unit != "") { - BioUnitDefinition unitDefinition = udList.get(gParam.getUnits()); - if(unitDefinition == null) { - System.err.println("[Warning] Unit definition "+gParam.getUnits()+" not defined in the SBML : we add it"); - unitDefinition = new BioUnitDefinition(gParam.getUnits(), gParam.getUnits()); - udList.add(unitDefinition); - } - bioParam.unitDefinition = unitDefinition; - } - - this.flxNet.addFluxBound(bioParam); - } - } - } - - /** - * Parse the list of GeneProduct to create the corresponding genes. Only - * introduced in package fbc version 2 - */ - private void parseListOfGeneProducts() { - for (GeneProduct geneProd : this.getFbcModel().getListOfGeneProducts()) { - String geneId = geneProd.getId(); - String geneName = geneProd.getName() != null ? geneProd.getName() : - (geneProd.getLabel() != null ? geneProd.getLabel() : geneProd.getId()); - - BioGene gene = new BioGene(geneId, geneName); - - this.getFlxNet().getUnderlyingBionet().add(gene); - - BioProtein protein = new BioProtein(geneId, geneName); - - this.getFlxNet().getUnderlyingBionet().add(protein); - - this.getFlxNet().getUnderlyingBionet().affectGeneProduct(protein, gene); - - - } - } - - /** - * Parse the list of reaction and uses the data provided by the fbc package - * to fill the missing data for the reactions presents in the bionetwork. - * Example are: - * <ul> - * <li>fbc:upperbound - * <li>fbc:lowerbound - * <li>fbc:GeneProductAssociation - * </ul> - */ - private void parseFluxReactions() throws Met4jSbmlReaderException, GeneSetException { - - for (Reaction rxn : this.getFbcModel().getParent().getListOfReactions()) { - - BioReaction reaction = this.flxNet.getUnderlyingBionet().getReaction(rxn.getId()); - - FBCReactionPlugin rxnPlugin = (FBCReactionPlugin) rxn.getPlugin("fbc"); - FluxReaction flxReaction = new FluxReaction(reaction); + /** + * Parse the list of GeneProduct to create the corresponding genes. Only + * introduced in package fbc version 2 + */ + private void parseListOfGeneProducts() { + for (GeneProduct geneProd : this.getFbcModel().getListOfGeneProducts()) { + String geneId = geneProd.getId(); + String geneName = ! StringUtils.isVoid(geneProd.getName()) ? geneProd.getName() : + (! StringUtils.isVoid(geneProd.getLabel()) ? geneProd.getLabel() : geneProd.getId()); + + BioGene gene = new BioGene(geneId, geneName); - GeneAssociation geneAssociation = new GeneAssociation(); + this.getFlxNet().getUnderlyingBionet().add(gene); - // System.err.println(rxn.getId()); - if (parseGenes && rxnPlugin.isSetGeneProductAssociation()) { - geneAssociation = this.computeGeneAssocations(rxnPlugin.getGeneProductAssociation().getAssociation()); - } - // System.err.println("out of recursion"); - flxReaction.setReactionGeneAssociation(geneAssociation); - flxReaction.convertGeneAssociationstoComplexes(flxNet.getUnderlyingBionet()); + BioProtein protein = new BioProtein(geneId, geneName); - ReactionAttributes.setLowerBound(reaction, - this.flxNet.getListOfFluxBounds().get(rxnPlugin.getLowerFluxBound())); + this.getFlxNet().getUnderlyingBionet().add(protein); - ReactionAttributes.setUpperBound(reaction, - this.flxNet.getListOfFluxBounds().get(rxnPlugin.getUpperFluxBound())); + this.getFlxNet().getUnderlyingBionet().affectGeneProduct(protein, gene); - this.flxNet.getListOfFluxReactions().put(flxReaction.getId(), flxReaction); - } + } + } + + /** + * Parse the list of reaction and uses the data provided by the fbc package + * to fill the missing data for the reactions presents in the bionetwork. + * Example are: + * <ul> + * <li>fbc:upperbound + * <li>fbc:lowerbound + * <li>fbc:GeneProductAssociation + * </ul> + */ + private void parseFluxReactions() throws Met4jSbmlReaderException, GeneSetException { - } + for (Reaction rxn : this.getFbcModel().getParent().getListOfReactions()) { - /** - * Recursively parse Association blocks to retrieve all possible combination - * of Gene associations - * - * @param block - * the current Association block - * @return an ArrayList of {@link GeneSet} - */ - private GeneAssociation computeGeneAssocations(Association block) throws GeneSetException, Met4jSbmlReaderException { + BioReaction reaction = this.flxNet.getUnderlyingBionet().getReaction(rxn.getId()); - GeneAssociation geneAssociation = new GeneAssociation(); + FBCReactionPlugin rxnPlugin = (FBCReactionPlugin) rxn.getPlugin("fbc"); + FluxReaction flxReaction = new FluxReaction(reaction); - if (block != null) { + GeneAssociation geneAssociation = new GeneAssociation(); - if (block.getClass().getSimpleName().equals("And")) { - And andBlock = (And) block; + // System.err.println(rxn.getId()); + if (parseGenes && rxnPlugin.isSetGeneProductAssociation()) { + geneAssociation = this.computeGeneAssocations(rxnPlugin.getGeneProductAssociation().getAssociation()); + } + // System.err.println("out of recursion"); + flxReaction.setReactionGeneAssociation(geneAssociation); + flxReaction.convertGeneAssociationstoComplexes(flxNet.getUnderlyingBionet()); - ArrayList<GeneAssociation> geneAssociations = new ArrayList<GeneAssociation>(); + ReactionAttributes.setLowerBound(reaction, + this.flxNet.getListOfFluxBounds().get(rxnPlugin.getLowerFluxBound())); - for (Association andEl : andBlock.getListOfAssociations()) { + ReactionAttributes.setUpperBound(reaction, + this.flxNet.getListOfFluxBounds().get(rxnPlugin.getUpperFluxBound())); - geneAssociations.add(this.computeGeneAssocations(andEl)); + this.flxNet.getListOfFluxReactions().put(flxReaction.getId(), flxReaction); + + } + + } + + /** + * Recursively parse Association blocks to retrieve all possible combination + * of Gene associations + * + * @param block the current Association block + * @return an ArrayList of {@link GeneSet} + */ + private GeneAssociation computeGeneAssocations(Association block) throws GeneSetException, Met4jSbmlReaderException { + + GeneAssociation geneAssociation = new GeneAssociation(); + + if (block != null) { + + if (block.getClass().getSimpleName().equals("And")) { + And andBlock = (And) block; + + ArrayList<GeneAssociation> geneAssociations = new ArrayList<GeneAssociation>(); + + for (Association andEl : andBlock.getListOfAssociations()) { + + geneAssociations.add(this.computeGeneAssocations(andEl)); // for (GeneSet x : this.computeGeneAssocations(andEl)) { // @@ -312,172 +300,169 @@ public class FBCParser implements PackageParser, PrimaryDataTag, ReaderSBML3Comp // // } - } + } + + // Cross the geneAssociations + geneAssociation = GeneAssociations.merge(geneAssociations.stream().toArray(GeneAssociation[]::new)); + + } else if (block.getClass().getSimpleName().equals("Or")) { + Or orBlock = (Or) block; + + for (Association orEl : orBlock.getListOfAssociations()) { + geneAssociation.addAll(this.computeGeneAssocations(orEl)); + } + + } else { + + // The association is composed of a GeneProductRef. - // Cross the geneAssociations - geneAssociation = GeneAssociations.merge(geneAssociations.stream().toArray(GeneAssociation[]::new)); + GeneProductRef geneRef = (GeneProductRef) block; + GeneSet geneSet = new GeneSet(); - } else if (block.getClass().getSimpleName().equals("Or")) { - Or orBlock = (Or) block; + geneSet.setId(geneRef.getId()); - for (Association orEl : orBlock.getListOfAssociations()) { - geneAssociation.addAll(this.computeGeneAssocations(orEl)); - } + BioGene g = this.flxNet.getUnderlyingBionet().getGene(geneRef.getGeneProduct()); - } else { - - // The association is composed of a GeneProductRef. + if (g == null) { + throw new Met4jSbmlReaderException("Gene " + geneRef.getGeneProduct() + " not present in the list of genes"); + } - GeneProductRef geneRef = (GeneProductRef) block; - GeneSet geneSet = new GeneSet(); + geneSet.add(g.getId()); - geneSet.setId(geneRef.getId()); + geneAssociation.add(geneSet); + } + } - BioGene g = this.flxNet.getUnderlyingBionet().getGene(geneRef.getGeneProduct()); + return geneAssociation; + } + + /** + * Parse the list of species and uses the data provided by the fbc package + * to fill the missing data for the metabolites presents in the bionetwork. + * Example are: + * <ul> + * <li>fbc:charge + * <li>fbc:chemicalformula + * </ul> + */ + private void parseFluxSpecies() { + for (Species specie : this.getFbcModel().getParent().getListOfSpecies()) { + FBCSpeciesPlugin speciePlugin = (FBCSpeciesPlugin) specie.getPlugin("fbc"); + + BioNetwork net = this.flxNet.getUnderlyingBionet(); + + BioMetabolite metabolite = net.getMetabolite(specie.getId()); + + if (speciePlugin.isSetCharge()) + metabolite.setCharge(speciePlugin.getCharge()); + if (speciePlugin.isSetChemicalFormula()) + metabolite.setChemicalFormula(speciePlugin.getChemicalFormula()); + } + + } + + /** + * Parse the list of Flux objective of this FBC model + * + * @see BioObjective + */ + private void parseListOfFluxObjectives() { + + + BioObjectiveCollection objectives = new BioObjectiveCollection(); + + for (Objective fbcObj : this.getFbcModel().getListOfObjectives()) { + + BioObjective objective = new BioObjective(fbcObj.getId(), fbcObj.getName()); + + String type = "maximize"; + + if (fbcObj.getType() != null) { + type = fbcObj.getType().toString(); + } + + objective.setType(fbcObj.getType().toString()); + + objective.active = this.getFbcModel().getActiveObjective().equals(fbcObj.getId()) ? true : false; + + for (FluxObjective fbcFluxObj : fbcObj.getListOfFluxObjectives()) { + + String id, name; + + BioReaction r = this.flxNet.getUnderlyingBionet().getReaction(fbcFluxObj.getReaction()); - if(g== null) { - throw new Met4jSbmlReaderException("Gene "+geneRef.getGeneProduct() + " not present in the list of genes"); - } + if (r != null) { - geneSet.add(g.getId()); + if (!StringUtils.isVoid(fbcFluxObj.getId())) { + id = fbcFluxObj.getId(); + } else { + id = fbcFluxObj.getReaction(); + } - geneAssociation.add(geneSet); - } - } + if (!StringUtils.isVoid(fbcFluxObj.getName())) { + name = fbcFluxObj.getName(); + } else { + name = id; + } - return geneAssociation; - } + ReactionObjective biodataFluxObj = new ReactionObjective(id, name); - /** - * Parse the list of species and uses the data provided by the fbc package - * to fill the missing data for the metabolites presents in the bionetwork. - * Example are: - * <ul> - * <li>fbc:charge - * <li>fbc:chemicalformula - * </ul> - */ - private void parseFluxSpecies() { - for (Species specie : this.getFbcModel().getParent().getListOfSpecies()) { - FBCSpeciesPlugin speciePlugin = (FBCSpeciesPlugin) specie.getPlugin("fbc"); + biodataFluxObj.setCoefficient(fbcFluxObj.getCoefficient()); - BioNetwork net = this.flxNet.getUnderlyingBionet(); + biodataFluxObj.setFlxReaction(new FluxReaction(r)); - BioMetabolite metabolite = net.getMetabolite(specie.getId()); + objective.getListOfReactionObjectives().add(biodataFluxObj); + } + } - if (speciePlugin.isSetCharge()) - metabolite.setCharge(speciePlugin.getCharge()); - if (speciePlugin.isSetChemicalFormula()) - metabolite.setChemicalFormula(speciePlugin.getChemicalFormula()); - } - - } - - /** - * Parse the list of Flux objective of this FBC model - * - * @see BioObjective - */ - private void parseListOfFluxObjectives() { - - - BioObjectiveCollection objectives = new BioObjectiveCollection(); - - for (Objective fbcObj : this.getFbcModel().getListOfObjectives()) { - - BioObjective objective = new BioObjective(fbcObj.getId(), fbcObj.getName()); - - String type = "maximize"; - - if(fbcObj.getType() != null) - { - type = fbcObj.getType().toString(); - } - - objective.setType(fbcObj.getType().toString()); - - objective.active = this.getFbcModel().getActiveObjective().equals(fbcObj.getId()) ? true : false; - - for (FluxObjective fbcFluxObj : fbcObj.getListOfFluxObjectives()) { - - String id, name; - - BioReaction r = this.flxNet.getUnderlyingBionet().getReaction(fbcFluxObj.getReaction()); - - if(r != null) { - - if (!StringUtils.isVoid(fbcFluxObj.getId())) { - id = fbcFluxObj.getId(); - } else { - id = fbcFluxObj.getReaction(); - } - - if (!StringUtils.isVoid(fbcFluxObj.getName())) { - name = fbcFluxObj.getName(); - } else { - name = id; - } - - ReactionObjective biodataFluxObj = new ReactionObjective(id, name); - - biodataFluxObj.setCoefficient(fbcFluxObj.getCoefficient()); - - biodataFluxObj.setFlxReaction(new FluxReaction(r)); - - objective.getListOfReactionObjectives().add(biodataFluxObj); - } - } - - objectives.add(objective); - - // TODO : est ce qu'on s'en sert encore ? - this.flxNet.getListOfObjectives().put(objective.getId(), objective); - - } - - NetworkAttributes.setObjectives(this.flxNet.getUnderlyingBionet(), objectives); - - - this.flxNet.setActiveObjective(this.getFbcModel().getActiveObjective()); - - } - - /** - * <p>Getter for the field <code>flxNet</code>.</p> - * - * @return the flxNet - */ - public FluxNetwork getFlxNet() { - return flxNet; - } - - /** - * <p>Setter for the field <code>flxNet</code>.</p> - * - * @param flxNet - * the flxNet to set - */ - public void setFlxNet(FluxNetwork flxNet) { - this.flxNet = flxNet; - } - - /** - * <p>Getter for the field <code>fbcModel</code>.</p> - * - * @return the fbcModel - */ - public FBCModelPlugin getFbcModel() { - return fbcModel; - } - - /** - * <p>Setter for the field <code>fbcModel</code>.</p> - * - * @param fbcModel - * the fbcModel to set - */ - public void setFbcModel(FBCModelPlugin fbcModel) { - this.fbcModel = fbcModel; - } + objectives.add(objective); + + // TODO : est ce qu'on s'en sert encore ? + this.flxNet.getListOfObjectives().put(objective.getId(), objective); + + } + + NetworkAttributes.setObjectives(this.flxNet.getUnderlyingBionet(), objectives); + + + this.flxNet.setActiveObjective(this.getFbcModel().getActiveObjective()); + + } + + /** + * <p>Getter for the field <code>flxNet</code>.</p> + * + * @return the flxNet + */ + public FluxNetwork getFlxNet() { + return flxNet; + } + + /** + * <p>Setter for the field <code>flxNet</code>.</p> + * + * @param flxNet the flxNet to set + */ + public void setFlxNet(FluxNetwork flxNet) { + this.flxNet = flxNet; + } + + /** + * <p>Getter for the field <code>fbcModel</code>.</p> + * + * @return the fbcModel + */ + public FBCModelPlugin getFbcModel() { + return fbcModel; + } + + /** + * <p>Setter for the field <code>fbcModel</code>.</p> + * + * @param fbcModel the fbcModel to set + */ + public void setFbcModel(FBCModelPlugin fbcModel) { + this.fbcModel = fbcModel; + } } diff --git a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/SbmlDocMock.java b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/SbmlDocMock.java index f60f41a35..1d07fe1a1 100644 --- a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/SbmlDocMock.java +++ b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/SbmlDocMock.java @@ -91,15 +91,15 @@ public class SbmlDocMock { FBCModelPlugin fbcModel = (FBCModelPlugin) model.getPlugin("http://www.sbml.org/sbml/level3/version1/fbc/version2"); GeneProduct gene1 = fbcModel.createGeneProduct(); gene1.setId("g1"); - gene1.setName("g1"); - gene1.setLabel("g1"); + gene1.setName("G1_name"); + gene1.setLabel("G1_label"); fbcModel.addGeneProduct(gene1); GeneProduct gene2 = fbcModel.createGeneProduct(); gene2.setId("g2"); - gene2.setName("g2"); - gene2.setLabel("g2"); + gene2.setName("G2_name"); + gene2.setLabel("G2_label"); fbcModel.addGeneProduct(gene2); diff --git a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParserTest.java b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParserTest.java index bc6947c41..38ad03a01 100644 --- a/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParserTest.java +++ b/met4j-io/src/test/java/fr/inrae/toulouse/metexplore/met4j_io/jsbml/reader/plugin/FBCParserTest.java @@ -45,6 +45,7 @@ import java.util.stream.Collectors; import javax.xml.stream.XMLStreamException; +import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioGene; import fr.inrae.toulouse.metexplore.met4j_io.annotations.reaction.ReactionAttributes; import fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.Met4jSbmlReaderException; import org.junit.Before; @@ -242,9 +243,20 @@ public class FBCParserTest { rxn2Plugin = (FBCReactionPlugin) rSbml2.getPlugin("fbc"); rxn3Plugin = (FBCReactionPlugin) rSbml3.getPlugin("fbc"); - plugin.addGeneProduct(new GeneProduct("g1")); - plugin.addGeneProduct(new GeneProduct("g2")); - plugin.addGeneProduct(new GeneProduct("g3")); + GeneProduct g1 = new GeneProduct("g1"); + g1.setLabel("g1Label"); + g1.setName("g1Name"); + + GeneProduct g2 = new GeneProduct("g2"); + g2.setLabel("g2Label"); + // G2 Does not have name + + GeneProduct g3 = new GeneProduct("g3"); + // G3 does not have neither name or label + + plugin.addGeneProduct(g1); + plugin.addGeneProduct(g2); + plugin.addGeneProduct(g3); GeneProductRef p1 = new GeneProductRef("g1ref"); p1.setGeneProduct("g1"); @@ -280,6 +292,22 @@ public class FBCParserTest { parser.parseModel(model, network); + BioGene bioGene1 = network.getGenesView().get("g1"); + assertNotNull(bioGene1); + assertEquals("g1", bioGene1.getId()); + assertEquals("g1Name", bioGene1.getName()); + + BioGene bioGene2 = network.getGenesView().get("g2"); + assertNotNull(bioGene2); + assertEquals("g2", bioGene2.getId()); + assertEquals("g2Label", bioGene2.getName()); + + BioGene bioGene3 = network.getGenesView().get("g3"); + assertNotNull(bioGene3); + assertEquals("g3", bioGene3.getId()); + assertEquals("g3", bioGene3.getName()); + + String ga1 = BioReactionUtils.getGPR(network, r1, false); assertEquals("g1", ga1); -- GitLab