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 a3c6131fb71fc4a557758362949f6f4a99df14dd..cb70338973c87e8f70af120bdddb1e66047d6247 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 @@ -13,7 +13,9 @@ import org.sbml.jsbml.Model; import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph; import org.sbml.jsbml.ext.layout.BoundingBox; import org.sbml.jsbml.ext.layout.Dimensions; +import org.sbml.jsbml.ext.layout.GeneralGlyph; import org.sbml.jsbml.ext.layout.Point; +import org.sbml.jsbml.ext.layout.ReferenceGlyph; import org.sbml.jsbml.ext.multi.MultiModelPlugin; import org.sbml.jsbml.ext.multi.MultiSpeciesPlugin; import org.sbml.jsbml.ext.multi.MultiSpeciesType; @@ -453,14 +455,15 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j if (isExtensionEnabled(SbmlExtension.MULTI)) { if (element instanceof SpeciesWithModificationResidue) { for (ModificationResidue mr : ((SpeciesWithModificationResidue) element).getModificationResidues()) { - org.sbml.jsbml.Species sbmlSpecies = getSbmlModel().getSpecies(speciesGlyph.getReference()); - createModificationGlyph(mr, sbmlSpecies); + createModificationGlyph(mr, speciesGlyph); } } } } - private void createModificationGlyph(ModificationResidue mr, org.sbml.jsbml.Species sbmlSpecies) { + private void createModificationGlyph(ModificationResidue mr, AbstractReferenceGlyph speciesGlyph) { + org.sbml.jsbml.Species sbmlSpecies = getSbmlModel().getSpecies(speciesGlyph.getReference()); + MultiSpeciesPlugin speciesExtension = (MultiSpeciesPlugin) sbmlSpecies.getExtension("multi"); SpeciesFeature feature = null; String featureTypeId = MultiPackageNamingUtils.getModificationFeatureId(mr); @@ -477,8 +480,11 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j } } - AbstractReferenceGlyph modificationGlyph = getLayout().createGeneralGlyph("modification_" + (idCounter++), + GeneralGlyph modificationGlyph = getLayout().createGeneralGlyph("modification_" + (idCounter++), modificationFeatureValue.getId()); + ReferenceGlyph referenceGlyph = new ReferenceGlyph("modification_reference_" + (idCounter++)); + referenceGlyph.setReference(speciesGlyph.getId()); + modificationGlyph.addReferenceGlyph(referenceGlyph); double width, height; if (mr instanceof AbstractRegionModification) { width = ((AbstractRegionModification) mr).getWidth(); 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 de9ba5546d6efadd08fa7f0165bf991a9ec28bc9..468348e3449f59a2abadc727a2f51b1a3c9125e1 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 @@ -12,6 +12,7 @@ import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph; import org.sbml.jsbml.ext.layout.CompartmentGlyph; import org.sbml.jsbml.ext.layout.GeneralGlyph; import org.sbml.jsbml.ext.layout.GraphicalObject; +import org.sbml.jsbml.ext.layout.ReferenceGlyph; import org.sbml.jsbml.ext.layout.SpeciesGlyph; import org.sbml.jsbml.ext.multi.MultiModelPlugin; import org.sbml.jsbml.ext.multi.MultiSpeciesPlugin; @@ -366,14 +367,7 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species> private void assignModificationResiduesLayout(Element element) { if (element instanceof SpeciesWithModificationResidue) { for (ModificationResidue mr : ((SpeciesWithModificationResidue) element).getModificationResidues()) { - GeneralGlyph residueGlyph = null; - for (GraphicalObject graphicalObject : getLayout().getListOfAdditionalGraphicalObjects()) { - if (graphicalObject instanceof GeneralGlyph) { - if (((GeneralGlyph) graphicalObject).getReference().equals(mr.getIdModificationResidue())) { - residueGlyph = (GeneralGlyph) graphicalObject; - } - } - } + GeneralGlyph residueGlyph = getResidueGlyphForModification(mr); if (residueGlyph != null) { if (residueGlyph.getBoundingBox() == null || residueGlyph.getBoundingBox().getDimensions() == null) { logger.warn(new ElementUtils().getElementTag(mr) + "Layout doesn't contain coordinates"); @@ -394,6 +388,26 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species> } + private GeneralGlyph getResidueGlyphForModification(ModificationResidue mr) { + GeneralGlyph residueGlyph = null; + for (GraphicalObject graphicalObject : getLayout().getListOfAdditionalGraphicalObjects()) { + if (graphicalObject instanceof GeneralGlyph) { + if (((GeneralGlyph) graphicalObject).getReference().equals(mr.getIdModificationResidue())) { + if (((GeneralGlyph) graphicalObject).getListOfReferenceGlyphs().size() > 0) { + // find a reference to the alias in layout, so we know it's the proper value + ReferenceGlyph referenceGlyph = ((GeneralGlyph) graphicalObject).getListOfReferenceGlyphs().get(0); + if (referenceGlyph.getReference().equals(mr.getSpecies().getElementId())) { + residueGlyph = (GeneralGlyph) graphicalObject; + } + } else { + residueGlyph = (GeneralGlyph) graphicalObject; + } + } + } + } + return residueGlyph; + } + private void assignCompartment(Element element, String compartmentId) { Compartment compartment = getMinervaModel().getElementByElementId(compartmentId); if (compartment == null && getLayout() != null) { diff --git a/converter-sbml/testFiles/cd_for_multi/modification_in_aliases.xml b/converter-sbml/testFiles/cd_for_multi/modification_in_aliases.xml new file mode 100644 index 0000000000000000000000000000000000000000..b2b1a3cf818f757d303ff5a8cc105aa81276c50a --- /dev/null +++ b/converter-sbml/testFiles/cd_for_multi/modification_in_aliases.xml @@ -0,0 +1,109 @@ +<?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="untitled" id="untitled"> +<annotation> +<celldesigner:extension> +<celldesigner:modelVersion>4.0</celldesigner:modelVersion> +<celldesigner:modelDisplay sizeX="600" sizeY="400"/> +<celldesigner:listOfCompartmentAliases/> +<celldesigner:listOfComplexSpeciesAliases/> +<celldesigner:listOfSpeciesAliases> +<celldesigner:speciesAlias id="sa1" species="s1"> +<celldesigner:activity>inactive</celldesigner:activity> +<celldesigner:bounds x="120.0" y="168.0" w="80.0" h="40.0"/> +<celldesigner:font size="12"/> +<celldesigner:view state="usual"/> +<celldesigner:usualView> +<celldesigner:innerPosition x="0.0" y="0.0"/> +<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="0.0" y="0.0"/> +<celldesigner:boxSize width="80.0" height="60.0"/> +<celldesigner:singleLine width="0.0"/> +<celldesigner:paint color="3fff0000" scheme="Color"/> +</celldesigner:briefView> +<celldesigner:info state="empty" angle="-1.5707963267948966"/> +</celldesigner:speciesAlias> +<celldesigner:speciesAlias id="sa3" species="s1"> +<celldesigner:activity>inactive</celldesigner:activity> +<celldesigner:bounds x="267.0" y="165.0" w="80.0" h="40.0"/> +<celldesigner:font size="12"/> +<celldesigner:view state="usual"/> +<celldesigner:usualView> +<celldesigner:innerPosition x="0.0" y="0.0"/> +<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="0.0" y="0.0"/> +<celldesigner:boxSize width="80.0" height="60.0"/> +<celldesigner:singleLine width="0.0"/> +<celldesigner:paint color="3fff0000" scheme="Color"/> +</celldesigner:briefView> +<celldesigner:info state="empty" angle="-1.5707963267948966"/> +</celldesigner:speciesAlias> +</celldesigner:listOfSpeciesAliases> +<celldesigner:listOfGroups/> +<celldesigner:listOfProteins> +<celldesigner:protein id="pr1" name="s1" type="GENERIC"> +<celldesigner:listOfModificationResidues> +<celldesigner:modificationResidue angle="3.141592653589793" id="rs1" side="none"/> +</celldesigner:listOfModificationResidues> +</celldesigner:protein> +</celldesigner:listOfProteins> +<celldesigner:listOfGenes/> +<celldesigner:listOfRNAs/> +<celldesigner:listOfAntisenseRNAs/> +<celldesigner:listOfLayers/> +<celldesigner:listOfBlockDiagrams/> +</celldesigner:extension> +</annotation> +<listOfUnitDefinitions> +<unitDefinition metaid="substance" id="substance" name="substance"> +<listOfUnits> +<unit metaid="CDMT00001" kind="mole"/> +</listOfUnits> +</unitDefinition> +<unitDefinition metaid="volume" id="volume" name="volume"> +<listOfUnits> +<unit metaid="CDMT00002" kind="litre"/> +</listOfUnits> +</unitDefinition> +<unitDefinition metaid="area" id="area" name="area"> +<listOfUnits> +<unit metaid="CDMT00003" kind="metre" exponent="2"/> +</listOfUnits> +</unitDefinition> +<unitDefinition metaid="length" id="length" name="length"> +<listOfUnits> +<unit metaid="CDMT00004" kind="metre"/> +</listOfUnits> +</unitDefinition> +<unitDefinition metaid="time" id="time" name="time"> +<listOfUnits> +<unit metaid="CDMT00005" kind="second"/> +</listOfUnits> +</unitDefinition> +</listOfUnitDefinitions> +<listOfCompartments> +<compartment metaid="default" id="default" size="1" units="volume"/> +</listOfCompartments> +<listOfSpecies> +<species metaid="s1" id="s1" name="s1" compartment="default" initialAmount="0"> +<annotation> +<celldesigner:extension> +<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment> +<celldesigner:speciesIdentity> +<celldesigner:class>PROTEIN</celldesigner:class> +<celldesigner:proteinReference>pr1</celldesigner:proteinReference> +</celldesigner:speciesIdentity> +</celldesigner:extension> +</annotation> +</species> +</listOfSpecies> +</model> +</sbml>