Commit 5f6b4efc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '554-poor-handling-of-modification-states-when-exporting-to-sbgn-ml' into 'master'

Resolve "Poor handling of modification states when exporting to SBGN-ML"

Closes #554

See merge request minerva/core!1010
parents 2f04b2ef 79e345e9
......@@ -11,6 +11,8 @@ minerva (15.0.0~alpha.1) stable; urgency=medium
exporter violates SBGN specification (#707)
* Bug fix: unknown catalysis boolean gate modifiers in CellDesigner are
visualized with proper line type across all included modifiers (#957)
* Bug fix: dimension of the modifications is the same as in minerva when
exporting to SBGNML-PD (#554)
minerva (15.0.0~alpha.0) stable; urgency=medium
* Improvement: logs provided for validation data model are structurized (#325)
......
......@@ -15,6 +15,7 @@ import org.sbgn.bindings.Map;
import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SpeciesConverter;
import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter;
import lcsb.mapviewer.model.graphics.ArrowType;
import lcsb.mapviewer.model.graphics.PolylineData;
......@@ -205,7 +206,7 @@ public class SbgnmlXmlExporter {
glyph.setState(state);
Bbox bbox = new Bbox();
float width = structuralState.getWidth().floatValue();
float height = structuralState.getHeight().floatValue();
bbox.setH(height);
......@@ -400,32 +401,28 @@ public class SbgnmlXmlExporter {
glyph.setId(mr.getIdModificationResidue());
glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz());
double width = SpeciesConverter.DEFAULT_MODIFICATION_DIAMETER;
double height = SpeciesConverter.DEFAULT_MODIFICATION_DIAMETER;
if (mr instanceof AbstractSiteModification) {
AbstractSiteModification modification = (AbstractSiteModification) mr;
Glyph.State state = new Glyph.State();
state.setVariable(mr.getName());
glyph.setState(state);
if (modification.getState() != null) {
Glyph.State state = new Glyph.State();
state.setValue(modification.getState().getAbbreviation());
state.setVariable(mr.getName());
glyph.setState(state);
}
} else if (mr instanceof AbstractRegionModification) {
width = ((AbstractRegionModification) mr).getWidth();
height = ((AbstractRegionModification) mr).getHeight();
}
Bbox bbox = new Bbox();
final float filledWidth = 70.0f;
final float filledHeight = 28.0f;
final float emptyWidth = 20.0f;
final float emptyHeight = 22.0f;
if (glyph.getState() != null) {
bbox.setH(filledHeight);
bbox.setW(filledWidth);
} else {
bbox.setH(emptyHeight);
bbox.setW(emptyWidth);
}
bbox.setH((float) width);
bbox.setW((float) height);
bbox.setX((float) mr.getPosition().getX());
bbox.setY((float) mr.getPosition().getY());
bbox.setX((float) (mr.getPosition().getX() - width / 2));
bbox.setY((float) (mr.getPosition().getY() - height / 2));
glyph.setBbox(bbox);
......
......@@ -4,15 +4,14 @@ import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbgn.*;
import org.sbgn.bindings.*;
import org.sbgn.bindings.Arc.*;
import org.sbgn.bindings.Map;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.DoubleComparator;
......@@ -80,6 +79,8 @@ public class SbgnmlXmlParser {
*/
private List<Arc> logicArcs = new ArrayList<Arc>();
Model model;
/**
* Method used to create a model from SBGN-ML file.
*
......@@ -94,7 +95,7 @@ public class SbgnmlXmlParser {
*/
public Model createModel(String filename, File inputSbgnmlFile) throws InvalidInputDataExecption {
Model model = new ModelFullIndexed(null);
model = new ModelFullIndexed(null);
model.setIdModel(filename);
Sbgn sbgnData;
......@@ -598,7 +599,7 @@ public class SbgnmlXmlParser {
logger.warn("Only macromolecule elements can have state variables.");
}
} else {
StructuralState state = stateVariableToStructuralState(child);
StructuralState state = createStructuralState(child);
if (newSpecies instanceof Protein) {
((Protein) newSpecies).setStructuralState(state);
} else {
......@@ -625,21 +626,12 @@ public class SbgnmlXmlParser {
}
private StructuralState stateVariableToStructuralState(Glyph glyph) {
StructuralState state = new StructuralState();
state.setFontSize(10);
state.setPosition(new Point2D.Double(glyph.getBbox().getX(), glyph.getBbox().getY()));
state.setHeight((double) glyph.getBbox().getH());
state.setWidth((double) glyph.getBbox().getW());
if (glyph.getState() != null) {
state.setValue(glyph.getState().getValue());
}
return state;
}
private StructuralState createStructuralState(Glyph glyph) {
if (glyph.getState() == null || glyph.getState().getValue() == null) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, glyph.getId(), "state", model.getName()),
"Invalid structural state");
return null;
}
StructuralState structuralState = new StructuralState();
double height = new Double(glyph.getBbox().getH());
......
......@@ -3,21 +3,29 @@ package lcsb.mapviewer.converter.model.sbgnml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.map.Drawable;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.StructuralStateComparator;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -114,4 +122,35 @@ public class CellDesignerToSbgnTest extends SbgnmlTestFunctions {
assertEquals(0, comparator.compare(protein1.getStructuralState(), protein2.getStructuralState()));
}
@Test
public void testModifications() throws Exception {
Converter converter = new CellDesignerXmlParser();
Converter converter2 = new SbgnmlXmlConverter();
Model model = converter.createModel(new ConverterParams().filename("testFiles/cellDesigner/modifications.xml"));
String output = File.createTempFile("temp-sbgn-output", ".sbgn").getAbsolutePath();
converter2.model2File(model, output);
Model model2 = converter2.createModel(new ConverterParams().filename(output).sizeAutoAdjust(false));
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
for (ModificationResidue region : ((Protein)model.getElementByElementId("sa3988")).getModificationResidues()) {
set1.add(region.toString());
}
for (ModificationResidue region : ((Protein)model2.getElementByElementId("sa3988")).getModificationResidues()) {
set2.add(region.toString());
}
SetComparator<String> comparator = new SetComparator<>(new StringComparator());
assertEquals(0, comparator.compare(set1, set2));
new File(output).delete();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
<model metaid="A_comprehensive_Parkinsons_disease_map" id="A_comprehensive_Parkinsons_disease_map">
<listOfUnitDefinitions>
<unitDefinition id="substance" name="substance" >
<listOfUnits>
<unit kind="mole" scale="0" exponent="1" multiplier="1.0" />
</listOfUnits>
</unitDefinition><unitDefinition id="length" name="length" >
<listOfUnits>
<unit kind="metre" scale="0" exponent="1" multiplier="1.0" />
</listOfUnits>
</unitDefinition><unitDefinition id="time" name="time" >
<listOfUnits>
<unit kind="second" scale="0" exponent="1" multiplier="1.0" />
</listOfUnits>
</unitDefinition><unitDefinition id="volume" name="volume" >
<listOfUnits>
<unit kind="litre" scale="0" exponent="1" multiplier="1.0" />
</listOfUnits>
</unitDefinition><unitDefinition id="area" name="area" >
<listOfUnits>
<unit kind="metre" scale="0" exponent="2" multiplier="1.0" />
</listOfUnits>
</unitDefinition></listOfUnitDefinitions>
<notes><html xmlns="http://www.w3.org/1999/xhtml"><head><title/></head><body></body></html></notes><annotation>
<celldesigner:extension>
<celldesigner:modelVersion>4.0</celldesigner:modelVersion>
<celldesigner:modelDisplay sizeX="2203" sizeY="1269"/>
<celldesigner:listOfIncludedSpecies>
<celldesigner:species id="s_id_sa3987" name="NFKBIA"><celldesigner:notes><html xmlns="http://www.w3.org/1999/xhtml"><head><title/></head><body>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#s_id_sa3987">
</rdf:Description>
</rdf:RDF>
</body></html></celldesigner:notes>
<celldesigner:annotation>
<celldesigner:complexSpecies>s_id_csa553</celldesigner:complexSpecies>
<celldesigner:speciesIdentity><celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>p_s_id_sa3987</celldesigner:proteinReference>
<celldesigner:state>
<celldesigner:listOfModifications>
<celldesigner:modification residue="rs1" state="phosphorylated"> </celldesigner:modification>
<celldesigner:modification residue="rs2" state="phosphorylated"> </celldesigner:modification>
</celldesigner:listOfModifications>
</celldesigner:state>
<celldesigner:name>NFKBIA</celldesigner:name>
</celldesigner:speciesIdentity>
</celldesigner:annotation>
</celldesigner:species>
<celldesigner:species id="s_id_sa3989" name="NFKB1"><celldesigner:notes><html xmlns="http://www.w3.org/1999/xhtml"><head><title/></head><body>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#s_id_sa3989">
</rdf:Description>
</rdf:RDF>
</body></html></celldesigner:notes>
<celldesigner:annotation>
<celldesigner:complexSpecies>s_id_csa553</celldesigner:complexSpecies>
<celldesigner:speciesIdentity><celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>p_s_id_sa3989</celldesigner:proteinReference>
<celldesigner:name>NFKB1</celldesigner:name>
</celldesigner:speciesIdentity>
</celldesigner:annotation>
</celldesigner:species>
<celldesigner:species id="s_id_sa3988" name="RELA"><celldesigner:notes><html xmlns="http://www.w3.org/1999/xhtml"><head><title/></head><body>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#s_id_sa3988">
</rdf:Description>
</rdf:RDF>
</body></html></celldesigner:notes>
<celldesigner:annotation>
<celldesigner:complexSpecies>s_id_csa553</celldesigner:complexSpecies>
<celldesigner:speciesIdentity><celldesigner:class>PROTEIN</celldesigner:class>
<celldesigner:proteinReference>p_s_id_sa3988</celldesigner:proteinReference>
<celldesigner:state>
<celldesigner:listOfModifications>
</celldesigner:listOfModifications>
</celldesigner:state>
<celldesigner:name>RELA</celldesigner:name>
</celldesigner:speciesIdentity>
</celldesigner:annotation>
</celldesigner:species>
</celldesigner:listOfIncludedSpecies>
<celldesigner:listOfCompartmentAliases>
</celldesigner:listOfCompartmentAliases>
<celldesigner:listOfComplexSpeciesAliases>
<celldesigner:complexSpeciesAlias id="csa553" species="s_id_csa553" >
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="171.72326936217178" y="638.1046227966417" w="190.0" h="120.0" />
<celldesigner:font size="12"/><celldesigner:view state="usual"/>
<celldesigner:usualView><celldesigner:innerPosition x="171.72326936217178" y="638.1046227966417"/><celldesigner:boxSize width="190.0" height="120.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFF7F7F7" scheme="Color"/></celldesigner:usualView>
<celldesigner:briefView><celldesigner:innerPosition x="171.72326936217178" y="638.1046227966417"/><celldesigner:boxSize width="190.0" height="120.0"/><celldesigner:singleLine width="190.0"/><celldesigner:paint color="FFF7F7F7" scheme="Color"/></celldesigner:briefView>
</celldesigner:complexSpeciesAlias>
</celldesigner:listOfComplexSpeciesAliases>
<celldesigner:listOfSpeciesAliases>
<celldesigner:speciesAlias id="sa3988" species="s_id_sa3988" complexSpeciesAlias="csa553" >
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="268.056818181818" y="696.545454545454" w="80.0" h="40.0" />
<celldesigner:font size="12"/><celldesigner:view state="usual"/>
<celldesigner:usualView><celldesigner:innerPosition x="268.056818181818" y="696.545454545454"/><celldesigner:boxSize width="80.0" height="40.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFCCFFCC" scheme="Color"/></celldesigner:usualView>
<celldesigner:briefView><celldesigner:innerPosition x="268.056818181818" y="696.545454545454"/><celldesigner:boxSize width="80.0" height="40.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFCCFFCC" scheme="Color"/></celldesigner:briefView>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa3989" species="s_id_sa3989" complexSpeciesAlias="csa553" >
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="181.80681818181802" y="696.545454545454" w="80.0" h="40.0" />
<celldesigner:font size="12"/><celldesigner:view state="usual"/>
<celldesigner:usualView><celldesigner:innerPosition x="181.80681818181802" y="696.545454545454"/><celldesigner:boxSize width="80.0" height="40.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFCCFFCC" scheme="Color"/></celldesigner:usualView>
<celldesigner:briefView><celldesigner:innerPosition x="181.80681818181802" y="696.545454545454"/><celldesigner:boxSize width="80.0" height="40.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFCCFFCC" scheme="Color"/></celldesigner:briefView>
</celldesigner:speciesAlias>
<celldesigner:speciesAlias id="sa3987" species="s_id_sa3987" complexSpeciesAlias="csa553" >
<celldesigner:activity>inactive</celldesigner:activity>
<celldesigner:bounds x="226.067170457276" y="645.3546227966417" w="80.0" h="40.0" />
<celldesigner:font size="12"/><celldesigner:view state="usual"/>
<celldesigner:usualView><celldesigner:innerPosition x="226.067170457276" y="645.3546227966417"/><celldesigner:boxSize width="80.0" height="40.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFCCFFCC" scheme="Color"/></celldesigner:usualView>
<celldesigner:briefView><celldesigner:innerPosition x="226.067170457276" y="645.3546227966417"/><celldesigner:boxSize width="80.0" height="40.0"/><celldesigner:singleLine width="1.0"/><celldesigner:paint color="FFCCFFCC" scheme="Color"/></celldesigner:briefView>
</celldesigner:speciesAlias>
</celldesigner:listOfSpeciesAliases>
<celldesigner:listOfProteins><celldesigner:protein id="p_s_id_sa3988" name="RELA" type="GENERIC">
<celldesigner:listOfModificationResidues><celldesigner:modificationResidue id="rs1" name="S276" angle="3.8682226504929313"></celldesigner:modificationResidue><celldesigner:modificationResidue id="rs2" name="S529" angle="2.3550214342198026"></celldesigner:modificationResidue></celldesigner:listOfModificationResidues>
</celldesigner:protein>
<celldesigner:protein id="p_s_id_sa3989" name="NFKB1" type="GENERIC">
</celldesigner:protein>
<celldesigner:protein id="p_s_id_sa3987" name="NFKBIA" type="GENERIC">
<celldesigner:listOfModificationResidues><celldesigner:modificationResidue id="rs1" name="S32" angle="3.87729847927592"></celldesigner:modificationResidue><celldesigner:modificationResidue id="rs2" name="S36" angle="2.4376765858046574"></celldesigner:modificationResidue><celldesigner:modificationResidue id="rs4" angle="-1.5001322409935126E-12"></celldesigner:modificationResidue></celldesigner:listOfModificationResidues>
</celldesigner:protein>
</celldesigner:listOfProteins>
<celldesigner:listOfGenes></celldesigner:listOfGenes>
<celldesigner:listOfRNAs></celldesigner:listOfRNAs>
<celldesigner:listOfAntisenseRNAs></celldesigner:listOfAntisenseRNAs>
<celldesigner:listOfLayers><celldesigner:layer id ="1" name ="Layout annotation" locked ="false" visible ="false">
<celldesigner:listOfTexts>
<celldesigner:layerSpeciesAlias><celldesigner:layerNotes>
Inflammation Signalling
</celldesigner:layerNotes><celldesigner:paint color="FF000000"/><celldesigner:bounds x="207.16666666666606" y="142.0" w="1825.0" h="985.0"/><celldesigner:font size="11"/></celldesigner:layerSpeciesAlias>
</celldesigner:listOfTexts>
<celldesigner:listOfSquares>
</celldesigner:listOfSquares>
<celldesigner:listOfFreeLines>
</celldesigner:listOfFreeLines>
</celldesigner:layer>
</celldesigner:listOfLayers>
</celldesigner:extension>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#A_comprehensive_Parkinsons_disease_map">
<dcterms:modified rdf:parseType="Resource"></dcterms:modified>
</rdf:Description>
</rdf:RDF>
</annotation>
<listOfCompartments>
<compartment metaid="default" id="default" name="" size="1" units="volume" >
<notes><html xmlns="http://www.w3.org/1999/xhtml"><head><title/></head><body>
</body></html></notes>
<annotation>
<celldesigner:extension>
<celldesigner:name></celldesigner:name>
</celldesigner:extension>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#default">
<dcterms:modified rdf:parseType="Resource"></dcterms:modified>
</rdf:Description>
</rdf:RDF>
</annotation>
</compartment>
</listOfCompartments>
<listOfSpecies><species name="NFkappaB:IkappaB" id="s_id_csa553" metaid="s_id_csa553" initialAmount="0.0" hasOnlySubstanceUnits="false" constant="false" boundaryCondition="false" compartment="default"><annotation><celldesigner:extension><celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment><celldesigner:speciesIdentity><celldesigner:class>COMPLEX</celldesigner:class>
<celldesigner:name>NFkappaB:IkappaB</celldesigner:name>
</celldesigner:speciesIdentity>
</celldesigner:extension>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
<rdf:Description rdf:about="#s_id_csa553">
<dcterms:modified rdf:parseType="Resource"></dcterms:modified>
</rdf:Description>
</rdf:RDF>
</annotation>
</species>
</listOfSpecies>
</model></sbml>
\ No newline at end of file
......@@ -47,7 +47,7 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
/**
* Default diameter of the modification residues.
*/
protected static final int DEFAULT_MODIFICATION_DIAMETER = 15;
public static final int DEFAULT_MODIFICATION_DIAMETER = 15;
/**
* How far from the original shape should the activity border be drawn.
*/
......
......@@ -107,12 +107,12 @@ public class ElementComparator extends Comparator<Element> {
}
if (colorComparator.compare(arg0.getFillColor(), arg1.getFillColor()) != 0) {
logger.debug("Color different: " + arg0.getFillColor() + ", " + arg1.getFillColor());
logger.debug("Fill color different: " + arg0.getFillColor() + ", " + arg1.getFillColor());
return colorComparator.compare(arg0.getFillColor(), arg1.getFillColor());
}
if (colorComparator.compare(arg0.getBorderColor(), arg1.getBorderColor()) != 0) {
logger.debug("Border Color different: " + arg0.getBorderColor() + ", " + arg1.getBorderColor());
logger.debug("Border color different: " + arg0.getBorderColor() + ", " + arg1.getBorderColor());
return colorComparator.compare(arg0.getBorderColor(), arg1.getBorderColor());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment