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

layout is no longer passed as an argument - it's always taken from the model

parent 842e8541
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",!560Resolve "add support for modifications and states in sbml export/import"
......@@ -12,7 +12,6 @@ import org.apache.log4j.Logger;
import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderConstants;
import org.sbml.jsbml.ext.render.RenderGraphicalObjectPlugin;
......@@ -22,16 +21,20 @@ import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.model.map.species.Element;
public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends SbmlBioEntityParser {
Logger logger = Logger.getLogger(SbmlElementParser.class);
/**
* Default class logger.
*/
private Logger logger = Logger.getLogger(SbmlElementParser.class);
public SbmlElementParser(Model sbmlModel, lcsb.mapviewer.model.map.model.Model minervaModel) {
super(sbmlModel, minervaModel);
}
public List<Element> parseList(Model sbmlModel) throws InvalidInputDataExecption {
public List<Element> parseList() throws InvalidInputDataExecption {
List<Element> result = new ArrayList<>();
for (T sbmlElement : getSbmlElementList(sbmlModel)) {
Element element = parse(sbmlElement, sbmlModel);
for (T sbmlElement : getSbmlElementList()) {
Element element = parse(sbmlElement);
if (element != null) {
result.add(element);
elementBySbmlId.put(element.getElementId(), element);
......@@ -40,7 +43,7 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
return result;
}
protected abstract ListOf<T> getSbmlElementList(Model sbmlModel);
protected abstract ListOf<T> getSbmlElementList();
Map<String, Element> elementBySbmlId = new HashMap<>();
......@@ -54,7 +57,7 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
return sbmlIdByElementId.get(compartmentId);
}
protected List<Element> mergeLayout(List<? extends Element> elements, Layout sbmlLayout, Model sbmlModel)
protected List<Element> mergeLayout(List<? extends Element> elements)
throws InvalidInputDataExecption {
Set<String> used = new HashSet<>();
List<Element> result = new ArrayList<>();
......@@ -69,7 +72,7 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
applyStyleToElement(element, style);
}
}
for (Pair<String, AbstractReferenceGlyph> idGlyphPair : getGlyphs(sbmlLayout)) {
for (Pair<String, AbstractReferenceGlyph> idGlyphPair : getGlyphs()) {
String id = idGlyphPair.getLeft();
Element source = elementBySbmlId.get(id);
if (source == null) {
......@@ -125,8 +128,8 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
}
}
protected abstract List<Pair<String, AbstractReferenceGlyph>> getGlyphs(Layout sbmlLayout);
protected abstract List<Pair<String, AbstractReferenceGlyph>> getGlyphs();
protected abstract Element parse(T species, Model sbmlModel) throws InvalidInputDataExecption;
protected abstract Element parse(T species) throws InvalidInputDataExecption;
}
......@@ -87,9 +87,9 @@ public class SbmlParser implements IConverter {
model.addParameters(parameterParser.parseList(sbmlModel));
model.addFunctions(functionParser.parseList(sbmlModel));
model.addElements(compartmentParser.parseList(sbmlModel));
model.addElements(speciesParser.parseList(sbmlModel));
model.addReactions(reactionParser.parseList(sbmlModel));
model.addElements(compartmentParser.parseList());
model.addElements(speciesParser.parseList());
model.addReactions(reactionParser.parseList());
if (layoutExists) {
if (layout.getDimensions() != null) {
......@@ -97,9 +97,9 @@ public class SbmlParser implements IConverter {
model.setHeight(layout.getDimensions().getHeight());
}
compartmentParser.mergeLayout(model.getCompartments(), layout, sbmlModel);
speciesParser.mergeLayout(model.getSpeciesList(), layout, sbmlModel);
reactionParser.mergeLayout(model.getReactions(), layout, sbmlModel);
compartmentParser.mergeLayout(model.getCompartments());
speciesParser.mergeLayout(model.getSpeciesList());
reactionParser.mergeLayout(model.getReactions());
}
reactionParser.validateReactions(model.getReactions());
......
......@@ -6,10 +6,8 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
import org.sbml.jsbml.ext.layout.CompartmentGlyph;
import org.sbml.jsbml.ext.layout.Layout;
import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand;
import lcsb.mapviewer.common.Pair;
......@@ -20,14 +18,18 @@ import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.species.Element;
public class SbmlCompartmentParser extends SbmlElementParser<org.sbml.jsbml.Compartment> {
Logger logger = Logger.getLogger(SbmlCompartmentParser.class);
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(SbmlCompartmentParser.class);
public SbmlCompartmentParser(Model sbmlModel, lcsb.mapviewer.model.map.model.Model minervaModel) {
super(sbmlModel, minervaModel);
}
@Override
protected Compartment parse(org.sbml.jsbml.Compartment compartment, Model sbmlModel)
protected Compartment parse(org.sbml.jsbml.Compartment compartment)
throws InvalidInputDataExecption {
if (compartment.getId().equals("default")) {
return null;
......@@ -38,14 +40,14 @@ public class SbmlCompartmentParser extends SbmlElementParser<org.sbml.jsbml.Comp
}
@Override
protected ListOf<org.sbml.jsbml.Compartment> getSbmlElementList(Model sbmlModel) {
return sbmlModel.getListOfCompartments();
protected ListOf<org.sbml.jsbml.Compartment> getSbmlElementList() {
return getSbmlModel().getListOfCompartments();
}
@Override
public List<Element> mergeLayout(List<? extends Element> elements, Layout sbmlLayout, Model sbmlModel)
public List<Element> mergeLayout(List<? extends Element> elements)
throws InvalidInputDataExecption {
List<Element> result = super.mergeLayout(elements, sbmlLayout, sbmlModel);
List<Element> result = super.mergeLayout(elements);
for (Element element : result) {
Compartment parent = element.getCompartment();
......@@ -66,9 +68,9 @@ public class SbmlCompartmentParser extends SbmlElementParser<org.sbml.jsbml.Comp
}
@Override
protected List<Pair<String, AbstractReferenceGlyph>> getGlyphs(Layout sbmlLayout) {
protected List<Pair<String, AbstractReferenceGlyph>> getGlyphs() {
List<Pair<String, AbstractReferenceGlyph>> result = new ArrayList<>();
for (CompartmentGlyph glyph : sbmlLayout.getListOfCompartmentGlyphs()) {
for (CompartmentGlyph glyph : getLayout().getListOfCompartmentGlyphs()) {
if (!glyph.getCompartment().equals("default")) {
result.add(new Pair<>(glyph.getCompartment(), glyph));
}
......
......@@ -19,7 +19,6 @@ import org.sbml.jsbml.Model;
import org.sbml.jsbml.ModifierSpeciesReference;
import org.sbml.jsbml.SpeciesReference;
import org.sbml.jsbml.ext.layout.CurveSegment;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.ReactionGlyph;
import org.sbml.jsbml.ext.layout.SpeciesGlyph;
import org.sbml.jsbml.ext.layout.SpeciesReferenceGlyph;
......@@ -82,19 +81,19 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
this.compartmentParser = compartmentParser;
}
public List<Reaction> parseList(Model sbmlModel) throws InvalidInputDataExecption {
public List<Reaction> parseList() throws InvalidInputDataExecption {
List<Reaction> result = new ArrayList<>();
for (org.sbml.jsbml.Reaction sbmlElement : getSbmlElementList(sbmlModel)) {
result.add(parse(sbmlElement, sbmlModel));
for (org.sbml.jsbml.Reaction sbmlElement : getSbmlElementList()) {
result.add(parse(sbmlElement));
}
return result;
}
protected ListOf<org.sbml.jsbml.Reaction> getSbmlElementList(Model sbmlModel) {
return sbmlModel.getListOfReactions();
protected ListOf<org.sbml.jsbml.Reaction> getSbmlElementList() {
return getSbmlModel().getListOfReactions();
}
public void mergeLayout(Collection<Reaction> reactions, Layout sbmlLayout, Model sbmlModel)
public void mergeLayout(Collection<Reaction> reactions)
throws InvalidInputDataExecption {
Set<Reaction> used = new HashSet<>();
Map<String, Reaction> reactionById = new HashMap<>();
......@@ -105,7 +104,7 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
reactionById.put(reaction.getIdReaction(), reaction);
}
for (ReactionGlyph glyph : sbmlLayout.getListOfReactionGlyphs()) {
for (ReactionGlyph glyph : getLayout().getListOfReactionGlyphs()) {
Reaction source = reactionById.get(glyph.getReaction());
if (source == null) {
throw new InvalidInputDataExecption("Layout contains invalid Species id: " + glyph.getReaction());
......@@ -423,7 +422,7 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
}
protected Reaction parse(org.sbml.jsbml.Reaction sbmlReaction, Model sbmlModel) throws InvalidInputDataExecption {
protected Reaction parse(org.sbml.jsbml.Reaction sbmlReaction) throws InvalidInputDataExecption {
Reaction reaction = new Reaction();
assignBioEntityData(sbmlReaction, reaction);
reaction.setIdReaction(sbmlReaction.getId());
......
......@@ -9,7 +9,6 @@ import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
import org.sbml.jsbml.ext.layout.CompartmentGlyph;
import org.sbml.jsbml.ext.layout.Layout;
import org.sbml.jsbml.ext.layout.SpeciesGlyph;
import org.sbml.jsbml.ext.render.LocalStyle;
......@@ -34,7 +33,7 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
}
@Override
protected Species parse(org.sbml.jsbml.Species species, Model sbmlModel) throws InvalidInputDataExecption {
protected Species parse(org.sbml.jsbml.Species species) throws InvalidInputDataExecption {
String sboTerm = species.getSBOTermID();
Class<? extends Species> clazz = SBOTermSpeciesType.getTypeSBOTerm(sboTerm);
try {
......@@ -63,19 +62,19 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
}
@Override
public List<Element> mergeLayout(List<? extends Element> elements, Layout sbmlLayout, Model sbmlModel)
public List<Element> mergeLayout(List<? extends Element> elements)
throws InvalidInputDataExecption {
List<Element> result = super.mergeLayout(elements, sbmlLayout, sbmlModel);
List<Element> result = super.mergeLayout(elements);
for (Element element : result) {
String compartmentId = null;
if (sbmlLayout.getSpeciesGlyph(element.getElementId()) != null) {
compartmentId = ((org.sbml.jsbml.Species) sbmlLayout.getSpeciesGlyph(element.getElementId())
if (getLayout().getSpeciesGlyph(element.getElementId()) != null) {
compartmentId = ((org.sbml.jsbml.Species) getLayout().getSpeciesGlyph(element.getElementId())
.getSpeciesInstance()).getCompartment();
} else {
if (!element.getElementId().equals(ARTIFITIAL_SINK_ID)
&& !element.getElementId().equals(ARTIFITIAL_SOURCE_ID)) {
compartmentId = sbmlModel.getSpecies(element.getElementId()).getCompartment();
compartmentId = getSbmlModel().getSpecies(element.getElementId()).getCompartment();
}
}
assignCompartment(element, compartmentId);
......@@ -106,14 +105,14 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
}
@Override
protected ListOf<org.sbml.jsbml.Species> getSbmlElementList(Model sbmlModel) {
return sbmlModel.getListOfSpecies();
protected ListOf<org.sbml.jsbml.Species> getSbmlElementList() {
return getSbmlModel().getListOfSpecies();
}
@Override
protected List<Pair<String, AbstractReferenceGlyph>> getGlyphs(Layout sbmlLayout) {
protected List<Pair<String, AbstractReferenceGlyph>> getGlyphs() {
List<Pair<String, AbstractReferenceGlyph>> result = new ArrayList<>();
for (SpeciesGlyph glyph : sbmlLayout.getListOfSpeciesGlyphs()) {
for (SpeciesGlyph glyph : getLayout().getListOfSpeciesGlyphs()) {
result.add(new Pair<String, AbstractReferenceGlyph>(glyph.getSpecies(), glyph));
}
return result;
......
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