Skip to content
Snippets Groups Projects
Commit c09422ac authored by Piotr Gawron's avatar Piotr Gawron
Browse files

export to sbml includes default compartment, and import ingornes this compartment

parent bb9b51a5
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!508Resolve "Export to SBML results in invalid SBML file"
Showing
with 123 additions and 54 deletions
......@@ -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;
......
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();
}
}
......@@ -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;
}
......
......@@ -18,6 +18,7 @@ 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;
......
......@@ -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;
......
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 {
if (element == null || element.getElementId().equals("default")) {
return getSbmlModel().createCompartment("default");
}
return getSbmlModel().createCompartment("comp_" + (getNextId()));
}
@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);
}
}
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;
}
......
......@@ -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;
......
......@@ -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,9 +26,7 @@ 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());
}
......@@ -56,7 +54,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) {
......
......@@ -71,7 +71,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()));
}
}
......
......@@ -184,6 +184,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);
......
......@@ -93,6 +93,7 @@ public class SbmlReactionExportArrowType {
model.addElement(ion3);
Reaction reaction = (Reaction) clazz.getConstructor().newInstance();
reaction.setIdReaction("reactionId");
reaction.addReactant(createReactant(ion));
Product product = createProduct(ion2);
reaction.addProduct(product);
......
......@@ -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;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment