diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ElementAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ElementAnnotator.java index b2a6c81fa49469e9e7b698621c33bee6e8049516..9995d2be78f13e0a086fa2a27e86b5348e9f96a1 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ElementAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ElementAnnotator.java @@ -523,6 +523,11 @@ public abstract class ElementAnnotator extends CachableInterface { element.addMiriamData(md); } + protected void addMesh(BioEntity element, String value) { + MiriamData md = createMiriamData(MiriamType.MESH_2012, value); + element.addMiriamData(md); + } + protected void addChemblCompound(BioEntity element, String value) { MiriamData md = createMiriamData(MiriamType.CHEMBL_COMPOUND, value); element.addMiriamData(md); diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ReconAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ReconAnnotator.java index 320cf818c65fbbb8125cff35e8c284da46fe1b35..b41ee984effc76035b637aa4cb5a80f3b1deb11c 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ReconAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ReconAnnotator.java @@ -299,6 +299,8 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService addCas(annotatedObject, value); } else if (key.equals("chembl")) { addChemblCompound(annotatedObject, value); + } else if (key.equals("mesh_id")) { + addMesh(annotatedObject, value); } else if (key.equals("rhea")) { addRhea(annotatedObject, value); } else if (key.equals("epa_id")) { @@ -313,9 +315,33 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService } else if (key.equals("biocyc")) { // for now we don't handle it continue; + } else if (key.equals("organellemap")) { + // for now we don't handle it + continue; } else if (key.equals("fda_id")) { // for now we don't handle it continue; + } else if (key.equals("chodb_id")) { + // for now we don't handle it + continue; + } else if (key.equals("mitochondrionmap")) { + // for now we don't handle it + continue; + } else if (key.equals("nucleusmap")) { + // for now we don't handle it + continue; + } else if (key.equals("peroxisomemap")) { + // for now we don't handle it + continue; + } else if (key.equals("reticulummap")) { + // for now we don't handle it + continue; + } else if (key.equals("golgimap")) { + // for now we don't handle it + continue; + } else if (key.equals("lysosomemap")) { + // for now we don't handle it + continue; } else { unknown = true; } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerElementCollection.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerElementCollection.java index 00ea8ca9115c4b911d8bc5070739a15b48fb2d65..101fd298f92cd7b1edb951b653b13b75003a1995 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerElementCollection.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerElementCollection.java @@ -8,8 +8,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.log4j.Logger; + import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.model.map.species.AntisenseRna; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Element; @@ -27,6 +30,8 @@ import lcsb.mapviewer.model.map.species.field.ModificationResidue; */ public class CellDesignerElementCollection { + Logger logger = Logger.getLogger(CellDesignerElementCollection.class); + /** * Element by element identifier (it's CellDesigner identifier). */ @@ -238,4 +243,38 @@ public class CellDesignerElementCollection { } } + private Map<String, String> modificationResidueIdByHash = new HashMap<>(); + private Set<String> usedModificationResidueIds = new HashSet<>(); + + /** + * This method computes modificationResidueId that should be used when exporting + * modification residue to CellDesigner. The identifier relies on type and + * position on the list of modification + * + * @param region + * {@link ModificationResidue} for which we want to find out identifier + * @param number + * position on which this {@link ModificationResidue} is located in + * species + * @return identifier that can be used in CellDesigner + */ + public String getModificationResidueId(ModificationResidue region, int number) { + String hash = region.getClass().getSimpleName() + "\n" + number; + String result = modificationResidueIdByHash.get(hash); + if (result == null) { + if (!usedModificationResidueIds.contains(region.getIdModificationResidue())) { + result = region.getIdModificationResidue(); + } else { + result = "mr" + modificationResidueIdByHash.keySet().size(); + } + modificationResidueIdByHash.put(hash, result); + usedModificationResidueIds.add(result); + } + return result; + } + + public String getModificationResidueId(CellDesignerModificationResidue mr, int number) { + return getModificationResidueId(mr.createModificationResidue(new Gene("X")), number); + } + } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java index 631685017f23deda1b68c4c322817b6039265ec1..60a9e523a44bd658d76b30de7ab3e6ee9c2f2408 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParser.java @@ -61,91 +61,98 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> { String speciesId = getNodeAttr("species", aliasNode); String aliasId = getNodeAttr("id", aliasNode); + + String errorPrefix = "[" + speciesId + "," + aliasId + "]\t"; CellDesignerSpecies<?> species = elements.getElementByElementId(speciesId); if (species == null) { throw new InvalidXmlSchemaException("Unknown species for alias (speciesId: " + speciesId + ")"); } if (species instanceof CellDesignerComplexSpecies) { - logger.warn("[" + speciesId + "," + aliasId - + "]\tSpecies is defined as a complex, but alias is not a complex. Changing alias to complex."); + logger.warn( + errorPrefix + "Species is defined as a complex, but alias is not a complex. Changing alias to complex."); } elements.addElement(species, aliasId); - Species result = species.createModelElement(aliasId); - - String state = "usual"; - NodeList nodes = aliasNode.getChildNodes(); - View usualView = null; - View briefView = null; - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:activity")) { - result.setActivity(getNodeValue(node).equalsIgnoreCase("active")); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { - result.setX(getNodeAttr("X", node)); - result.setY(getNodeAttr("Y", node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:font")) { - result.setFontSize(getNodeAttr("size", node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:view")) { - state = getNodeAttr("state", node); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:usualView")) { - usualView = getCommonParser().getView(node); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:briefView")) { - briefView = getCommonParser().getView(node); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:info")) { - processAliasState(node, result); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:structuralState")) { - // not handled - continue; - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:speciesAlias: " + node.getNodeName()); + try { + Species result = species.createModelElement(aliasId); + + String state = "usual"; + NodeList nodes = aliasNode.getChildNodes(); + View usualView = null; + View briefView = null; + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:activity")) { + result.setActivity(getNodeValue(node).equalsIgnoreCase("active")); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { + result.setX(getNodeAttr("X", node)); + result.setY(getNodeAttr("Y", node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:font")) { + result.setFontSize(getNodeAttr("size", node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:view")) { + state = getNodeAttr("state", node); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:usualView")) { + usualView = getCommonParser().getView(node); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:briefView")) { + briefView = getCommonParser().getView(node); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:info")) { + processAliasState(node, result); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:structuralState")) { + // not handled + continue; + } else { + throw new InvalidXmlSchemaException( + errorPrefix + "Unknown element of celldesigner:speciesAlias: " + node.getNodeName()); + } } } - } - View view = null; - if (state.equalsIgnoreCase("usual")) { - view = usualView; - } else if (state.equalsIgnoreCase("brief")) { - view = briefView; - } + View view = null; + if (state.equalsIgnoreCase("usual")) { + view = usualView; + } else if (state.equalsIgnoreCase("brief")) { + view = briefView; + } - if (view != null) { - // inner position defines the position in compartment - // result.moveBy(view.innerPosition); - result.setWidth(view.getBoxSize().width); - result.setHeight(view.getBoxSize().height); - result.setLineWidth(view.getSingleLine().getWidth()); - result.setColor(view.getColor()); - } else { - throw new InvalidXmlSchemaException("No view in Alias"); - } - result.setState(state); - String compartmentAliasId = getNodeAttr("compartmentAlias", aliasNode); - if (!compartmentAliasId.isEmpty()) { - Compartment compartment = model.getElementByElementId(compartmentAliasId); - if (compartment == null) { - throw new InvalidXmlSchemaException("CompartmentAlias does not exist: " + compartmentAliasId); + if (view != null) { + // inner position defines the position in compartment + // result.moveBy(view.innerPosition); + result.setWidth(view.getBoxSize().width); + result.setHeight(view.getBoxSize().height); + result.setLineWidth(view.getSingleLine().getWidth()); + result.setColor(view.getColor()); } else { - result.setCompartment(compartment); - compartment.addElement(result); + throw new InvalidXmlSchemaException(errorPrefix + "No view in Alias"); } - } - String complexAliasId = getNodeAttr("complexSpeciesAlias", aliasNode); - if (!complexAliasId.isEmpty()) { - Complex complex = model.getElementByElementId(complexAliasId); - if (complex == null) { - throw new InvalidXmlSchemaException( - "ComplexAlias does not exist: " + complexAliasId + ", current: " + result.getElementId()); - } else { - result.setComplex(complex); - complex.addSpecies(result); + result.setState(state); + String compartmentAliasId = getNodeAttr("compartmentAlias", aliasNode); + if (!compartmentAliasId.isEmpty()) { + Compartment compartment = model.getElementByElementId(compartmentAliasId); + if (compartment == null) { + throw new InvalidXmlSchemaException(errorPrefix + "CompartmentAlias does not exist: " + compartmentAliasId); + } else { + result.setCompartment(compartment); + compartment.addElement(result); + } + } + String complexAliasId = getNodeAttr("complexSpeciesAlias", aliasNode); + if (!complexAliasId.isEmpty()) { + Complex complex = model.getElementByElementId(complexAliasId); + if (complex == null) { + throw new InvalidXmlSchemaException( + errorPrefix + "ComplexAlias does not exist: " + complexAliasId + ", current: " + result.getElementId()); + } else { + result.setComplex(complex); + complex.addSpecies(result); + } } - } - species.updateModelElementAfterLayoutAdded(result); - return result; + species.updateModelElementAfterLayoutAdded(result); + return result; + } catch (NotImplementedException e) { + throw new InvalidXmlSchemaException(errorPrefix + "Problem with creating species", e); + } } /** diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java index 2db1d9e5e3ea02f845d68116bb05730abfcf0028..73d7a4006ae94ec5ef5afa8a3ff5390c6c091001 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/AntisenseRnaXmlParser.java @@ -14,10 +14,7 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType; import lcsb.mapviewer.model.map.species.AntisenseRna; -import lcsb.mapviewer.model.map.species.field.CodingRegion; import lcsb.mapviewer.model.map.species.field.ModificationResidue; -import lcsb.mapviewer.model.map.species.field.ModificationSite; -import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain; /** * Class that performs parsing of the CellDesigner xml for AntisenseRna object. @@ -39,6 +36,8 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner */ private CellDesignerElementCollection elements; + private ModificationResidueXmlParser modificationResidueXmlParser; + /** * Default constructor. * @@ -48,6 +47,7 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner */ public AntisenseRnaXmlParser(CellDesignerElementCollection elements) { this.elements = elements; + this.modificationResidueXmlParser = new ModificationResidueXmlParser(elements); } @Override @@ -105,7 +105,7 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner if (antisenseRna.getRegions().size() > 0) { result += "<celldesigner:listOfRegions>"; for (ModificationResidue region : antisenseRna.getRegions()) { - result += toXml(region); + result += modificationResidueXmlParser.toXml(region); } result += "</celldesigner:listOfRegions>"; } @@ -113,45 +113,6 @@ public class AntisenseRnaXmlParser extends AbstractElementXmlParser<CellDesigner return result; } - /** - * Transforms AntisenseRnaRegion into CellDEsigner xml representation. - * - * @param region - * object to be transformed - * @return xml representation of the given region - */ - private String toXml(ModificationResidue region) { - CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(region); - - String result = ""; - String attributes = ""; - if (!region.getIdModificationResidue().equals("")) { - attributes += " id=\"" + region.getIdModificationResidue() + "\""; - } - if (!region.getName().equals("")) { - attributes += " name=\"" + escapeXml(region.getName()) + "\""; - } - String type = null; - if (region instanceof CodingRegion) { - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - type = "CodingRegion"; - } else if (region instanceof ModificationSite) { - type = "Modification Site"; - } else if (region instanceof ProteinBindingDomain) { - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - type = "proteinBindingDomain"; - } else { - throw new InvalidArgumentException("Unknown modificatin type: " + region.getClass()); - } - - attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\""; - attributes += " type=\"" + type + "\""; - result += "<celldesigner:region " + attributes + ">"; - result += "</celldesigner:region>"; - - return result; - } - /** * Method that parse xml node into AntisenseRnaRegion element. * diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java index 7e041680e5843dd51d8387cdb9998218cb368ea9..6138ac457cac1cb1e6d1f024d5bced271f34693c 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParser.java @@ -9,17 +9,12 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser; -import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerGene; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType; import lcsb.mapviewer.model.map.species.Gene; -import lcsb.mapviewer.model.map.species.field.CodingRegion; import lcsb.mapviewer.model.map.species.field.ModificationResidue; -import lcsb.mapviewer.model.map.species.field.ModificationSite; -import lcsb.mapviewer.model.map.species.field.RegulatoryRegion; -import lcsb.mapviewer.model.map.species.field.TranscriptionSite; /** * Class that performs parsing of the CellDesigner xml for @@ -42,6 +37,8 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge */ private CellDesignerElementCollection elements; + private ModificationResidueXmlParser modificationResidueXmlParser; + /** * Default constructor. Model is required because some nodes require access to * other parts of the model. @@ -52,6 +49,7 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge */ public GeneXmlParser(CellDesignerElementCollection elements) { this.elements = elements; + this.modificationResidueXmlParser = new ModificationResidueXmlParser(elements); } @Override @@ -139,7 +137,7 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge if (gene.getModificationResidues().size() > 0) { result += "<celldesigner:listOfRegions>\n"; for (ModificationResidue mr : gene.getModificationResidues()) { - result += toXml(mr); + result += modificationResidueXmlParser.toXml(mr); } result += "</celldesigner:listOfRegions>\n"; } @@ -148,51 +146,4 @@ public class GeneXmlParser extends AbstractElementXmlParser<CellDesignerGene, Ge return result; } - /** - * Generates CellDesigner xml for {@link CellDesignerModificationResidue}. - * - * @param mr - * object to transform into xml - * @return CellDesigner xml for {@link CellDesignerModificationResidue} - */ - String toXml(ModificationResidue mr) { - CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr); - - String result = ""; - String attributes = ""; - if (!mr.getIdModificationResidue().equals("")) { - attributes += " id=\"" + mr.getIdModificationResidue() + "\""; - } - if (!mr.getName().equals("")) { - attributes += " name=\"" + escapeXml(mr.getName()) + "\""; - } - String type = null; - if (mr instanceof ModificationSite) { - type = ModificationType.MODIFICATION_SITE.getCellDesignerName(); - } else if (mr instanceof RegulatoryRegion) { - type = ModificationType.REGULATORY_REGION.getCellDesignerName(); - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - } else if (mr instanceof CodingRegion) { - type = ModificationType.CODING_REGION.getCellDesignerName(); - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - } else if (mr instanceof TranscriptionSite) { - TranscriptionSite transcriptionSite = (TranscriptionSite) mr; - if (transcriptionSite.getDirection().equals("RIGHT")) { - type = ModificationType.TRANSCRIPTION_SITE_RIGHT.getCellDesignerName(); - } else { - type = ModificationType.TRANSCRIPTION_SITE_LEFT.getCellDesignerName(); - } - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - attributes += " active=\"" + transcriptionSite.getActive() + "\""; - } else { - throw new InvalidArgumentException("Don't know how to handle: " + mr.getClass()); - } - attributes += " type=\"" + type + "\""; - attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\""; - result += "<celldesigner:region " + attributes + ">"; - result += "</celldesigner:region>\n"; - - return result; - } - } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ModificationResidueXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ModificationResidueXmlParser.java new file mode 100644 index 0000000000000000000000000000000000000000..0a479691fb0cd250823ce03c844103a14e2137dc --- /dev/null +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ModificationResidueXmlParser.java @@ -0,0 +1,249 @@ +package lcsb.mapviewer.converter.model.celldesigner.species; + +import java.util.List; + +import lcsb.mapviewer.common.XmlParser; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; +import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; +import lcsb.mapviewer.converter.model.celldesigner.structure.fields.ModificationType; +import lcsb.mapviewer.model.map.species.AntisenseRna; +import lcsb.mapviewer.model.map.species.Gene; +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.model.map.species.Rna; +import lcsb.mapviewer.model.map.species.field.BindingRegion; +import lcsb.mapviewer.model.map.species.field.CodingRegion; +import lcsb.mapviewer.model.map.species.field.ModificationResidue; +import lcsb.mapviewer.model.map.species.field.ModificationSite; +import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain; +import lcsb.mapviewer.model.map.species.field.RegulatoryRegion; +import lcsb.mapviewer.model.map.species.field.Residue; +import lcsb.mapviewer.model.map.species.field.TranscriptionSite; + +public class ModificationResidueXmlParser extends XmlParser { + + private CellDesignerElementCollection elements; + + public ModificationResidueXmlParser(CellDesignerElementCollection elements) { + this.elements = elements; + } + + /** + * Transforms ModificationResidue into CellDssigner xml representation. + * + * @param region + * object to be transformed + * @return xml representation of the given region + */ + public String toXml(ModificationResidue region) { + if (region.getSpecies() instanceof AntisenseRna) { + return antisenseRnaModificationResidueToXml(region); + } else if (region.getSpecies() instanceof Gene) { + return geneModificationResidueToXml(region); + } else if (region.getSpecies() instanceof Rna) { + return rnaModificationResidueToXml(region); + } else if (region.getSpecies() instanceof Protein) { + if (region instanceof BindingRegion) { + return proteinModificationResidueToXml((BindingRegion) region); + } else if (region instanceof Residue) { + return proteinModificationResidueToXml((Residue) region); + } else { + throw new NotImplementedException("toXml not implemented for " + region); + } + } else { + throw new NotImplementedException("toXml not implemented for " + region.getSpecies()); + } + } + + private String antisenseRnaModificationResidueToXml(ModificationResidue region) { + CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(region); + + String result = ""; + String attributes = " id=\"" + computeModificationResidueId(region) + "\""; + if (!region.getName().equals("")) { + attributes += " name=\"" + escapeXml(region.getName()) + "\""; + } + String type = null; + if (region instanceof CodingRegion) { + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + type = "CodingRegion"; + } else if (region instanceof ModificationSite) { + type = "Modification Site"; + } else if (region instanceof ProteinBindingDomain) { + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + type = "proteinBindingDomain"; + } else { + throw new InvalidArgumentException("Unknown modificatin type: " + region.getClass()); + } + + attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\""; + attributes += " type=\"" + type + "\""; + result += "<celldesigner:region " + attributes + ">"; + result += "</celldesigner:region>\n"; + + return result; + } + + /** + * This method computes modificationResidueId that should be used when exporting + * modification residue to CellDesigner. It cannot be taken from data structure + * because we have to merge elements when exporting to CellDesigner and this + * might introduce inconsistent identifiers. + * + * @param region {@link ModificationResidue} for which we want to find out identifier + * @return identifier that can be used in CellDesigner + */ + private String computeModificationResidueId(ModificationResidue region) { + List<? extends ModificationResidue> modificationResidues; + if (region.getSpecies() instanceof Protein) { + modificationResidues = ((Protein) region.getSpecies()).getModificationResidues(); + } else if (region.getSpecies() instanceof Rna) { + modificationResidues = ((Rna) region.getSpecies()).getRegions(); + } else if (region.getSpecies() instanceof AntisenseRna) { + modificationResidues = ((AntisenseRna) region.getSpecies()).getRegions(); + } else if (region.getSpecies() instanceof Gene) { + modificationResidues = ((Gene) region.getSpecies()).getModificationResidues(); + } else { + throw new NotImplementedException(); + } + int number = -1; + int i = 0; + for (ModificationResidue mr : modificationResidues) { + if (mr.getIdModificationResidue().equals(region.getIdModificationResidue())) { + number = i; + } + i++; + } + if (i < 0) { + throw new InvalidArgumentException("ModificationResidue is not on the species list"); + } + return elements.getModificationResidueId(region, number); + } + + /** + * Generates CellDesigner xml for {@link CellDesignerModificationResidue}. + * + * @param mr + * object to transform into xml + * @return CellDesigner xml for {@link CellDesignerModificationResidue} + */ + String geneModificationResidueToXml(ModificationResidue mr) { + CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr); + + String result = ""; + String attributes = " id=\"" + computeModificationResidueId(mr) + "\""; + if (!mr.getName().equals("")) { + attributes += " name=\"" + escapeXml(mr.getName()) + "\""; + } + String type = null; + if (mr instanceof ModificationSite) { + type = ModificationType.MODIFICATION_SITE.getCellDesignerName(); + } else if (mr instanceof RegulatoryRegion) { + type = ModificationType.REGULATORY_REGION.getCellDesignerName(); + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + } else if (mr instanceof CodingRegion) { + type = ModificationType.CODING_REGION.getCellDesignerName(); + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + } else if (mr instanceof TranscriptionSite) { + TranscriptionSite transcriptionSite = (TranscriptionSite) mr; + if (transcriptionSite.getDirection().equals("RIGHT")) { + type = ModificationType.TRANSCRIPTION_SITE_RIGHT.getCellDesignerName(); + } else { + type = ModificationType.TRANSCRIPTION_SITE_LEFT.getCellDesignerName(); + } + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + attributes += " active=\"" + transcriptionSite.getActive() + "\""; + } else { + throw new InvalidArgumentException("Don't know how to handle: " + mr.getClass()); + } + attributes += " type=\"" + type + "\""; + attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\""; + result += "<celldesigner:region " + attributes + ">"; + result += "</celldesigner:region>\n"; + + return result; + } + + /** + * Generates CellDesigner xml for {@link Residue}. + * + * @param mr + * object to transform into xml + * @return CellDesigner xml for {@link Residue} + */ + private String proteinModificationResidueToXml(Residue mr) { + CellDesignerAliasConverter converter = new CellDesignerAliasConverter(mr.getSpecies(), false); + + String result = ""; + String attributes = " id=\"" + computeModificationResidueId(mr) + "\""; + if (!mr.getName().equals("")) { + attributes += " name=\"" + escapeXml(mr.getName()) + "\""; + } + attributes += " angle=\"" + converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()) + "\""; + result += "<celldesigner:modificationResidue " + attributes + ">"; + result += "</celldesigner:modificationResidue>"; + + return result; + } + + /** + * Generates CellDesigner xml for {@link BindingRegion}. + * + * @param mr + * object to transform into xml + * @return CellDesigner xml for {@link BindingRegion} + */ + private String proteinModificationResidueToXml(BindingRegion mr) { + + CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr); + String result = ""; + String attributes = " id=\"" + computeModificationResidueId(mr) + "\""; + if (!mr.getName().equals("")) { + attributes += " name=\"" + escapeXml(mr.getName()) + "\""; + } + attributes += " angle=\"" + cellDesignerModificationResidue.getAngle() + "\""; + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + result += "<celldesigner:bindingRegion " + attributes + ">"; + result += "</celldesigner:bindingRegion>"; + + return result; + } + + /** + * Generates CellDesigner xml for {@link CellDesignerModificationResidue}. + * + * @param mr + * object to transform into xml + * @return CellDesigner xml for {@link CellDesignerModificationResidue} + */ + String rnaModificationResidueToXml(ModificationResidue mr) { + CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr); + + String result = ""; + String attributes = " id=\"" + computeModificationResidueId(mr) + "\""; + if (!mr.getName().equals("")) { + attributes += " name=\"" + escapeXml(mr.getName()) + "\""; + } + String type = null; + if (mr instanceof ModificationSite) { + type = ModificationType.MODIFICATION_SITE.getCellDesignerName(); + } else if (mr instanceof CodingRegion) { + type = ModificationType.CODING_REGION.getCellDesignerName(); + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + } else if (mr instanceof ProteinBindingDomain) { + type = ModificationType.PROTEIN_BINDING_DOMAIN.getCellDesignerName(); + attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; + } else { + throw new InvalidArgumentException("Don't know how to handle: " + mr.getClass()); + } + attributes += " type=\"" + type + "\""; + attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\""; + result += "<celldesigner:region " + attributes + ">"; + result += "</celldesigner:region>\n"; + + return result; + } + +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java index 4f1e6d4cdc3a317b8f505dffdda898c45d3717c7..c58e513537179cbed7b670d4775734d747939721 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/ProteinXmlParser.java @@ -11,7 +11,6 @@ import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; -import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerProtein; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; @@ -43,6 +42,8 @@ public class ProteinXmlParser extends AbstractElementXmlParser<CellDesignerProte */ private CellDesignerElementCollection elements; + private ModificationResidueXmlParser modificationResidueXmlParser; + /** * Default constructor. Model is required because some nodes require access to * other parts of the model. @@ -53,6 +54,7 @@ public class ProteinXmlParser extends AbstractElementXmlParser<CellDesignerProte */ public ProteinXmlParser(CellDesignerElementCollection elements) { this.elements = elements; + this.modificationResidueXmlParser = new ModificationResidueXmlParser(elements); } @Override @@ -141,14 +143,14 @@ public class ProteinXmlParser extends AbstractElementXmlParser<CellDesignerProte if (residues.size() > 0) { result += "<celldesigner:listOfModificationResidues>"; for (Residue mr : residues) { - result += toXml(mr); + result += modificationResidueXmlParser.toXml(mr); } result += "</celldesigner:listOfModificationResidues>\n"; } if (bindingRegions.size() > 0) { result += "<celldesigner:listOfBindingRegions>"; for (BindingRegion mr : bindingRegions) { - result += toXml(mr); + result += modificationResidueXmlParser.toXml(mr); } result += "</celldesigner:listOfBindingRegions>\n"; } @@ -159,57 +161,6 @@ public class ProteinXmlParser extends AbstractElementXmlParser<CellDesignerProte return result; } - /** - * Generates CellDesigner xml for {@link Residue}. - * - * @param mr - * object to transform into xml - * @return CellDesigner xml for {@link Residue} - */ - private String toXml(Residue mr) { - CellDesignerAliasConverter converter = new CellDesignerAliasConverter(mr.getSpecies(), false); - - String result = ""; - String attributes = ""; - if (!mr.getIdModificationResidue().equals("")) { - attributes += " id=\"" + mr.getIdModificationResidue() + "\""; - } - if (!mr.getName().equals("")) { - attributes += " name=\"" + escapeXml(mr.getName()) + "\""; - } - attributes += " angle=\"" + converter.getAngleForPoint(mr.getSpecies(), mr.getPosition()) + "\""; - result += "<celldesigner:modificationResidue " + attributes + ">"; - result += "</celldesigner:modificationResidue>"; - - return result; - } - - /** - * Generates CellDesigner xml for {@link BindingRegion}. - * - * @param mr - * object to transform into xml - * @return CellDesigner xml for {@link BindingRegion} - */ - private String toXml(BindingRegion mr) { - - CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr); - String result = ""; - String attributes = ""; - if (!mr.getIdModificationResidue().equals("")) { - attributes += " id=\"" + mr.getIdModificationResidue() + "\""; - } - if (!mr.getName().equals("")) { - attributes += " name=\"" + escapeXml(mr.getName()) + "\""; - } - attributes += " angle=\"" + cellDesignerModificationResidue.getAngle() + "\""; - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - result += "<celldesigner:bindingRegion " + attributes + ">"; - result += "</celldesigner:bindingRegion>"; - - return result; - } - /** * Parses CellDesigner xml node for ModificationResidue. * diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/RnaXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/RnaXmlParser.java index 1a8561939784facaba3ff978804574de184934e5..8136f76158a210dd9573cb82572faff26397d397 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/RnaXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/RnaXmlParser.java @@ -42,6 +42,8 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> */ private CellDesignerElementCollection elements; + private ModificationResidueXmlParser modificationResidueXmlParser; + /** * Default constructor. Model is required because some nodes require access to * other parts of the model. @@ -52,6 +54,7 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> */ public RnaXmlParser(CellDesignerElementCollection elements) { this.elements = elements; + this.modificationResidueXmlParser = new ModificationResidueXmlParser(elements); } @Override @@ -134,7 +137,7 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> if (rna.getRegions().size() > 0) { result += "<celldesigner:listOfRegions>"; for (ModificationResidue mr : rna.getRegions()) { - result += toXml(mr); + result += modificationResidueXmlParser.toXml(mr); } result += "</celldesigner:listOfRegions>"; } @@ -143,42 +146,5 @@ public class RnaXmlParser extends AbstractElementXmlParser<CellDesignerRna, Rna> return result; } - /** - * Generates CellDesigner xml for {@link CellDesignerModificationResidue}. - * - * @param mr - * object to transform into xml - * @return CellDesigner xml for {@link CellDesignerModificationResidue} - */ - String toXml(ModificationResidue mr) { - CellDesignerModificationResidue cellDesignerModificationResidue = new CellDesignerModificationResidue(mr); - - String result = ""; - String attributes = ""; - if (!mr.getIdModificationResidue().equals("")) { - attributes += " id=\"" + mr.getIdModificationResidue() + "\""; - } - if (!mr.getName().equals("")) { - attributes += " name=\"" + escapeXml(mr.getName()) + "\""; - } - String type = null; - if (mr instanceof ModificationSite) { - type = ModificationType.MODIFICATION_SITE.getCellDesignerName(); - } else if (mr instanceof CodingRegion) { - type = ModificationType.CODING_REGION.getCellDesignerName(); - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - } else if (mr instanceof ProteinBindingDomain) { - type = ModificationType.PROTEIN_BINDING_DOMAIN.getCellDesignerName(); - attributes += " size=\"" + cellDesignerModificationResidue.getSize() + "\""; - } else { - throw new InvalidArgumentException("Don't know how to handle: " + mr.getClass()); - } - attributes += " type=\"" + type + "\""; - attributes += " pos=\"" + cellDesignerModificationResidue.getPos() + "\""; - result += "<celldesigner:region " + attributes + ">"; - result += "</celldesigner:region>\n"; - - return result; - } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesCollectionXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesCollectionXmlParser.java index d457a85c7ae62327e5b94dd39c9de44154a81b61..4cae4bb902d046bbb1eb21af38305a6f8e9f21a6 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesCollectionXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesCollectionXmlParser.java @@ -255,7 +255,7 @@ public class SpeciesCollectionXmlParser extends XmlParser { * * @param collection * set of proteins - * @return CellDesigner xml node corrseponding to the input + * @return CellDesigner xml node corresponding to the input */ public String proteinCollectionToXmlString(Collection<Protein> collection) { StringBuilder result = new StringBuilder(); diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java index a38a634c097cc21692fe90c3fa9b70cc4781bc78..d71e8f17a4198b25f8e4c3f6736781876975cc8f 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParser.java @@ -333,8 +333,9 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec } if (state.getModifications().size() > 0) { sb.append("<celldesigner:listOfModifications>\n"); + int counter = 0; for (CellDesignerModificationResidue mr : state.getModifications()) { - sb.append(modificationResidueToXml(mr)); + sb.append(modificationResidueToXml(mr, counter++)); } sb.append("</celldesigner:listOfModifications>\n"); } @@ -591,7 +592,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec * object to be transformed into xml * @return xml node representing param object */ - private String modificationResidueToXml(CellDesignerModificationResidue mr) { + private String modificationResidueToXml(CellDesignerModificationResidue mr, int number) { String state = ""; if (mr.getState() != null) { state = mr.getState().getFullName(); @@ -599,7 +600,7 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec if (state == null || state.equals("")) { return ""; } - return "<celldesigner:modification residue=\"" + mr.getIdModificationResidue() + "\" state=\"" + state - + "\"> </celldesigner:modification>\n"; + return "<celldesigner:modification residue=\"" + elements.getModificationResidueId(mr, number) + + "\" state=\"" + state + "\"> </celldesigner:modification>\n"; } } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ModificationTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ModificationTest.java index bacc86fe1bd0cb526203cd376f465c01c1198e43..ee6f7fe47e30253c0b68cdb31bfc97128c7cb43d 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ModificationTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ModificationTest.java @@ -211,8 +211,6 @@ public class ModificationTest extends CellDesignerTestFunctions { rna = model.getElementByElementId("sa3"); assertEquals(1, rna.getRegions().size()); assertTrue(rna.getRegions().get(0) instanceof ModificationSite); - - testXmlSerialization(model); } catch (Exception e) { e.printStackTrace(); throw e; @@ -241,8 +239,6 @@ public class ModificationTest extends CellDesignerTestFunctions { ModificationSite modificationSite = (ModificationSite) rna.getRegions().get(0); assertEquals(ModificationState.PHOSPHORYLATED, modificationSite.getState()); - testXmlSerialization(model); - } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParserTest.java index 392170407bc10f795672b65d08ba0e320cc992ef..5c194856ee777ae492bf7e3f6bf3f708737159ce 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/alias/SpeciesAliasXmlParserTest.java @@ -272,8 +272,9 @@ public class SpeciesAliasXmlParserTest extends CellDesignerTestFunctions { String xmlString = readFile("testFiles/invalid/species_alias6.xml"); parser.parseXmlAlias(xmlString); fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Unkown alias state")); + } catch (InvalidXmlSchemaException e) { + logger.debug(e.getMessage()); + assertTrue(e.getMessage().contains("Problem with creating species")); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/AllSpeciesTests.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/AllSpeciesTests.java index e55c6c43f1d33a9e9108547da3dcec8684cc30f4..96c528abf591756009243c1b049fcc1c01b5efaa 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/AllSpeciesTests.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/AllSpeciesTests.java @@ -5,16 +5,17 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ AntisenseRnaXmlParserTest.class, - ComplexParserTest.class, - GeneXmlParserTest.class, - InternalModelSpeciesDataTest.class, - ProteinMappingTest.class, - ProteinXmlParserTest.class, - RnaXmlParserTest.class, - SpeciesCollectionTest.class, - SpeciesCollectionXmlParserTest.class, - SpeciesMappingTest.class, - SpeciesSbmlParserTest.class, + ComplexParserTest.class, + GeneXmlParserTest.class, + InternalModelSpeciesDataTest.class, + ModificationResidueXmlParserTest.class, + ProteinMappingTest.class, + ProteinXmlParserTest.class, + RnaXmlParserTest.class, + SpeciesCollectionTest.class, + SpeciesCollectionXmlParserTest.class, + SpeciesMappingTest.class, + SpeciesSbmlParserTest.class, }) public class AllSpeciesTests { diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java index c4c864b485e6fd2b397d287c2db5d960f4cad2a9..ed2aa793014903e58f1e4daa7e90b4ec78e7e24d 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/GeneXmlParserTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.awt.geom.Point2D; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; @@ -26,11 +25,8 @@ import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions; import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerGene; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.species.Gene; -import lcsb.mapviewer.model.map.species.GenericProtein; -import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.ModificationState; -import lcsb.mapviewer.model.map.species.field.Residue; public class GeneXmlParserTest extends CellDesignerTestFunctions { Logger logger = Logger.getLogger(GeneXmlParserTest.class.getName()); @@ -148,24 +144,4 @@ public class GeneXmlParserTest extends CellDesignerTestFunctions { } } - @Test - public void testModificationResidueToXml() throws Exception { - try { - Gene protein = new Gene("id"); - protein.setX(10); - protein.setY(10); - protein.setWidth(10); - protein.setHeight(10); - ModificationSite mr = new ModificationSite(); - mr.setIdModificationResidue("i"); - mr.setName("a"); - mr.setPosition(new Point2D.Double(3.0, 2.0)); - mr.setSpecies(protein); - String xmlString = geneParser.toXml(mr); - assertNotNull(xmlString); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/ModificationResidueXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/ModificationResidueXmlParserTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c8450837b0a10d60aabdb92356d29d38c3c87bd6 --- /dev/null +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/ModificationResidueXmlParserTest.java @@ -0,0 +1,44 @@ +package lcsb.mapviewer.converter.model.celldesigner.species; + +import static org.junit.Assert.assertNotNull; + +import java.awt.geom.Point2D; + +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection; +import lcsb.mapviewer.model.map.species.Gene; +import lcsb.mapviewer.model.map.species.field.ModificationSite; + +public class ModificationResidueXmlParserTest { + + ModificationResidueXmlParser parser; + + @Before + public void setUp() throws Exception { + parser = new ModificationResidueXmlParser(new CellDesignerElementCollection()); + } + + @Test + public void testGeneModificationResidueToXml() throws Exception { + try { + Gene protein = new Gene("id"); + protein.setX(10); + protein.setY(10); + protein.setWidth(10); + protein.setHeight(10); + ModificationSite mr = new ModificationSite(); + mr.setIdModificationResidue("i"); + mr.setName("a"); + mr.setPosition(new Point2D.Double(3.0, 2.0)); + mr.setSpecies(protein); + String xmlString = parser.toXml(mr); + assertNotNull(xmlString); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java index 1b536d4ee9b56c9bcd04995456abea94c3786bcb..e42c08201cb52bd7f9799fa5a701f2e63dbdbe79 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.sbgn.ArcClazz; import org.sbgn.GlyphClazz; @@ -164,11 +165,11 @@ public class SbgnmlXmlExporter { for (Element element : model.getElements()) { if (element instanceof Species) { if (((Species) element).getComplex() == null) { - Glyph newGlyph = aliasToGlyph(element); + Glyph newGlyph = elementToGlyph(element); map.getGlyph().add(newGlyph); } } else if (element instanceof Compartment) { - Glyph newGlyph = aliasToGlyph(element); + Glyph newGlyph = elementToGlyph(element); map.getGlyph().add(newGlyph); } } @@ -196,53 +197,56 @@ public class SbgnmlXmlExporter { /** * Creates new glyph element with all parameters from given alias. * - * @param alias + * @param element * alias with all parameters for the glyph * @return newly created glyph */ - private Glyph aliasToGlyph(Element alias) { + private Glyph elementToGlyph(Element element) { Glyph newGlyph = new Glyph(); - boolean idIsANumber = true; - try { - Integer.parseInt(alias.getElementId().substring(0, 1)); - } catch (NumberFormatException e) { - idIsANumber = false; - } + boolean idIsANumber = StringUtils.isNumeric(element.getElementId().substring(0, 1)); if (idIsANumber) { - newGlyph.setId(RandomStringUtils.randomAlphabetic(ID_RANDOM_STRING_LENGTH).concat(alias.getElementId())); + newGlyph.setId(RandomStringUtils.randomAlphabetic(ID_RANDOM_STRING_LENGTH).concat(element.getElementId())); } else { - newGlyph.setId(alias.getElementId()); + newGlyph.setId(element.getElementId()); } - newGlyph.setClazz(getGlyphClazzFromElement(alias).getClazz()); - newGlyph.setLabel(getGlyphLabelFromAlias(alias)); + newGlyph.setClazz(getGlyphClazzFromElement(element).getClazz()); + newGlyph.setLabel(getGlyphLabelFromAlias(element)); Bbox bbox = new Bbox(); - bbox.setX(alias.getX().floatValue()); - bbox.setY(alias.getY().floatValue()); - bbox.setW(alias.getWidth().floatValue()); - bbox.setH(alias.getHeight().floatValue()); + bbox.setX(element.getX().floatValue()); + bbox.setY(element.getY().floatValue()); + bbox.setW(element.getWidth().floatValue()); + bbox.setH(element.getHeight().floatValue()); newGlyph.setBbox(bbox); - if (GlyphClazz.fromClazz(newGlyph.getClazz()).equals(GlyphClazz.MACROMOLECULE) - || GlyphClazz.fromClazz(newGlyph.getClazz()).equals(GlyphClazz.MACROMOLECULE_MULTIMER)) { - Protein protein = (Protein) alias; - for (ModificationResidue mr : protein.getModificationResidues()) { - Glyph stateVariableGlyph = parseStateVariable(mr, newGlyph); - stateVariableGlyph.setId(newGlyph.getId().concat("-").concat(stateVariableGlyph.getId())); - newGlyph.getGlyph().add(stateVariableGlyph); + if (element instanceof Species) { + Species species = (Species) element; + if (element instanceof Protein) { + Protein protein = (Protein) element; + for (ModificationResidue mr : protein.getModificationResidues()) { + Glyph stateVariableGlyph = parseStateVariable(mr); + stateVariableGlyph.setId(newGlyph.getId().concat("-").concat(stateVariableGlyph.getId())); + newGlyph.getGlyph().add(stateVariableGlyph); + } + if (protein.getStructuralState() != null && !protein.getStructuralState().isEmpty()) { + newGlyph.getGlyph().add(createStateVariableForStructuralState(protein, protein.getStructuralState())); + } } - } - Glyph unitOfInformationGlyph = getUnitOfInformationGlyph(alias); - if (unitOfInformationGlyph != null) { - newGlyph.getGlyph().add(unitOfInformationGlyph); - } + Glyph unitOfInformationGlyph = getUnitOfInformationGlyph(species); + if (unitOfInformationGlyph != null) { + newGlyph.getGlyph().add(unitOfInformationGlyph); + } - if (alias instanceof Complex) { - Complex complexAlias = (Complex) alias; - for (Species a : complexAlias.getElements()) { - Glyph childGlyph = aliasToGlyph(a); - newGlyph.getGlyph().add(childGlyph); + if (element instanceof Complex) { + Complex complex = (Complex) element; + for (Species child : complex.getElements()) { + Glyph childGlyph = elementToGlyph(child); + newGlyph.getGlyph().add(childGlyph); + } + if (complex.getStructuralState() != null && !complex.getStructuralState().isEmpty()) { + newGlyph.getGlyph().add(createStateVariableForStructuralState(complex, complex.getStructuralState())); + } } } @@ -250,6 +254,30 @@ public class SbgnmlXmlExporter { return newGlyph; } + private Glyph createStateVariableForStructuralState(Element element, String structuralState) { + Glyph glyph = new Glyph(); + glyph.setId(element.getElementId() + "-state"); + glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz()); + + Glyph.State state = new Glyph.State(); + state.setValue(structuralState); + glyph.setState(state); + + Bbox bbox = new Bbox(); + + float width = (float) (element.getWidth() - 20); + float height = 28.0f; + bbox.setH(width); + bbox.setW(height); + + bbox.setX((float) (element.getX() + 10)); + bbox.setY((float) (element.getY() - height / 2)); + + glyph.setBbox(bbox); + + return glyph; + } + /** * Creates new glyph element with all parameters from given operator. * @@ -424,11 +452,9 @@ public class SbgnmlXmlExporter { * * @param mr * {@link ModificationResidue} to be parsed - * @param parentGlyph - * parent glyph for the state variable * @return state variable glyph */ - private Glyph parseStateVariable(ModificationResidue mr, Glyph parentGlyph) { + private Glyph parseStateVariable(ModificationResidue mr) { Glyph glyph = new Glyph(); glyph.setId(mr.getIdModificationResidue()); glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz()); @@ -469,57 +495,51 @@ public class SbgnmlXmlExporter { * Returns glyph with unit of information extracted from the alias or null if no * unit of information was found. * - * @param alias - * input alias + * @param species + * input species * @return glyph with unit of information extracted from the alias or null if no * unit of information was found */ - private Glyph getUnitOfInformationGlyph(Element alias) { + private Glyph getUnitOfInformationGlyph(Species species) { Glyph uoiGlyph = null; String uoiText = ""; - if (alias instanceof Species) { - Species species = (Species) alias; - int homodir = species.getHomodimer(); - if (homodir > 1) { - uoiText = "N:".concat(Integer.toString(homodir)); - } + int homodir = species.getHomodimer(); + if (homodir > 1) { + uoiText = "N:".concat(Integer.toString(homodir)); } - if (alias instanceof TruncatedProtein) { + if (species instanceof TruncatedProtein) { if (!uoiText.equals("")) { uoiText = uoiText.concat("; "); } uoiText = uoiText.concat("ct:truncatedProtein"); } - if (alias instanceof Species) { - Species speciesAlias = (Species) alias; - if ((speciesAlias.getStateLabel() != null) && (speciesAlias.getStatePrefix() != null)) { - if (!uoiText.equals("")) { - uoiText = uoiText.concat("; "); - } - if (!speciesAlias.getStatePrefix().equals("free input")) { - uoiText = uoiText.concat(speciesAlias.getStatePrefix()).concat(":"); - } - uoiText = uoiText.concat(speciesAlias.getStateLabel()); + if ((species.getStateLabel() != null) && (species.getStatePrefix() != null)) { + if (!uoiText.equals("")) { + uoiText = uoiText.concat("; "); + } + if (!species.getStatePrefix().equals("free input")) { + uoiText = uoiText.concat(species.getStatePrefix()).concat(":"); } + uoiText = uoiText.concat(species.getStateLabel()); } if (!uoiText.contains("ct:")) { - if (alias instanceof Rna) { + if (species instanceof Rna) { if (!uoiText.equals("")) { uoiText = uoiText.concat("; "); } uoiText = uoiText.concat("ct:RNA"); } - if (alias instanceof AntisenseRna) { + if (species instanceof AntisenseRna) { if (!uoiText.equals("")) { uoiText = uoiText.concat("; "); } uoiText = uoiText.concat("ct:antisenseRNA"); } - if (alias instanceof Gene) { + if (species instanceof Gene) { if (!uoiText.equals("")) { uoiText = uoiText.concat("; "); } @@ -530,17 +550,17 @@ public class SbgnmlXmlExporter { if (!uoiText.equals("")) { uoiGlyph = new Glyph(); uoiGlyph.setClazz(GlyphClazz.UNIT_OF_INFORMATION.getClazz()); - uoiGlyph.setId(alias.getElementId().concat("uoi")); + uoiGlyph.setId(species.getElementId().concat("uoi")); Label label = new Label(); label.setText(uoiText); uoiGlyph.setLabel(label); Bbox bbox = new Bbox(); - bbox.setX((float) (alias.getX() + UNIT_OF_INFORMATION_MARGIN)); - bbox.setY((float) (alias.getY() - UNIT_OF_INFORMATION_HEIGHT / 2)); + bbox.setX((float) (species.getX() + UNIT_OF_INFORMATION_MARGIN)); + bbox.setY((float) (species.getY() - UNIT_OF_INFORMATION_HEIGHT / 2)); bbox.setH((float) UNIT_OF_INFORMATION_HEIGHT); - bbox.setW((float) (alias.getWidth() - 2 * UNIT_OF_INFORMATION_MARGIN)); + bbox.setW((float) (species.getWidth() - 2 * UNIT_OF_INFORMATION_MARGIN)); uoiGlyph.setBbox(bbox); } diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java index c38a6e2e9482a7509ab690f8e0306f6303f6a03c..7c6c5e53d52912687a33cfebb0affa922f2b66a1 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java @@ -24,10 +24,8 @@ import org.sbgn.bindings.Map; import org.sbgn.bindings.Port; import org.sbgn.bindings.Sbgn; -import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.comparator.DoubleComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.InvalidInputDataExecption; import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SpeciesConverter; @@ -180,6 +178,20 @@ public class SbgnmlXmlParser { } } + for (Element element : model.getElements()) { + if (element.getCompartment() == null) { + Compartment parent = null; + if (element instanceof Species && ((Species) element).getComplex() == null) { + parent = findParentCompartment(element, model); + } else if (element instanceof Compartment) { + parent = findParentCompartment(element, model); + } + if (parent != null) { + parent.addElement(element); + } + } + } + return model; } @@ -615,7 +627,7 @@ public class SbgnmlXmlParser { if (GlyphClazz.fromClazz(child.getClazz()).equals(GlyphClazz.STATE_VARIABLE)) { if (child.getState() == null || child.getState().getVariable() != null) { try { - parseStateVariable(child, g, newSpecies); + parseStateVariable(child, newSpecies); } catch (Exception ex) { logger.warn(ex.getMessage()); } @@ -679,8 +691,6 @@ public class SbgnmlXmlParser { if (glyph.getCompartmentRef() != null) { Glyph compartmentGlyph = (Glyph) glyph.getCompartmentRef(); parentCompartment = model.getElementByElementId(compartmentGlyph.getId()); - } else if (species.getComplex() == null) { - parentCompartment = findParentCompartment(species, model); } if (parentCompartment != null) { species.setCompartment(parentCompartment); @@ -715,9 +725,11 @@ public class SbgnmlXmlParser { nullParent.setY(0.0); Compartment parent = nullParent; for (Compartment potentialParent : model.getCompartments()) { - if (potentialParent.contains(child)) { - if (parent.getSize() > potentialParent.getSize()) { - parent = potentialParent; + if (!potentialParent.equals(child)) { + if (potentialParent.contains(child)) { + if (parent.getSize() > potentialParent.getSize()) { + parent = potentialParent; + } } } } @@ -752,7 +764,7 @@ public class SbgnmlXmlParser { // If no unit of information was found, or the cardinality is invalid, // raise exception if (multimerCardinality <= 0) { - throw new Exception( + throw new InvalidArgumentException( "No proper unit of information with multimer cardinality was found." + " Glyph: " + g.getId()); } @@ -788,18 +800,17 @@ public class SbgnmlXmlParser { * unit of information glyph from sbgn-ml file * @param speciesGlyph * glyph that the unit of information considers - * @param newSpecies + * @param species * species that the unit of information considers * @throws Exception * Exception is thrown if state variable is parsed for species other * than Protein */ - private void parseStateVariable(Glyph unitOfInformationGlyph, Glyph speciesGlyph, Species newSpecies) - throws Exception { - if (!(newSpecies instanceof Protein)) { - throw new Exception("Only macromolecule elements can have state variables."); + private void parseStateVariable(Glyph unitOfInformationGlyph, Species species) { + if (!(species instanceof Protein)) { + throw new InvalidArgumentException("Only macromolecule elements can have state variables."); } - Protein protein = (Protein) newSpecies; + Protein protein = (Protein) species; Residue mr = new Residue(); mr.setSpecies(protein); @@ -1130,7 +1141,7 @@ public class SbgnmlXmlParser { return new PhysicalStimulation(); default: logger.warn("Modifier arc of invalid class."); - throw new Exception("Wrong arc class."); + throw new InvalidArgumentException("Wrong arc class."); } } @@ -1183,7 +1194,8 @@ public class SbgnmlXmlParser { */ private void parseProcess(Process p, Model model) throws Exception { if (p.getProductArcs().isEmpty()) { - throw new Exception(p.getCentralPoint().getId() + ": The process must have at least one outgoing arc."); + throw new InvalidArgumentException( + p.getCentralPoint().getId() + ": The process must have at least one outgoing arc."); } p.setProductsPort((Port) p.getProductArcs().get(0).getSource()); for (Arc productArc : p.getProductArcs()) { @@ -1197,12 +1209,13 @@ public class SbgnmlXmlParser { } if ((p.getReagentArcs().isEmpty() && !p.isReversible()) || (p.getRevReagentArcs().isEmpty() && p.isReversible())) { - throw new Exception(p.getCentralPoint().getId() + ": The process must have at least one incoming arc."); + throw new InvalidArgumentException( + p.getCentralPoint().getId() + ": The process must have at least one incoming arc."); } Reaction reaction; if (p.getCentralPoint() == null) { - throw new Exception("Process has no central point."); + throw new InvalidArgumentException("Process has no central point."); } reaction = getReactionFromProcessGlyphClazz(p.getCentralPoint().getClazz()); reaction.setIdReaction(p.getCentralPoint().getId()); @@ -1357,7 +1370,7 @@ public class SbgnmlXmlParser { atd.setArrowType(ArrowType.NONE); break; default: - throw new Exception("Wrong arc class."); + throw new InvalidArgumentException("Wrong arc class."); } return atd.copy(); } @@ -1388,7 +1401,7 @@ public class SbgnmlXmlParser { } } if (logicOperator == null) { - throw new Exception("Missing logic operator for logic arc: " + arc.getId()); + throw new InvalidArgumentException("Missing logic operator for logic arc: " + arc.getId()); } // LogicOperator is valid for CellDesigner only if it has exactly 2 @@ -1398,7 +1411,7 @@ public class SbgnmlXmlParser { .filter(a -> tempLogicOperator.getPort().contains(a.getTarget()) && !(a.getSource() instanceof Port)) .count() == 2; if (!isCellDesignerValidLogicOperator) { - throw new Exception("Parsed operator is not valid for CellDesigner: " + logicOperator.getId()); + throw new InvalidArgumentException("Parsed operator is not valid for CellDesigner: " + logicOperator.getId()); } NodeOperator operator; @@ -1414,7 +1427,7 @@ public class SbgnmlXmlParser { "NOT gates are not implemented in the platform. Glyph: " + logicOperator.getId() + " has not been parsed."); return; default: - throw new Exception("Wrong logic operator class."); + throw new InvalidArgumentException("Wrong logic operator class."); } // Parse line from arc and operator glyph @@ -1491,7 +1504,7 @@ public class SbgnmlXmlParser { modifier = new PhysicalStimulation(); break; default: - throw new Exception("Wrong arc class."); + throw new InvalidArgumentException("Wrong arc class."); } Glyph sourceGlyph = (Glyph) logicArc.getSource(); @@ -1539,11 +1552,6 @@ public class SbgnmlXmlParser { compartment.setNamePoint(compartment.getX() + compartment.getThickness() + CONTAINER_NAME_MARGIN, compartment.getY() + compartment.getThickness() + CONTAINER_NAME_MARGIN); } - Compartment parent = findParentCompartment(compartment, model); - if (parent != null) { - compartment.setCompartment(parent); - parent.addElement(compartment); - } model.addElement(compartment); } diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java index 05fca1f6c7d59c5ad2d8092ced751872bb0ab45e..96ad2aac1d4d25538bdbc6d9c338571c56a52f07 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/CellDesignerToSbgnTest.java @@ -1,5 +1,6 @@ package lcsb.mapviewer.converter.model.sbgnml; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; @@ -17,6 +18,7 @@ import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.species.Element; +import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.modelutils.map.ElementUtils; public class CellDesignerToSbgnTest { @@ -62,8 +64,7 @@ public class CellDesignerToSbgnTest { IConverter converter = new CellDesignerXmlParser(); IConverter converter2 = new SbgnmlXmlConverter(); - Model model; - model = converter.createModel(new ConverterParams().filename("testFiles/cellDesigner/bubbles.xml")); + Model model = converter.createModel(new ConverterParams().filename("testFiles/cellDesigner/bubbles.xml")); String output = File.createTempFile("temp-sbgn-output", ".sbgn").getAbsolutePath(); converter2.exportModelToFile(model, output); @@ -107,4 +108,30 @@ public class CellDesignerToSbgnTest { } + @Test + public void testProteinState() throws Exception { + try { + IConverter converter = new CellDesignerXmlParser(); + IConverter converter2 = new SbgnmlXmlConverter(); + + Model model = converter.createModel(new ConverterParams().filename("testFiles/cellDesigner/state.xml")); + + String output = File.createTempFile("temp-sbgn-output", ".sbgn").getAbsolutePath(); + converter2.exportModelToFile(model, output); + + Model model2 = converter2.createModel(new ConverterParams().filename(output)); + + Protein protein1 = model.getElementByElementId("sa1"); + Protein protein2 = model2.getElementByElementId("sa1"); + assertEquals(protein1.getStructuralState(), protein2.getStructuralState()); + + protein1 = model.getElementByElementId("sa2"); + protein2 = model2.getElementByElementId("sa2"); + assertEquals(protein1.getStructuralState(), protein2.getStructuralState()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + } diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest.java index a6940ca9003e4793bd116d85ac473edd9d27907f..fb4d974706f1064207a86dc39b93fd065ea27e4c 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest.java @@ -29,7 +29,6 @@ import lcsb.mapviewer.converter.graphics.PngImageGenerator; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; -import lcsb.mapviewer.model.map.species.Protein; @RunWith(Parameterized.class) public class SbgnmlXmlParserTest { @@ -95,37 +94,14 @@ public class SbgnmlXmlParserTest { nig2.saveToFile(pngFilePath2); assertNotNull(model2); - // for (Reaction r : model.getReactions()) { - // logger.debug("Reaction: " + r.getIdReaction()); - // for (AbstractNode node: r.getNodes()){ - // logger.debug(node); - // for (Point2D point: node.getLine().getPoints()) - // logger.debug(point); - // } - // logger.debug("--"); - // } - // for (Reaction r : model2.getReactions()) { - // logger.debug("Reaction: " + r.getIdReaction()); - // for (AbstractNode node: r.getNodes()){ - // logger.debug(node); - // for (Point2D point: node.getLine().getPoints()) - // logger.debug(point); - // } - // logger.debug("--"); - // } - - // logger.debug(pngFilePath); - // logger.debug(pngFilePath2); ModelComparator comparator = new ModelComparator(1.0); assertEquals(0, comparator.compare(model, model2)); FileUtils.deleteDirectory(new File(dir)); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); throw e; } -// logger.debug(filePath); } } diff --git a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java index c4c7f7f03847f2a90a8d43b825cbc6c0cd5958c1..fd00fea41cba0e4b087597edf4a3563cea2b383b 100644 --- a/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java +++ b/converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java @@ -1,5 +1,7 @@ package lcsb.mapviewer.converter.model.sbgnml; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.awt.geom.Point2D; @@ -8,6 +10,11 @@ import org.apache.log4j.Logger; import org.junit.Test; import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.converter.ConverterParams; +import lcsb.mapviewer.converter.IConverter; +import lcsb.mapviewer.model.map.compartment.Compartment; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.field.Residue; @@ -33,4 +40,23 @@ public class SbgnmlXmlParserTest2 { } + @Test + public void createModelWithCompartmentsTest() throws Exception { + try { + IConverter converter = new SbgnmlXmlConverter(); + + Model model = converter + .createModel(new ConverterParams().filename("testFiles/sbgnmlParserTestFiles/sbgnmlFiles/elements_inside_compartment.xml")); + Complex complexInsideCompartment = model.getElementByElementId("csa1830"); + assertNotNull("Complex inside compartment has undefined compartment", complexInsideCompartment.getCompartment()); + Complex complexOutsideCompartment = model.getElementByElementId("csa1831"); + assertNull("Complex outside compartment has not null compartment",complexOutsideCompartment.getCompartment()); + Compartment compartment = model.getElementByElementId("ca107"); + assertNull("Top compartment has not null compartment", compartment.getCompartment()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + } diff --git a/converter-SBGNML/testFiles/cellDesigner/state.xml b/converter-SBGNML/testFiles/cellDesigner/state.xml new file mode 100644 index 0000000000000000000000000000000000000000..f894eb0fd7b824ae92b554a544c30ded67163a1e --- /dev/null +++ b/converter-SBGNML/testFiles/cellDesigner/state.xml @@ -0,0 +1,129 @@ +<?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="139.0" y="185.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="sa2" species="s2"> +<celldesigner:activity>inactive</celldesigner:activity> +<celldesigner:bounds x="305.0" y="184.0" w="80.0" h="40.0"/> +<celldesigner:font size="12"/> +<celldesigner:view state="usual"/> +<celldesigner:structuralState angle="1.5707963267948966"/> +<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:modificationResidue angle="3.04" id="rs2" name="x" side="none"/> +<celldesigner:modificationResidue angle="2.94" id="rs3" name="a" side="none"/> +<celldesigner:modificationResidue angle="5.21" id="rs4" 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> +<species metaid="s2" id="s2" 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:state> +<celldesigner:listOfStructuralStates> +<celldesigner:structuralState structuralState="xyz"/> +</celldesigner:listOfStructuralStates> +</celldesigner:state> +</celldesigner:speciesIdentity> +</celldesigner:extension> +</annotation> +</species> +</listOfSpecies> +</model> +</sbml> diff --git a/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/elements_inside_compartment.xml b/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/elements_inside_compartment.xml new file mode 100644 index 0000000000000000000000000000000000000000..03f7e28d5f2f98778f837ab3ee9fd1ce6d6477d8 --- /dev/null +++ b/converter-SBGNML/testFiles/sbgnmlParserTestFiles/sbgnmlFiles/elements_inside_compartment.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<sbgn xmlns="http://sbgn.org/libsbgn/0.2"> + <map language="process description"> + <glyph class="complex" id="csa1831"> + <label text="TFEB_SNCA"/> + <bbox w="100.0" h="120.0" x="11731.0" y="1945.0"/> + <glyph class="macromolecule" id="sa11447"> + <label text="SNCA"/> + <bbox w="80.0" h="40.0" x="11740.954" y="1998.1818"/> + <glyph class="state variable" id="sa11447-rs1"> + <bbox w="20.0" h="22.0" x="11816.603" y="2037.5337"/> + </glyph> + <glyph class="state variable" id="sa11447-rs2"> + <bbox w="20.0" h="22.0" x="11770.781" y="2038.1818"/> + </glyph> + <glyph class="state variable" id="sa11447-rs4"> + <bbox w="20.0" h="22.0" x="11780.039" y="2038.1818"/> + </glyph> + <glyph class="state variable" id="sa11447-rs5"> + <bbox w="20.0" h="22.0" x="11788.954" y="2038.1818"/> + </glyph> + <glyph class="state variable" id="sa11447-rs6"> + <bbox w="20.0" h="22.0" x="11797.8955" y="2038.1818"/> + </glyph> + </glyph> + <glyph class="macromolecule" id="sa11446"> + <label text="TFEB"/> + <bbox w="80.0" h="40.0" x="11741.704" y="1954.1818"/> + <glyph class="state variable" id="sa11446-rs1"> + <state value="P" variable="S211"/> + <bbox w="70.0" h="28.0" x="11743.253" y="1957.633"/> + </glyph> + </glyph> + </glyph> + <glyph class="complex" id="csa1830"> + <label text="TFEB_SNCA"/> + <bbox w="100.0" h="120.0" x="11505.454" y="1945.1818"/> + <glyph class="macromolecule" id="sa11445"> + <label text="SNCA"/> + <bbox w="80.0" h="40.0" x="11515.409" y="1998.3636"/> + <glyph class="state variable" id="sa11445-rs1"> + <bbox w="20.0" h="22.0" x="11591.058" y="2037.7155"/> + </glyph> + <glyph class="state variable" id="sa11445-rs2"> + <bbox w="20.0" h="22.0" x="11545.236" y="2038.3636"/> + </glyph> + <glyph class="state variable" id="sa11445-rs4"> + <bbox w="20.0" h="22.0" x="11554.494" y="2038.3636"/> + </glyph> + <glyph class="state variable" id="sa11445-rs5"> + <bbox w="20.0" h="22.0" x="11563.409" y="2038.3636"/> + </glyph> + <glyph class="state variable" id="sa11445-rs6"> + <bbox w="20.0" h="22.0" x="11572.351" y="2038.3636"/> + </glyph> + </glyph> + <glyph class="macromolecule" id="sa11444"> + <label text="TFEB"/> + <bbox w="80.0" h="40.0" x="11518.159" y="1954.3636"/> + <glyph class="state variable" id="sa11444-rs1"> + <state value="P" variable="S211"/> + <bbox w="70.0" h="28.0" x="11519.708" y="1957.815"/> + </glyph> + </glyph> + </glyph> + <glyph class="compartment" id="ca107"> + <label text="Lewy body"/> + <bbox w="194.0" h="344.0" x="11458.0" y="1921.0"/> + </glyph> + </map> +</sbgn> diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractRegionModification.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractRegionModification.java index 58ed068047f140fa34c899ecdf3c7abecd4676e7..04fe8e12a032eeb4cfce77fd9ae7aa6a366075d4 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractRegionModification.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractRegionModification.java @@ -50,8 +50,8 @@ public abstract class AbstractRegionModification extends ModificationResidue { } else { position = "Point2D[" + format.format(getPosition().getX()) + "," + format.format(getPosition().getY()) + "]"; } - String result = "[" + this.getClass().getSimpleName() + "]: " + getIdModificationResidue() + "," + getName() + "," - + getWidth() + "," + getHeight() + "," + position; + String result = "[" + this.getClass().getSimpleName() + "]: " + getName() + "," + getWidth() + "," + getHeight() + + "," + position; return result; } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractSiteModification.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractSiteModification.java index d0249cea6281efb73da01a857a48fe80c72e932d..e1b7030a96809f6e15175f516571631b5b47ecf7 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractSiteModification.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/AbstractSiteModification.java @@ -15,7 +15,7 @@ public abstract class AbstractSiteModification extends ModificationResidue { * */ private static final long serialVersionUID = 1L; - + /** * State in which this modification is. */ @@ -42,10 +42,9 @@ public abstract class AbstractSiteModification extends ModificationResidue { @Override public String toString() { DecimalFormat format = new DecimalFormat("#.##"); - String result = getIdModificationResidue() + "," + getName() + "," + getState() + ",Point2D[" - + format.format(getPosition().getX()) + "," + format.format(getPosition().getY()) + "]"; + String result = getName() + "," + getState() + ",Point2D[" + format.format(getPosition().getX()) + "," + + format.format(getPosition().getY()) + "]"; return result; } - } \ No newline at end of file