diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlBioEntityExporter.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlBioEntityExporter.java index be31323ace489bad052aa2171c8e6c23b4ffdfd4..190a2bb028a68693626e4e0b417a5ce4fbd42246 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlBioEntityExporter.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlBioEntityExporter.java @@ -38,7 +38,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s private Map<String, S> sbmlElementByElementId = new HashMap<>(); Map<String, AbstractReferenceGlyph> sbmlGlyphByElementId = new HashMap<>(); - private Map<String, S> sbmlElementByElementNameAndCompartmentName = new HashMap<>(); + protected Map<String, S> sbmlElementByElementNameAndCompartmentName = new HashMap<>(); private int idCounter = 0; @@ -150,16 +150,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s protected ColorDefinition getColorDefinition(Color color) { RenderLayoutPlugin renderPlugin = getRenderPlugin(); - LocalRenderInformation renderInformation = null; - for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) { - if (lri.getId().equals("minerva_definitions")) { - renderInformation = lri; - } - } - if (renderInformation == null) { - renderInformation = new LocalRenderInformation("minerva_definitions"); - renderPlugin.addLocalRenderInformation(renderInformation); - } + LocalRenderInformation renderInformation = getRenderInformation(renderPlugin); for (ColorDefinition cd : renderInformation.getListOfColorDefinitions()) { if (cd.getValue().equals(color)) { @@ -168,11 +159,24 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s } ColorDefinition colorDefinition = new ColorDefinition("color_" + colorToString(color), color); - renderInformation.addColorDefinition(colorDefinition); return colorDefinition; } + protected LocalRenderInformation getRenderInformation(RenderLayoutPlugin renderPlugin) { + LocalRenderInformation renderInformation = null; + for (LocalRenderInformation lri : renderPlugin.getListOfLocalRenderInformation()) { + if (lri.getId().equals("minerva_definitions")) { + renderInformation = lri; + } + } + if (renderInformation == null) { + renderInformation = new LocalRenderInformation("minerva_definitions"); + renderPlugin.addLocalRenderInformation(renderInformation); + } + return renderInformation; + } + protected void assignStyleToGlyph(AbstractReferenceGlyph speciesGlyph, LocalStyle style) { RenderGraphicalObjectPlugin rgop = new RenderGraphicalObjectPlugin(speciesGlyph); rgop.setObjectRole(style.getRoleList().get(0)); @@ -181,12 +185,11 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s } protected LocalStyle createStyle(T element) { - LocalRenderInformation renderInformation = new LocalRenderInformation(); + LocalRenderInformation renderInformation = getRenderInformation(getRenderPlugin()); LocalStyle style = new LocalStyle(); style.getRoleList().add("style_" + element.getElementId()); style.setGroup(new RenderGroup()); renderInformation.addLocalStyle(style); - getRenderPlugin().addLocalRenderInformation(renderInformation); return style; } diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlCompartmentExporter.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlCompartmentExporter.java deleted file mode 100644 index 2399328b4f428b9a98936151c20777765a2117a6..0000000000000000000000000000000000000000 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlCompartmentExporter.java +++ /dev/null @@ -1,39 +0,0 @@ -package lcsb.mapviewer.converter.model.sbml; - -import java.util.List; - -import org.apache.log4j.Logger; -import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph; -import org.sbml.jsbml.ext.layout.Layout; - -import lcsb.mapviewer.model.map.InconsistentModelException; -import lcsb.mapviewer.model.map.compartment.Compartment; - -public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, org.sbml.jsbml.Compartment> { - Logger logger = Logger.getLogger(SbmlCompartmentExporter.class); - - public SbmlCompartmentExporter(Layout layout, lcsb.mapviewer.model.map.model.Model minervaModel) { - super(layout, minervaModel); - } - - @Override - public org.sbml.jsbml.Compartment createSbmlElement(Compartment element) throws InconsistentModelException { - return getSbmlModel().createCompartment("comp_" + (getNextId())); - } - - @Override - protected List<Compartment> getElementList() { - return getMinervaModel().getCompartments(); - } - - @Override - protected AbstractReferenceGlyph createElementGlyph(String sbmlCompartmentId, String glyphId) { - return getLayout().createCompartmentGlyph(glyphId, sbmlCompartmentId); - } - - @Override - protected String getSbmlIdKey(Compartment element) { - return element.getName(); - } - -} diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java index 8f630430f001d5675aaabb8b031cf18d5035623f..fd13c6671c7220751eaeaf06d8b701c1083967be 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java @@ -33,8 +33,10 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends List<Element> result = new ArrayList<>(); for (T sbmlElement : getSbmlElementList(sbmlModel)) { Element element = parse(sbmlElement, sbmlModel); - result.add(element); - elementBySbmlId.put(element.getElementId(), element); + if (element != null) { + result.add(element); + elementBySbmlId.put(element.getElementId(), element); + } } return result; } diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlExporter.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlExporter.java index 3d860fecee9bbe994a4011e7674ffc9c333979fd..25fa73c370852f74c3251b892851a98950cb2359 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlExporter.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlExporter.java @@ -1,5 +1,7 @@ package lcsb.mapviewer.converter.model.sbml; +import java.io.UnsupportedEncodingException; + import javax.xml.stream.XMLStreamException; import org.apache.commons.io.output.ByteArrayOutputStream; @@ -14,6 +16,9 @@ import org.sbml.jsbml.ext.layout.LayoutModelPlugin; import org.sbml.jsbml.ext.render.GlobalRenderInformation; import org.sbml.jsbml.ext.render.RenderLayoutPlugin; +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.exception.InvalidStateException; +import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentExporter; import lcsb.mapviewer.converter.model.sbml.reaction.SbmlReactionExporter; import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesExporter; import lcsb.mapviewer.converter.model.sbml.units.SbmlUnitExporter; @@ -25,35 +30,40 @@ public class SbmlExporter { public String toXml(lcsb.mapviewer.model.map.model.Model model) throws SBMLException, XMLStreamException, InconsistentModelException { - SBMLDocument doc = new SBMLDocument(3, 1); - Model result = doc.createModel(model.getIdModel()); - result.setName(model.getName()); - Layout layout = createSbmlLayout(model, result); + try { + SBMLDocument doc = new SBMLDocument(3, 2); + Model result = doc.createModel(model.getIdModel()); + result.setName(model.getName()); + Layout layout = createSbmlLayout(model, result); - SbmlCompartmentExporter compartmentExporter = new SbmlCompartmentExporter(layout, model); - SbmlBioEntityExporter<Species, org.sbml.jsbml.Species> speciesExporter = new SbmlSpeciesExporter(layout, model, - compartmentExporter); - SbmlReactionExporter reactionExporter = new SbmlReactionExporter(layout, model, speciesExporter, - compartmentExporter); - SbmlUnitExporter unitExporter = new SbmlUnitExporter(model); - SbmlParameterExporter parameterExporter = new SbmlParameterExporter(model); - SbmlFunctionExporter functionExporter = new SbmlFunctionExporter(model); + SbmlCompartmentExporter compartmentExporter = new SbmlCompartmentExporter(layout, model); + SbmlBioEntityExporter<Species, org.sbml.jsbml.Species> speciesExporter = new SbmlSpeciesExporter(layout, model, + compartmentExporter); + SbmlReactionExporter reactionExporter = new SbmlReactionExporter(layout, model, speciesExporter, + compartmentExporter); + SbmlUnitExporter unitExporter = new SbmlUnitExporter(model); + SbmlParameterExporter parameterExporter = new SbmlParameterExporter(model); + SbmlFunctionExporter functionExporter = new SbmlFunctionExporter(model); - compartmentExporter.exportElements(result); - speciesExporter.exportElements(result); - reactionExporter.exportElements(result); - unitExporter.exportUnits(result); - parameterExporter.exportParameter(result); - functionExporter.exportFunction(result); + compartmentExporter.exportElements(result); + speciesExporter.exportElements(result); + reactionExporter.exportElements(result); + unitExporter.exportUnits(result); + parameterExporter.exportParameter(result); + functionExporter.exportFunction(result); - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - SBMLWriter.write(doc, stream, "minerva", "1.0"); - return stream.toString(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + SBMLWriter.write(doc, stream, "minerva", Configuration.getSystemVersion(null)); + return stream.toString("UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new InvalidStateException(e); + } } public Layout createSbmlLayout(lcsb.mapviewer.model.map.model.Model model, Model result) { LayoutModelPlugin layoutPlugin = new LayoutModelPlugin(result); Layout layout = new Layout(); + layout.setId("minerva_layout"); Dimensions dimensions = new Dimensions(); if (model.getHeight() != null) { dimensions.setHeight(model.getHeight()); @@ -68,7 +78,7 @@ public class SbmlExporter { layout.setDimensions(dimensions); layoutPlugin.add(layout); result.addExtension("layout", layoutPlugin); - + createSbmlRenderPlugin(layout, result); return layout; } diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java index 2b97fc6adfaf3290c49edee6f5527386218b81bd..2696dc103750d1e660b955e74782e2b711bd99cd 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java @@ -29,12 +29,14 @@ import lcsb.mapviewer.converter.ConverterException; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.IConverter; import lcsb.mapviewer.converter.InvalidInputDataExecption; +import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentParser; import lcsb.mapviewer.converter.model.sbml.reaction.SbmlReactionParser; import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesParser; import lcsb.mapviewer.converter.model.sbml.units.SbmlUnitsParser; import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; import lcsb.mapviewer.model.map.modifier.Modulation; diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/compartment/SbmlCompartmentExporter.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/compartment/SbmlCompartmentExporter.java new file mode 100644 index 0000000000000000000000000000000000000000..d47b472dc0d2920154d1d807a1cd8aa43a5ec53f --- /dev/null +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/compartment/SbmlCompartmentExporter.java @@ -0,0 +1,101 @@ +package lcsb.mapviewer.converter.model.sbml.compartment; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph; +import org.sbml.jsbml.ext.layout.BoundingBox; +import org.sbml.jsbml.ext.layout.CompartmentGlyph; +import org.sbml.jsbml.ext.layout.Dimensions; +import org.sbml.jsbml.ext.layout.Layout; +import org.sbml.jsbml.ext.layout.Point; + +import lcsb.mapviewer.converter.model.sbml.SbmlElementExporter; +import lcsb.mapviewer.model.map.InconsistentModelException; +import lcsb.mapviewer.model.map.compartment.Compartment; + +public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, org.sbml.jsbml.Compartment> { + Logger logger = Logger.getLogger(SbmlCompartmentExporter.class); + + public SbmlCompartmentExporter(Layout layout, lcsb.mapviewer.model.map.model.Model minervaModel) { + super(layout, minervaModel); + } + + @Override + public org.sbml.jsbml.Compartment createSbmlElement(Compartment element) throws InconsistentModelException { + org.sbml.jsbml.Compartment result; + if (element == null || element.getElementId().equals("default")) { + result = getSbmlModel().createCompartment("default"); + } else { + result = getSbmlModel().createCompartment("comp_" + (getNextId())); + } + //for now we don't have this information - needed for validation + result.setConstant(false); + return result; + } + + @Override + protected List<Compartment> getElementList() { + List<Compartment> result = new ArrayList<>(); + result.addAll(getMinervaModel().getCompartments()); + boolean defaultFound = false; + for (Compartment compartment : result) { + if (compartment.getElementId().equals("default")) { + defaultFound = true; + } + } + if (!defaultFound) { + Compartment defaultCompartment = new Compartment("default"); + result.add(defaultCompartment); + } + return result; + } + + @Override + protected AbstractReferenceGlyph createElementGlyph(String sbmlCompartmentId, String glyphId) { + if (sbmlCompartmentId.equals("default")) { + glyphId = "default_compartment"; + } + CompartmentGlyph result = getLayout().createCompartmentGlyph(glyphId, sbmlCompartmentId); + return result; + } + + @Override + protected String getSbmlIdKey(Compartment compartment) { + if (compartment == null || compartment.getElementId().equals("default")) { + return "default"; + } + return compartment.getName(); + } + + @Override + protected void assignLayoutToGlyph(Compartment element, AbstractReferenceGlyph speciesGlyph) { + if (element.getElementId().equals("default")) { + BoundingBox boundingBox = new BoundingBox(); + + boundingBox.setPosition(new Point(element.getX(), element.getY())); + Dimensions dimensions = new Dimensions(); + + if (getMinervaModel().getWidth() != null) { + dimensions.setWidth(getMinervaModel().getWidth()); + dimensions.setHeight(getMinervaModel().getHeight()); + } + boundingBox.setDimensions(dimensions); + speciesGlyph.setBoundingBox(boundingBox); + } else { + super.assignLayoutToGlyph(element, speciesGlyph); + } + } + + @Override + public org.sbml.jsbml.Compartment getSbmlElement(Compartment element) throws InconsistentModelException { + String mapKey = getSbmlIdKey(element); + if (element == null && sbmlElementByElementNameAndCompartmentName.get(mapKey) == null) { + org.sbml.jsbml.Compartment sbmlElement = createSbmlElement(element); + sbmlElementByElementNameAndCompartmentName.put(mapKey, sbmlElement); + } + return super.getSbmlElement(element); + } + +} diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlCompartmentParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/compartment/SbmlCompartmentParser.java similarity index 84% rename from converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlCompartmentParser.java rename to converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/compartment/SbmlCompartmentParser.java index 1853edcf89e597da59a2304fe944df56474bbe1d..7fe2925b571841f96f5baa348b556e42127f4000 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlCompartmentParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/compartment/SbmlCompartmentParser.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.model.sbml; +package lcsb.mapviewer.converter.model.sbml.compartment; import java.util.ArrayList; import java.util.List; @@ -13,6 +13,7 @@ import org.sbml.jsbml.ext.layout.Layout; import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.converter.InvalidInputDataExecption; +import lcsb.mapviewer.converter.model.sbml.SbmlElementParser; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.SquareCompartment; import lcsb.mapviewer.model.map.species.Element; @@ -27,6 +28,9 @@ public class SbmlCompartmentParser extends SbmlElementParser<org.sbml.jsbml.Comp @Override protected Compartment parse(org.sbml.jsbml.Compartment compartment, Model sbmlModel) throws InvalidInputDataExecption { + if (compartment.getId().equals("default")) { + return null; + } Compartment result = new SquareCompartment(compartment.getId()); assignBioEntityData(compartment, result); return result; @@ -38,7 +42,7 @@ public class SbmlCompartmentParser extends SbmlElementParser<org.sbml.jsbml.Comp } @Override - protected List<Element> mergeLayout(List<? extends Element> elements, Layout sbmlLayout, Model sbmlModel) + public List<Element> mergeLayout(List<? extends Element> elements, Layout sbmlLayout, Model sbmlModel) throws InvalidInputDataExecption { List<Element> result = super.mergeLayout(elements, sbmlLayout, sbmlModel); @@ -64,7 +68,9 @@ public class SbmlCompartmentParser extends SbmlElementParser<org.sbml.jsbml.Comp protected List<Pair<String, AbstractReferenceGlyph>> getGlyphs(Layout sbmlLayout) { List<Pair<String, AbstractReferenceGlyph>> result = new ArrayList<>(); for (CompartmentGlyph glyph : sbmlLayout.getListOfCompartmentGlyphs()) { - result.add(new Pair<String, AbstractReferenceGlyph>(glyph.getCompartment(), glyph)); + if (!glyph.getCompartment().equals("default")) { + result.add(new Pair<>(glyph.getCompartment(), glyph)); + } } return result; } diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporter.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporter.java index 5594f48fabb34e57ac59942acbf55576d0723715..441ee02e450c67864debaa1f489399fd54f78157 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporter.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporter.java @@ -77,11 +77,13 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb for (Product product : reaction.getProducts()) { Species sbmlSymbol = speciesExporter.getSbmlElementByElementId(product.getElement().getElementId()); SpeciesReference speciesReference = result.createProduct(sbmlSymbol); + speciesReference.setConstant(false); speciesReferenceByReactionNode.put(product, speciesReference); } for (Reactant reactant : reaction.getReactants()) { Species sbmlSymbol = speciesExporter.getSbmlElementByElementId(reactant.getElement().getElementId()); SpeciesReference speciesReference = result.createReactant(sbmlSymbol); + speciesReference.setConstant(false); speciesReferenceByReactionNode.put(reactant, speciesReference); } for (Modifier modifier : reaction.getModifiers()) { @@ -261,13 +263,12 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb } private LocalStyle createStyleForModifier(Modifier modifier) { - LocalRenderInformation renderInformation = new LocalRenderInformation(); + LocalRenderInformation renderInformation = getRenderInformation(getRenderPlugin()); LocalStyle style = new LocalStyle(); style.getRoleList() .add("style_" + modifier.getReaction().getElementId() + "_modifier_" + modifier.getElement().getElementId()); style.setGroup(new RenderGroup()); renderInformation.addLocalStyle(style); - getRenderPlugin().addLocalRenderInformation(renderInformation); style.getGroup().setStroke(modifier.getLine().getType().name()); return style; } diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionParser.java index 0b001e485d9d1fc40bc7c96b5451b80da3ec81bb..e3614d5bb4eda32a71b24d0b6229cdde783a253e 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionParser.java @@ -35,8 +35,8 @@ import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.InvalidInputDataExecption; import lcsb.mapviewer.converter.model.celldesigner.types.ModifierType; import lcsb.mapviewer.converter.model.sbml.SbmlBioEntityParser; -import lcsb.mapviewer.converter.model.sbml.SbmlCompartmentParser; import lcsb.mapviewer.converter.model.sbml.SbmlParameterParser; +import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentParser; import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesParser; import lcsb.mapviewer.model.graphics.ArrowType; import lcsb.mapviewer.model.graphics.ArrowTypeData; diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporter.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporter.java index dba417b2738f687400dc32e25ea076b234e8eb52..806ba53900fdce13be552be6f00f72c7a04b770c 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporter.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporter.java @@ -7,8 +7,8 @@ import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph; import org.sbml.jsbml.ext.layout.Layout; import org.sbml.jsbml.ext.render.LocalStyle; -import lcsb.mapviewer.converter.model.sbml.SbmlCompartmentExporter; import lcsb.mapviewer.converter.model.sbml.SbmlElementExporter; +import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentExporter; import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.species.Species; @@ -26,12 +26,19 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j public org.sbml.jsbml.Species createSbmlElement(Species element) throws InconsistentModelException { org.sbml.jsbml.Species result = getSbmlModel().createSpecies("species_" + (getNextId())); result.setSBOTerm(SBOTermSpeciesType.getTermByType(element.getClass())); - if (element.getCompartment() != null) { - result.setCompartment(compartmentExporter.getSbmlElement(element.getCompartment())); - } + result.setCompartment(compartmentExporter.getSbmlElement(element.getCompartment())); if (element.getInitialAmount() != null) { result.setInitialAmount(element.getInitialAmount()); } + if (element.hasOnlySubstanceUnits() != null) { + result.setHasOnlySubstanceUnits(element.hasOnlySubstanceUnits()); + } + if (element.getBoundaryCondition() != null) { + result.setBoundaryCondition(element.getBoundaryCondition()); + } + if (element.getConstant() != null) { + result.setConstant(element.getConstant()); + } return result; } @@ -56,7 +63,7 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j if (element.getComplex() != null) { complexName = element.getComplex().getName(); } - return element.getClass().getSimpleName() + "\n" + element.getName() + "\n" + compartmentName+ "\n" + complexName; + return element.getClass().getSimpleName() + "\n" + element.getName() + "\n" + compartmentName + "\n" + complexName; } protected LocalStyle createStyle(Species element) { diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java index c17c23765e6b96ef4e29f3a242395b22d58f82b5..7e9d35443eb4bd1f50e548bff33a8726f25a04a3 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParser.java @@ -37,6 +37,15 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species> if (!Double.isNaN(species.getInitialAmount())) { result.setInitialAmount(species.getInitialAmount()); } + if (species.isSetHasOnlySubstanceUnits()) { + result.setOnlySubstanceUnits(species.hasOnlySubstanceUnits()); + } + if (species.isSetBoundaryCondition()) { + result.setBoundaryCondition(species.getBoundaryCondition()); + } + if (species.isSetConstant()) { + result.setConstant(species.getConstant()); + } assignBioEntityData(species, result); if (layout == null) { assignCompartment(result, species.getCompartment()); @@ -71,7 +80,7 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species> if (compartment == null && layout != null) { List<Compartment> compartments = new ArrayList<>(); for (CompartmentGlyph glyph : layout.getListOfCompartmentGlyphs()) { - if (glyph.getCompartment().equals(compartmentId)) { + if (glyph.getCompartment().equals(compartmentId) && !glyph.getCompartment().equals("default")) { compartments.add(minervaModel.getElementByElementId(glyph.getId())); } } diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlExporterTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlExporterTest.java index 75a368f66c5e5c02a882a3a552a22c7b35c67f71..2a71a99c922b843070be949031bb9c62f553153b 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlExporterTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/SbmlExporterTest.java @@ -68,7 +68,6 @@ public class SbmlExporterTest { private Model getModelAfterSerializing(Model originalModel) throws Exception { String xml = exporter.toXml(originalModel); - logger.debug(xml); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8")); Model result = parser.createModel(new ConverterParams().inputStream(stream)); // showImage(originalModel); @@ -184,6 +183,8 @@ public class SbmlExporterTest { private Model createModelWithReaction() { Model model = new ModelFullIndexed(null); + model.setWidth(1000); + model.setHeight(1000); GenericProtein p1 = new GenericProtein("s1"); p1.setWidth(100); p1.setHeight(20); diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExportArrowType.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExportArrowType.java index 99be07708747cd4e6001d377039ecedb064867dd..d630040e5a232218753722f4afd2a09723271eeb 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExportArrowType.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExportArrowType.java @@ -68,31 +68,17 @@ public class SbmlReactionExportArrowType { Model model = new ModelFullIndexed(null); model.setWidth(1000); model.setHeight(1000); - Ion ion = new Ion("x1"); - ion.setName("ion 1"); - ion.setWidth(100); - ion.setHeight(100); - ion.setX(200); - ion.setY(50); + Ion ion = createIon(1); model.addElement(ion); - Ion ion2 = new Ion("x2"); - ion2.setName("ion 1"); - ion2.setWidth(100); - ion2.setHeight(100); - ion2.setX(200); - ion2.setY(250); + Ion ion2 = createIon(2); model.addElement(ion2); - Ion ion3 = new Ion("x3"); - ion3.setName("ion 1"); - ion3.setWidth(100); - ion3.setHeight(100); - ion3.setX(400); - ion3.setY(450); + Ion ion3 = createIon(3); model.addElement(ion3); Reaction reaction = (Reaction) clazz.getConstructor().newInstance(); + reaction.setIdReaction("reactionId"); reaction.addReactant(createReactant(ion)); Product product = createProduct(ion2); reaction.addProduct(product); @@ -133,6 +119,20 @@ public class SbmlReactionExportArrowType { return modelAfterSerialization; } + private static Ion createIon(int id) { + Ion ion = new Ion("x" + id); + ion.setName("ion " + id); + ion.setWidth(100); + ion.setHeight(100); + ion.setX(200 * (id % 2 + 1)); + ion.setY(50 * (id / 2 + 1)); + ion.setOnlySubstanceUnits(true); + ion.setConstant(true); + ion.setInitialAmount(2.0); + ion.setBoundaryCondition(true); + return ion; + } + private static Reactant createReactant(Ion ion) { Reactant result = new Reactant(ion); Point2D point = ion.getCenter(); @@ -164,7 +164,7 @@ public class SbmlReactionExportArrowType { Reaction originalReaction = modelToBeTested.getReactions().iterator().next(); Reaction afterSerializationReaction = modelAfterSerialization.getReactions().iterator().next(); - + afterSerializationReaction.setIdReaction(originalReaction.getIdReaction()); assertEquals(0, reactionComparator.compare(originalReaction, afterSerializationReaction)); } catch (Exception e) { diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporterTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporterTest.java index 472737e3dd47a1c5d0c837a68da664a05bea1255..b41612ed3ec30e12d23dbfba3fb338e177e67970 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporterTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporterTest.java @@ -10,7 +10,7 @@ import org.sbml.jsbml.ext.layout.Layout; import org.sbml.jsbml.ext.layout.LayoutModelPlugin; import lcsb.mapviewer.converter.model.sbml.SbmlBioEntityExporter; -import lcsb.mapviewer.converter.model.sbml.SbmlCompartmentExporter; +import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentExporter; import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesExporter; import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.kinetics.SbmlKinetics; diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporterTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporterTest.java index a3ed722dd9f0e8e8ac8a43b54718feb80bac05f5..0a5a2db97f858a34d10b2be982b7b44ab6efd84b 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporterTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesExporterTest.java @@ -7,8 +7,8 @@ import org.junit.Test; import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.ext.layout.Layout; -import lcsb.mapviewer.converter.model.sbml.SbmlCompartmentExporter; import lcsb.mapviewer.converter.model.sbml.SbmlExporter; +import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentExporter; import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java index 99fd30b620d0a1e04ad903aaab9975a434516b1d..320f64b88aaef466070471fa289582caa970680d 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java @@ -152,4 +152,10 @@ public class SbmlSpeciesParserTest { Species element = model.getElementByElementId("s1"); assertEquals((Double)1.0, element.getInitialAmount()); } + @Test + public void testParseHasOnlySubstanceUnits() throws Exception { + Model model = parser.createModel(new ConverterParams().filename("testFiles/small/has_only_substance_units.xml")); + Species element = model.getElementByElementId("s1"); + assertTrue(element.hasOnlySubstanceUnits()); + } } diff --git a/converter-sbml/testFiles/small/has_only_substance_units.xml b/converter-sbml/testFiles/small/has_only_substance_units.xml new file mode 100644 index 0000000000000000000000000000000000000000..311e9322fa3558a7cf9f003310cf54ac13869473 --- /dev/null +++ b/converter-sbml/testFiles/small/has_only_substance_units.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4"> + <model id="TestGEN"> + <annotation/> + <listOfCompartments> + <compartment constant="true" id="cell" name="cell" sboTerm="SBO:0000290" size="1"> + <annotation> + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bqmodel="http://biomodels.net/model-qualifiers/" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/"> + <rdf:Description rdf:about="#"> + <bqbiol:isVersionOf> + <rdf:Bag> + <rdf:li rdf:resource="urn:miriam:obo.go:GO:0005623"/> + </rdf:Bag> + </bqbiol:isVersionOf> + </rdf:Description> + </rdf:RDF> + </annotation> + </compartment> + </listOfCompartments> + <listOfSpecies> + <species boundaryCondition="false" compartment="cell" hasOnlySubstanceUnits="true" id="s1" name="nm1" sboTerm="SBO:0000247" initialAmount="1"> + <annotation/> + </species> + </listOfSpecies> + </model> +</sbml> \ No newline at end of file