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 f2d32631948e78f156bd19f4a6230a7e527da0cb..14d80344012c7e2ba363496b5494833e79647283 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 @@ -26,6 +26,7 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.PathwayCompartment; +import lcsb.mapviewer.model.map.kinetics.SbmlUnitType; import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.species.AntisenseRna; import lcsb.mapviewer.model.map.species.Gene; @@ -44,582 +45,598 @@ import lcsb.mapviewer.model.map.species.field.PositionToCompartment; */ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpecies<?>, Species> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(SpeciesSbmlParser.class.getName()); - - /** - * Collection of {@link CellDesignerElement cell designer elements} parsed - * from xml. - */ - private CellDesignerElementCollection elements; - - /** - * Default constructor. Model is required because some nodes require access to - * other parts of the model. - * - * @param elements - * collection of {@link CellDesignerElement cell designer elements} - * parsed from xml - */ - public SpeciesSbmlParser(CellDesignerElementCollection elements) { - this.elements = elements; - } - - @Override - public Pair<String, CellDesignerSpecies<?>> parseXmlElement(Node spieciesNode) throws InvalidXmlSchemaException { - - NodeList list = spieciesNode.getChildNodes(); - - Node annotationNode = null; - Node notesNode = null; - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equals("annotation")) { - annotationNode = node; - } else if (node.getNodeName().equals("notes")) { - notesNode = node; - } else { - throw new InvalidXmlSchemaException("Unknown element of annotation " + node.getNodeName()); - } - } - } - - if (annotationNode == null) { - throw new InvalidXmlSchemaException("No annotation node in SBML/model/listOfSpecies/species"); - } - - list = annotationNode.getChildNodes(); - Node extensionNode = null; - Node rdfNode = null; - - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equals("celldesigner:extension")) { - extensionNode = node; - } else if (node.getNodeName().equals("rdf:RDF")) { - rdfNode = node; - } else { - throw new InvalidXmlSchemaException("Unknown element of annotation " + node.getNodeName()); - } - } - } - - if (extensionNode == null) { - throw new InvalidXmlSchemaException("No celldesigner:extension node in SBML/model/listOfSpecies/species/annotation"); - } - - list = extensionNode.getChildNodes(); - Node speciesIdentity = null; - Node positionToCompartment = null; - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equals("celldesigner:speciesIdentity")) { - speciesIdentity = node; - } else if (node.getNodeName().equals("celldesigner:positionToCompartment")) { - positionToCompartment = node; - } else if (node.getNodeName().equals("celldesigner:listOfCatalyzedReactions")) { - // we can ignore it - every node on the map contains information about - // itself - continue; - } else { - throw new InvalidXmlSchemaException("[" + getNodeAttr("id", spieciesNode) + "]\tUnknown element of celldesigner:extension " + node.getNodeName()); - } - } - } - - if (speciesIdentity == null) { - throw new InvalidXmlSchemaException("No celldesigner:speciesIdentity node in SBML/model/listOfSpecies/species/annotation/extension"); - } - - Pair<String, CellDesignerSpecies<?>> result = parseSpeciesIdentity(speciesIdentity); - - CellDesignerSpecies<?> species = result.getRight(); - if (positionToCompartment != null) { - PositionToCompartment position = PositionToCompartment.getByString(getNodeValue(positionToCompartment)); - if (position == null) { - throw new InvalidXmlSchemaException("Unknown position on compartment: " + getNodeValue(positionToCompartment)); - } - species.setPositionToCompartment(position); - } - - // we ignore metaid - it's useless and obstruct data model - // species.setMetaId(getNodeAttr("metaid", spieciesNode)); - species.setElementId(getNodeAttr("id", spieciesNode)); - species.setName(decodeName(getNodeAttr("name", spieciesNode))); - species.setInitialAmount(getNodeAttr("initialAmount", spieciesNode)); - species.setInitialConcentration(getNodeAttr("initialConcentration", spieciesNode)); - species.setCharge(getNodeAttr("charge", spieciesNode)); - species.setOnlySubstanceUnits(getNodeAttr("hasOnlySubstanceUnits", spieciesNode)); - - CellDesignerCompartment compartment = elements.getElementByElementId(getNodeAttr("compartment", spieciesNode)); - if (compartment != null) { - species.setParent(compartment); - } - - if (notesNode != null) { - species.setNotes(getRap().getNotes(notesNode)); - } - - if (rdfNode != null) { - XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(); - species.addMiriamData(xmlAnnotationParser.parseRdfNode(annotationNode.getChildNodes())); - } - - return result; - } - - @Override - public String toXml(Species species) { - StringBuilder builder = new StringBuilder(); - StringBuilder attributesBuilder = new StringBuilder(); - attributesBuilder.append(" name=\"" + escapeXml(encodeName(species.getName())) + "\""); - attributesBuilder.append(" id=\"" + elements.getElementId(species) + "\""); - attributesBuilder.append(" metaid=\"" + elements.getElementId(species) + "\""); - if (species.getInitialAmount() != null) { - attributesBuilder.append(" initialAmount=\"" + species.getInitialAmount() + "\""); - } - if (species.getInitialConcentration() != null) { - attributesBuilder.append(" initialConcentration=\"" + species.getInitialConcentration() + "\""); - } - if (species.getCharge() != null) { - attributesBuilder.append(" charge=\"" + species.getCharge() + "\""); - } - if (species.hasOnlySubstanceUnits() != null) { - attributesBuilder.append(" hasOnlySubstanceUnits=\"" + species.hasOnlySubstanceUnits() + "\""); - } - - Compartment comp = null; - // we have to exclude artifitial compartment aliases, becuase they aren't - // exported to CellDesigner file - if (species.getCompartment() != null && !(species.getCompartment() instanceof PathwayCompartment)) { - comp = species.getCompartment(); - } else if (species.getComplex() == null) { - ModelData modelData = species.getModelData(); - if (modelData != null) { - for (Compartment cAlias : modelData.getModel().getCompartments()) { - if (!(cAlias instanceof PathwayCompartment) && cAlias.cross(species)) { - if (comp == null) { - comp = cAlias; - } else if (comp.getSize() > cAlias.getSize()) { - comp = cAlias; - } - } - } - } - } - - if (comp != null) { - attributesBuilder.append(" compartment=\"" + elements.getElementId(comp) + "\""); - } else { - attributesBuilder.append(" compartment=\"default\""); - } - builder.append("<species " + attributesBuilder.toString() + ">"); - - if ((species.getNotes() != null && !species.getNotes().equals("")) || species.getSymbol() != null || species.getFullName() != null - || species.getSynonyms().size() > 0) { - builder.append("<notes>"); - builder.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>"); - RestAnnotationParser rap = new RestAnnotationParser(); - builder.append(rap.createAnnotationString(species)); - if (species.getNotes() != null) { - builder.append(species.getNotes()); - } - builder.append("</body></html>"); - builder.append("</notes>\n"); - } - builder.append("<annotation>"); - builder.append("<celldesigner:extension>"); - if (species.getPositionToCompartment() != null) { - builder.append("<celldesigner:positionToCompartment>" + species.getPositionToCompartment().getStringName() + "</celldesigner:positionToCompartment>"); - } - builder.append(speciesIdentityToXml(species)); - - builder.append("</celldesigner:extension>\n"); - - XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(); - builder.append(xmlAnnotationParser.dataSetToXmlString(species.getMiriamData())); - - builder.append("</annotation>\n"); - - builder.append("</species>\n"); - return builder.toString(); - } - - /** - * Creates speciesIdentity xml node for the {@link CellDesignerSpecies}. - * - * @param species - * species to be transformed into xml - * @return speciesIdentity xml node - */ - String speciesIdentityToXml(Species species) { - StringBuilder sb = new StringBuilder(); - String classType = ""; - SpeciesMapping mapping = SpeciesMapping.getMappingByModelClass(species.getClass()); - if (mapping != null) { - classType = mapping.getCellDesignerString(); - } else { - throw new InvalidArgumentException("Invalid species class type: " + species.getClass().getName()); - } - sb.append("<celldesigner:speciesIdentity>"); - sb.append("<celldesigner:class>" + classType + "</celldesigner:class>\n"); - if (species instanceof Rna) { - sb.append("<celldesigner:rnaReference>r_" + elements.getElementId(species) + "</celldesigner:rnaReference>\n"); - } else if (species instanceof Protein) { - sb.append("<celldesigner:proteinReference>p_" + elements.getElementId(species) + "</celldesigner:proteinReference>\n"); - } else if (species instanceof Gene) { - sb.append("<celldesigner:geneReference>g_" + elements.getElementId(species) + "</celldesigner:geneReference>\n"); - } else if (species instanceof AntisenseRna) { - sb.append("<celldesigner:antisensernaReference>ar_" + elements.getElementId(species) + "</celldesigner:antisensernaReference>\n"); - } - SpeciesState state = new SpeciesState(species); - sb.append(speciesStateToXml(state)); - sb.append("<celldesigner:name>" + escapeXml(encodeName(species.getName())) + "</celldesigner:name>\n"); - - Boolean hypothetical = species.getHypothetical(); - if (hypothetical != null) { - sb.append("<celldesigner:hypothetical>" + hypothetical + "</celldesigner:hypothetical>\n"); - } - - sb.append("</celldesigner:speciesIdentity>\n"); - return sb.toString(); - } - - /** - * Creates CellDesigner species state into xml node. - * - * @param state - * state of the species. - * @return CellDesigner xml node used for description of the state - */ - String speciesStateToXml(SpeciesState state) { - StringBuilder sb = new StringBuilder(); - if (state.getHomodimer() != 1) { - sb.append("<celldesigner:homodimer>" + state.getHomodimer() + "</celldesigner:homodimer>\n"); - } - if (state.getStructuralState() != null && !state.getStructuralState().equals("")) { - sb.append("<celldesigner:listOfStructuralStates>\n"); - sb.append( - "<celldesigner:structuralState structuralState=\"" + state.getStructuralState() + "\">" + state.getStructuralState() - + "</celldesigner:structuralState>"); - sb.append("</celldesigner:listOfStructuralStates>\n"); - } - if (state.getModifications().size() > 0) { - sb.append("<celldesigner:listOfModifications>\n"); - for (CellDesignerModificationResidue mr : state.getModifications()) { - sb.append(modificationResidueToXml(mr)); - } - sb.append("</celldesigner:listOfModifications>\n"); - } - if (sb.length() > 0) { - sb.insert(0, "<celldesigner:state>\n"); - sb.append("</celldesigner:state>\n"); - } - return sb.toString(); - } - - /** - * Parses CellDesigner SpeciesIdentity node into {@link CellDesignerSpecies}. - * - * @param rootNode - * xml node to parse - * @return {@link Pair} of Species retrieved from SpeciesIdentity node and - * CellDesigner identifier - * @throws InvalidXmlSchemaException - * thrown when there is a problem with xml - */ - public Pair<String, CellDesignerSpecies<?>> parseSpeciesIdentity(Node rootNode) throws InvalidXmlSchemaException { - NodeList nodes = rootNode.getChildNodes(); - CellDesignerSpecies<?> result = new CellDesignerSpecies<Species>(); - Node classNode = getNode("celldesigner:class", nodes); - if (classNode == null) { - throw new InvalidXmlSchemaException("Species node in Sbml model doesn't contain node \"celldesigner:class\"."); - } else { - String value = getNodeValue(classNode); - SpeciesMapping mapping = SpeciesMapping.getMappingByString(value); - if (mapping != null) { - result = mapping.createSpecies(result); - } else { - throw new InvalidXmlSchemaException("Species node in Sbml model is of unknown type: " + value); - } - } - String identifier = ""; - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:class")) { - continue; - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:proteinReference")) { - if (result instanceof CellDesignerProtein) { - identifier = getNodeValue(node); - } else { - throw new InvalidXmlSchemaException("Wrong class type for protein reference: " + result.getClass().getName()); - } - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:geneReference")) { - if (result instanceof CellDesignerGene) { - identifier = getNodeValue(node); - } else { - throw new InvalidXmlSchemaException("Wrong class type for gene reference: " + result.getClass().getName()); - } - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:rnaReference")) { - if (result instanceof CellDesignerRna) { - identifier = getNodeValue(node); - } else { - throw new InvalidXmlSchemaException("Wrong class type for rna reference: " + result.getClass().getName()); - } - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:antisensernaReference")) { - if (result instanceof CellDesignerAntisenseRna) { - identifier = getNodeValue(node); - } else { - throw new InvalidXmlSchemaException("Wrong class type for antisense rna reference: " + result.getClass().getName()); - } - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:hypothetical")) { - result.setHypothetical(getNodeValue(node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:name")) { - result.setName(decodeName(getNodeValue(node))); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:state")) { - SpeciesState state = parseXmlSpeciesState(node); - processStateDataInSpecies(result, state); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:speciesIdentity: " + node.getNodeName()); - } - } - - } - return new Pair<String, CellDesignerSpecies<?>>(identifier, result); - } - - /** - * Set structural state to species. StructuralState is a generic class with - * some information about the species element. - * - * @param state - * state to be set - * - * @param species - * where the data should be saved - */ - void processStateDataInSpecies(CellDesignerSpecies<?> species, SpeciesState state) { - species.setHomodimer(state.getHomodimer()); - - if (species instanceof CellDesignerComplexSpecies) { - CellDesignerComplexSpecies complex = (CellDesignerComplexSpecies) species; - complex.setStructuralState(state.getStructuralState()); - if (state.getModifications().size() != 0) { - throw new NotImplementedException("Modification not supported in Complex"); - } - } else if (species instanceof CellDesignerGene) { - CellDesignerGene gene = (CellDesignerGene) species; - if (state.getStructuralState() != null) { - throw new NotImplementedException("StructuralState not supported in Gene"); - } - for (CellDesignerModificationResidue mr : state.getModifications()) { - gene.addModificationResidue(mr); - } - } else if (species instanceof CellDesignerProtein) { - CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; - protein.setStructuralState(state.getStructuralState()); - for (CellDesignerModificationResidue mr : state.getModifications()) { - protein.addModificationResidue(mr); - } - } else if (species instanceof CellDesignerRna) { - CellDesignerRna rna = (CellDesignerRna) species; - if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { - throw new NotImplementedException("Structural state not supported in RNA"); - } - - for (CellDesignerModificationResidue mr : state.getModifications()) { - rna.addRegion(createRnaRegion(mr)); - } - } else if (species instanceof CellDesignerSimpleMolecule) { - if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { - throw new NotImplementedException("Structural state not supported in SimpleMolecule"); - } - if (state.getModifications().size() != 0) { - throw new NotImplementedException("Modification not supported in SimpleMolecule"); - } - - } else if (species instanceof CellDesignerAntisenseRna) { - CellDesignerAntisenseRna antisenseRna = (CellDesignerAntisenseRna) species; - if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { - throw new NotImplementedException("Structural state not supported in AntisenseRna"); - } - - for (CellDesignerModificationResidue mr : state.getModifications()) { - CellDesignerAntisenseRnaRegion region = createAntisenseRnaRegion(mr); - antisenseRna.addRegion(region); - } - } else { - if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { - throw new NotImplementedException("Structural state not supported in " + species.getClass().getSimpleName()); - } - if (state.getModifications().size() != 0) { - throw new NotImplementedException("Modification not supported in " + species.getClass().getSimpleName()); - } - } - - } - - /** - * Creates {@link SpeciesState} from xml node. - * - * @param stateNode - * xml node - * @return {@link SpeciesState} retrieved from xml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - private SpeciesState parseXmlSpeciesState(Node stateNode) throws InvalidXmlSchemaException { - NodeList nodes = stateNode.getChildNodes(); - SpeciesState result = new SpeciesState(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:homodimer")) { - result.setHomodimer(getNodeValue(node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:listOfStructuralStates")) { - NodeList structureNodeList = node.getChildNodes(); - for (int y = 0; y < structureNodeList.getLength(); y++) { - Node structureNode = structureNodeList.item(y); - if (structureNode.getNodeType() == Node.ELEMENT_NODE) { - if (structureNode.getNodeName().equalsIgnoreCase("celldesigner:structuralState")) { - String state = getNodeAttr("structuralState", structureNode); - result.setStructuralState(state); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfStructuralStates: " + node.getNodeName()); - } - - } - - } - - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:listOfModifications")) { - NodeList modificationNodeList = node.getChildNodes(); - for (int y = 0; y < modificationNodeList.getLength(); y++) { - Node structureNode = modificationNodeList.item(y); - if (structureNode.getNodeType() == Node.ELEMENT_NODE) { - if (structureNode.getNodeName().equalsIgnoreCase("celldesigner:modification")) { - CellDesignerModificationResidue modification = getSpeciesModification(structureNode); - - result.addModificationResidue(modification); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfModifications: " + node.getNodeName()); - } - } - } - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:state: " + node.getNodeName()); - } - } - } - return result; - } - - /** - * Creates {@link CellDesignerModificationResidue} from the apropriate xml - * node. - * - * @param rootNode - * xml node - * @return {@link CellDesignerModificationResidue} retrieved from the node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - private CellDesignerModificationResidue getSpeciesModification(Node rootNode) throws InvalidXmlSchemaException { - CellDesignerModificationResidue modification = new CellDesignerModificationResidue(); - modification.setIdModificationResidue(getNodeAttr("residue", rootNode)); - String state = getNodeAttr("state", rootNode); - if (state != null) { - ModificationState mState = ModificationState.getByName(state); - if (mState == null) { - throw new InvalidXmlSchemaException( - "[" + modification.getClass().getSimpleName() + "\t" + modification.getIdModificationResidue() + "] Unknown modification state: " + state); - } - modification.setState(mState); - } - modification.setName(getNodeAttr("name", rootNode)); - modification.setSize(getNodeAttr("size", rootNode)); - modification.setAngle(getNodeAttr("pos", rootNode)); - NodeList list = rootNode.getChildNodes(); - for (int y = 0; y < list.getLength(); y++) { - Node node = list.item(y); - if (node.getNodeType() == Node.ELEMENT_NODE) { - throw new InvalidXmlSchemaException( - "[" + modification.getClass().getSimpleName() + "\t" + modification.getIdModificationResidue() + "] Unknown element of celldesigner:modification: " - + node.getNodeName()); - } - } - return modification; - } - - /** - * Creates xml node representing {@link CellDesignerModificationResidue}. - * - * @param mr - * object to be transformed into xml - * @return xml node representing param object - */ - private String modificationResidueToXml(CellDesignerModificationResidue mr) { - String state = ""; - if (mr.getState() != null) { - state = mr.getState().getFullName(); - } - if (state == null || state.equals("")) { - return ""; - } - return "<celldesigner:modification residue=\"" + mr.getIdModificationResidue() + "\" state=\"" + state + "\"> </celldesigner:modification>\n"; - } - - /** - * Creates {@link CellDesignerAntisenseRnaRegion} from - * {@link CellDesignerModificationResidue} description. - * - * @param mr - * object from which we create {@link CellDesignerAntisenseRnaRegion} - * @return {@link CellDesignerAntisenseRnaRegion} object created from param - */ - CellDesignerAntisenseRnaRegion createAntisenseRnaRegion(CellDesignerModificationResidue mr) { - CellDesignerAntisenseRnaRegion region = new CellDesignerAntisenseRnaRegion(); - region.setIdAntisenseRnaRegion(mr.getIdModificationResidue()); - if (mr.getSize() != null) { - region.setSize(mr.getSize()); - } - region.setState(mr.getState()); - region.setName(mr.getName()); - if (mr.getAngle() != null) { - region.setPos(mr.getAngle()); - } - return region; - } - - /** - * Creates {@link CellDesignerRnaRegion} from - * {@link CellDesignerModificationResidue} description. - * - * @param mr - * object from which we create {@link CellDesignerRnaRegion} - * @return {@link CellDesignerRnaRegion} object created from param - */ - public CellDesignerRnaRegion createRnaRegion(CellDesignerModificationResidue mr) { - CellDesignerRnaRegion result = new CellDesignerRnaRegion(); - result.setIdRnaRegion(mr.getIdModificationResidue()); - if (mr.getSize() != null) { - result.setSize(mr.getSize()); - } - result.setState(mr.getState()); - result.setName(mr.getName()); - if (mr.getAngle() != null) { - result.setPos(mr.getAngle()); - } - return result; - } + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(SpeciesSbmlParser.class.getName()); + + /** + * Collection of {@link CellDesignerElement cell designer elements} parsed from + * xml. + */ + private CellDesignerElementCollection elements; + + /** + * Default constructor. Model is required because some nodes require access to + * other parts of the model. + * + * @param elements + * collection of {@link CellDesignerElement cell designer elements} + * parsed from xml + */ + public SpeciesSbmlParser(CellDesignerElementCollection elements) { + this.elements = elements; + } + + @Override + public Pair<String, CellDesignerSpecies<?>> parseXmlElement(Node spieciesNode) throws InvalidXmlSchemaException { + + NodeList list = spieciesNode.getChildNodes(); + + Node annotationNode = null; + Node notesNode = null; + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equals("annotation")) { + annotationNode = node; + } else if (node.getNodeName().equals("notes")) { + notesNode = node; + } else { + throw new InvalidXmlSchemaException("Unknown element of annotation " + node.getNodeName()); + } + } + } + + if (annotationNode == null) { + throw new InvalidXmlSchemaException("No annotation node in SBML/model/listOfSpecies/species"); + } + + list = annotationNode.getChildNodes(); + Node extensionNode = null; + Node rdfNode = null; + + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equals("celldesigner:extension")) { + extensionNode = node; + } else if (node.getNodeName().equals("rdf:RDF")) { + rdfNode = node; + } else { + throw new InvalidXmlSchemaException("Unknown element of annotation " + node.getNodeName()); + } + } + } + + if (extensionNode == null) { + throw new InvalidXmlSchemaException( + "No celldesigner:extension node in SBML/model/listOfSpecies/species/annotation"); + } + + list = extensionNode.getChildNodes(); + Node speciesIdentity = null; + Node positionToCompartment = null; + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equals("celldesigner:speciesIdentity")) { + speciesIdentity = node; + } else if (node.getNodeName().equals("celldesigner:positionToCompartment")) { + positionToCompartment = node; + } else if (node.getNodeName().equals("celldesigner:listOfCatalyzedReactions")) { + // we can ignore it - every node on the map contains information about + // itself + continue; + } else { + throw new InvalidXmlSchemaException("[" + getNodeAttr("id", spieciesNode) + + "]\tUnknown element of celldesigner:extension " + node.getNodeName()); + } + } + } + + if (speciesIdentity == null) { + throw new InvalidXmlSchemaException( + "No celldesigner:speciesIdentity node in SBML/model/listOfSpecies/species/annotation/extension"); + } + + Pair<String, CellDesignerSpecies<?>> result = parseSpeciesIdentity(speciesIdentity); + + CellDesignerSpecies<?> species = result.getRight(); + if (positionToCompartment != null) { + PositionToCompartment position = PositionToCompartment.getByString(getNodeValue(positionToCompartment)); + if (position == null) { + throw new InvalidXmlSchemaException("Unknown position on compartment: " + getNodeValue(positionToCompartment)); + } + species.setPositionToCompartment(position); + } + + // we ignore metaid - it's useless and obstruct data model + // species.setMetaId(getNodeAttr("metaid", spieciesNode)); + species.setElementId(getNodeAttr("id", spieciesNode)); + species.setName(decodeName(getNodeAttr("name", spieciesNode))); + species.setInitialAmount(getNodeAttr("initialAmount", spieciesNode)); + String substanceUnits = getNodeAttr("substanceUnits", spieciesNode); + if (substanceUnits != null && !substanceUnits.isEmpty()) { + species.setSubstanceUnits(SbmlUnitType.valueOf(substanceUnits.toUpperCase())); + } + species.setInitialAmount(getNodeAttr("initialAmount", spieciesNode)); + species.setInitialConcentration(getNodeAttr("initialConcentration", spieciesNode)); + species.setCharge(getNodeAttr("charge", spieciesNode)); + species.setOnlySubstanceUnits(getNodeAttr("hasOnlySubstanceUnits", spieciesNode)); + species.setBoundaryCondition(getNodeAttr("boundaryCondition", spieciesNode)); + species.setConstant(getNodeAttr("constant", spieciesNode)); + + CellDesignerCompartment compartment = elements.getElementByElementId(getNodeAttr("compartment", spieciesNode)); + if (compartment != null) { + species.setParent(compartment); + } + + if (notesNode != null) { + species.setNotes(getRap().getNotes(notesNode)); + } + + if (rdfNode != null) { + XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(); + species.addMiriamData(xmlAnnotationParser.parseRdfNode(annotationNode.getChildNodes())); + } + + return result; + } + + @Override + public String toXml(Species species) { + StringBuilder builder = new StringBuilder(); + StringBuilder attributesBuilder = new StringBuilder(); + attributesBuilder.append(" name=\"" + escapeXml(encodeName(species.getName())) + "\""); + attributesBuilder.append(" id=\"" + elements.getElementId(species) + "\""); + attributesBuilder.append(" metaid=\"" + elements.getElementId(species) + "\""); + if (species.getInitialAmount() != null) { + attributesBuilder.append(" initialAmount=\"" + species.getInitialAmount() + "\""); + } + if (species.getInitialConcentration() != null) { + attributesBuilder.append(" initialConcentration=\"" + species.getInitialConcentration() + "\""); + } + if (species.getCharge() != null) { + attributesBuilder.append(" charge=\"" + species.getCharge() + "\""); + } + if (species.hasOnlySubstanceUnits() != null) { + attributesBuilder.append(" hasOnlySubstanceUnits=\"" + species.hasOnlySubstanceUnits() + "\""); + } + + Compartment comp = null; + // we have to exclude artifitial compartment aliases, becuase they aren't + // exported to CellDesigner file + if (species.getCompartment() != null && !(species.getCompartment() instanceof PathwayCompartment)) { + comp = species.getCompartment(); + } else if (species.getComplex() == null) { + ModelData modelData = species.getModelData(); + if (modelData != null) { + for (Compartment cAlias : modelData.getModel().getCompartments()) { + if (!(cAlias instanceof PathwayCompartment) && cAlias.cross(species)) { + if (comp == null) { + comp = cAlias; + } else if (comp.getSize() > cAlias.getSize()) { + comp = cAlias; + } + } + } + } + } + + if (comp != null) { + attributesBuilder.append(" compartment=\"" + elements.getElementId(comp) + "\""); + } else { + attributesBuilder.append(" compartment=\"default\""); + } + builder.append("<species " + attributesBuilder.toString() + ">"); + + if ((species.getNotes() != null && !species.getNotes().equals("")) || species.getSymbol() != null + || species.getFullName() != null || species.getSynonyms().size() > 0) { + builder.append("<notes>"); + builder.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title/></head><body>"); + RestAnnotationParser rap = new RestAnnotationParser(); + builder.append(rap.createAnnotationString(species)); + if (species.getNotes() != null) { + builder.append(species.getNotes()); + } + builder.append("</body></html>"); + builder.append("</notes>\n"); + } + builder.append("<annotation>"); + builder.append("<celldesigner:extension>"); + if (species.getPositionToCompartment() != null) { + builder.append("<celldesigner:positionToCompartment>" + species.getPositionToCompartment().getStringName() + + "</celldesigner:positionToCompartment>"); + } + builder.append(speciesIdentityToXml(species)); + + builder.append("</celldesigner:extension>\n"); + + XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(); + builder.append(xmlAnnotationParser.dataSetToXmlString(species.getMiriamData())); + + builder.append("</annotation>\n"); + + builder.append("</species>\n"); + return builder.toString(); + } + + /** + * Creates speciesIdentity xml node for the {@link CellDesignerSpecies}. + * + * @param species + * species to be transformed into xml + * @return speciesIdentity xml node + */ + String speciesIdentityToXml(Species species) { + StringBuilder sb = new StringBuilder(); + String classType = ""; + SpeciesMapping mapping = SpeciesMapping.getMappingByModelClass(species.getClass()); + if (mapping != null) { + classType = mapping.getCellDesignerString(); + } else { + throw new InvalidArgumentException("Invalid species class type: " + species.getClass().getName()); + } + sb.append("<celldesigner:speciesIdentity>"); + sb.append("<celldesigner:class>" + classType + "</celldesigner:class>\n"); + if (species instanceof Rna) { + sb.append("<celldesigner:rnaReference>r_" + elements.getElementId(species) + "</celldesigner:rnaReference>\n"); + } else if (species instanceof Protein) { + sb.append( + "<celldesigner:proteinReference>p_" + elements.getElementId(species) + "</celldesigner:proteinReference>\n"); + } else if (species instanceof Gene) { + sb.append("<celldesigner:geneReference>g_" + elements.getElementId(species) + "</celldesigner:geneReference>\n"); + } else if (species instanceof AntisenseRna) { + sb.append("<celldesigner:antisensernaReference>ar_" + elements.getElementId(species) + + "</celldesigner:antisensernaReference>\n"); + } + SpeciesState state = new SpeciesState(species); + sb.append(speciesStateToXml(state)); + sb.append("<celldesigner:name>" + escapeXml(encodeName(species.getName())) + "</celldesigner:name>\n"); + + Boolean hypothetical = species.getHypothetical(); + if (hypothetical != null) { + sb.append("<celldesigner:hypothetical>" + hypothetical + "</celldesigner:hypothetical>\n"); + } + + sb.append("</celldesigner:speciesIdentity>\n"); + return sb.toString(); + } + + /** + * Creates CellDesigner species state into xml node. + * + * @param state + * state of the species. + * @return CellDesigner xml node used for description of the state + */ + String speciesStateToXml(SpeciesState state) { + StringBuilder sb = new StringBuilder(); + if (state.getHomodimer() != 1) { + sb.append("<celldesigner:homodimer>" + state.getHomodimer() + "</celldesigner:homodimer>\n"); + } + if (state.getStructuralState() != null && !state.getStructuralState().equals("")) { + sb.append("<celldesigner:listOfStructuralStates>\n"); + sb.append("<celldesigner:structuralState structuralState=\"" + state.getStructuralState() + "\">" + + state.getStructuralState() + "</celldesigner:structuralState>"); + sb.append("</celldesigner:listOfStructuralStates>\n"); + } + if (state.getModifications().size() > 0) { + sb.append("<celldesigner:listOfModifications>\n"); + for (CellDesignerModificationResidue mr : state.getModifications()) { + sb.append(modificationResidueToXml(mr)); + } + sb.append("</celldesigner:listOfModifications>\n"); + } + if (sb.length() > 0) { + sb.insert(0, "<celldesigner:state>\n"); + sb.append("</celldesigner:state>\n"); + } + return sb.toString(); + } + + /** + * Parses CellDesigner SpeciesIdentity node into {@link CellDesignerSpecies}. + * + * @param rootNode + * xml node to parse + * @return {@link Pair} of Species retrieved from SpeciesIdentity node and + * CellDesigner identifier + * @throws InvalidXmlSchemaException + * thrown when there is a problem with xml + */ + public Pair<String, CellDesignerSpecies<?>> parseSpeciesIdentity(Node rootNode) throws InvalidXmlSchemaException { + NodeList nodes = rootNode.getChildNodes(); + CellDesignerSpecies<?> result = new CellDesignerSpecies<Species>(); + Node classNode = getNode("celldesigner:class", nodes); + if (classNode == null) { + throw new InvalidXmlSchemaException("Species node in Sbml model doesn't contain node \"celldesigner:class\"."); + } else { + String value = getNodeValue(classNode); + SpeciesMapping mapping = SpeciesMapping.getMappingByString(value); + if (mapping != null) { + result = mapping.createSpecies(result); + } else { + throw new InvalidXmlSchemaException("Species node in Sbml model is of unknown type: " + value); + } + } + String identifier = ""; + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:class")) { + continue; + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:proteinReference")) { + if (result instanceof CellDesignerProtein) { + identifier = getNodeValue(node); + } else { + throw new InvalidXmlSchemaException( + "Wrong class type for protein reference: " + result.getClass().getName()); + } + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:geneReference")) { + if (result instanceof CellDesignerGene) { + identifier = getNodeValue(node); + } else { + throw new InvalidXmlSchemaException("Wrong class type for gene reference: " + result.getClass().getName()); + } + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:rnaReference")) { + if (result instanceof CellDesignerRna) { + identifier = getNodeValue(node); + } else { + throw new InvalidXmlSchemaException("Wrong class type for rna reference: " + result.getClass().getName()); + } + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:antisensernaReference")) { + if (result instanceof CellDesignerAntisenseRna) { + identifier = getNodeValue(node); + } else { + throw new InvalidXmlSchemaException( + "Wrong class type for antisense rna reference: " + result.getClass().getName()); + } + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:hypothetical")) { + result.setHypothetical(getNodeValue(node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:name")) { + result.setName(decodeName(getNodeValue(node))); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:state")) { + SpeciesState state = parseXmlSpeciesState(node); + processStateDataInSpecies(result, state); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:speciesIdentity: " + node.getNodeName()); + } + } + + } + return new Pair<String, CellDesignerSpecies<?>>(identifier, result); + } + + /** + * Set structural state to species. StructuralState is a generic class with some + * information about the species element. + * + * @param state + * state to be set + * + * @param species + * where the data should be saved + */ + void processStateDataInSpecies(CellDesignerSpecies<?> species, SpeciesState state) { + species.setHomodimer(state.getHomodimer()); + + if (species instanceof CellDesignerComplexSpecies) { + CellDesignerComplexSpecies complex = (CellDesignerComplexSpecies) species; + complex.setStructuralState(state.getStructuralState()); + if (state.getModifications().size() != 0) { + throw new NotImplementedException("Modification not supported in Complex"); + } + } else if (species instanceof CellDesignerGene) { + CellDesignerGene gene = (CellDesignerGene) species; + if (state.getStructuralState() != null) { + throw new NotImplementedException("StructuralState not supported in Gene"); + } + for (CellDesignerModificationResidue mr : state.getModifications()) { + gene.addModificationResidue(mr); + } + } else if (species instanceof CellDesignerProtein) { + CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; + protein.setStructuralState(state.getStructuralState()); + for (CellDesignerModificationResidue mr : state.getModifications()) { + protein.addModificationResidue(mr); + } + } else if (species instanceof CellDesignerRna) { + CellDesignerRna rna = (CellDesignerRna) species; + if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { + throw new NotImplementedException("Structural state not supported in RNA"); + } + + for (CellDesignerModificationResidue mr : state.getModifications()) { + rna.addRegion(createRnaRegion(mr)); + } + } else if (species instanceof CellDesignerSimpleMolecule) { + if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { + throw new NotImplementedException("Structural state not supported in SimpleMolecule"); + } + if (state.getModifications().size() != 0) { + throw new NotImplementedException("Modification not supported in SimpleMolecule"); + } + + } else if (species instanceof CellDesignerAntisenseRna) { + CellDesignerAntisenseRna antisenseRna = (CellDesignerAntisenseRna) species; + if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { + throw new NotImplementedException("Structural state not supported in AntisenseRna"); + } + + for (CellDesignerModificationResidue mr : state.getModifications()) { + CellDesignerAntisenseRnaRegion region = createAntisenseRnaRegion(mr); + antisenseRna.addRegion(region); + } + } else { + if (state.getStructuralState() != null && !state.getStructuralState().isEmpty()) { + throw new NotImplementedException("Structural state not supported in " + species.getClass().getSimpleName()); + } + if (state.getModifications().size() != 0) { + throw new NotImplementedException("Modification not supported in " + species.getClass().getSimpleName()); + } + } + + } + + /** + * Creates {@link SpeciesState} from xml node. + * + * @param stateNode + * xml node + * @return {@link SpeciesState} retrieved from xml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + private SpeciesState parseXmlSpeciesState(Node stateNode) throws InvalidXmlSchemaException { + NodeList nodes = stateNode.getChildNodes(); + SpeciesState result = new SpeciesState(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:homodimer")) { + result.setHomodimer(getNodeValue(node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:listOfStructuralStates")) { + NodeList structureNodeList = node.getChildNodes(); + for (int y = 0; y < structureNodeList.getLength(); y++) { + Node structureNode = structureNodeList.item(y); + if (structureNode.getNodeType() == Node.ELEMENT_NODE) { + if (structureNode.getNodeName().equalsIgnoreCase("celldesigner:structuralState")) { + String state = getNodeAttr("structuralState", structureNode); + result.setStructuralState(state); + } else { + throw new InvalidXmlSchemaException( + "Unknown element of celldesigner:listOfStructuralStates: " + node.getNodeName()); + } + + } + + } + + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:listOfModifications")) { + NodeList modificationNodeList = node.getChildNodes(); + for (int y = 0; y < modificationNodeList.getLength(); y++) { + Node structureNode = modificationNodeList.item(y); + if (structureNode.getNodeType() == Node.ELEMENT_NODE) { + if (structureNode.getNodeName().equalsIgnoreCase("celldesigner:modification")) { + CellDesignerModificationResidue modification = getSpeciesModification(structureNode); + + result.addModificationResidue(modification); + } else { + throw new InvalidXmlSchemaException( + "Unknown element of celldesigner:listOfModifications: " + node.getNodeName()); + } + } + } + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:state: " + node.getNodeName()); + } + } + } + return result; + } + + /** + * Creates {@link CellDesignerModificationResidue} from the apropriate xml node. + * + * @param rootNode + * xml node + * @return {@link CellDesignerModificationResidue} retrieved from the node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + private CellDesignerModificationResidue getSpeciesModification(Node rootNode) throws InvalidXmlSchemaException { + CellDesignerModificationResidue modification = new CellDesignerModificationResidue(); + modification.setIdModificationResidue(getNodeAttr("residue", rootNode)); + String state = getNodeAttr("state", rootNode); + if (state != null) { + ModificationState mState = ModificationState.getByName(state); + if (mState == null) { + throw new InvalidXmlSchemaException("[" + modification.getClass().getSimpleName() + "\t" + + modification.getIdModificationResidue() + "] Unknown modification state: " + state); + } + modification.setState(mState); + } + modification.setName(getNodeAttr("name", rootNode)); + modification.setSize(getNodeAttr("size", rootNode)); + modification.setAngle(getNodeAttr("pos", rootNode)); + NodeList list = rootNode.getChildNodes(); + for (int y = 0; y < list.getLength(); y++) { + Node node = list.item(y); + if (node.getNodeType() == Node.ELEMENT_NODE) { + throw new InvalidXmlSchemaException( + "[" + modification.getClass().getSimpleName() + "\t" + modification.getIdModificationResidue() + + "] Unknown element of celldesigner:modification: " + node.getNodeName()); + } + } + return modification; + } + + /** + * Creates xml node representing {@link CellDesignerModificationResidue}. + * + * @param mr + * object to be transformed into xml + * @return xml node representing param object + */ + private String modificationResidueToXml(CellDesignerModificationResidue mr) { + String state = ""; + if (mr.getState() != null) { + state = mr.getState().getFullName(); + } + if (state == null || state.equals("")) { + return ""; + } + return "<celldesigner:modification residue=\"" + mr.getIdModificationResidue() + "\" state=\"" + state + + "\"> </celldesigner:modification>\n"; + } + + /** + * Creates {@link CellDesignerAntisenseRnaRegion} from + * {@link CellDesignerModificationResidue} description. + * + * @param mr + * object from which we create {@link CellDesignerAntisenseRnaRegion} + * @return {@link CellDesignerAntisenseRnaRegion} object created from param + */ + CellDesignerAntisenseRnaRegion createAntisenseRnaRegion(CellDesignerModificationResidue mr) { + CellDesignerAntisenseRnaRegion region = new CellDesignerAntisenseRnaRegion(); + region.setIdAntisenseRnaRegion(mr.getIdModificationResidue()); + if (mr.getSize() != null) { + region.setSize(mr.getSize()); + } + region.setState(mr.getState()); + region.setName(mr.getName()); + if (mr.getAngle() != null) { + region.setPos(mr.getAngle()); + } + return region; + } + + /** + * Creates {@link CellDesignerRnaRegion} from + * {@link CellDesignerModificationResidue} description. + * + * @param mr + * object from which we create {@link CellDesignerRnaRegion} + * @return {@link CellDesignerRnaRegion} object created from param + */ + public CellDesignerRnaRegion createRnaRegion(CellDesignerModificationResidue mr) { + CellDesignerRnaRegion result = new CellDesignerRnaRegion(); + result.setIdRnaRegion(mr.getIdModificationResidue()); + if (mr.getSize() != null) { + result.setSize(mr.getSize()); + } + result.setState(mr.getState()); + result.setName(mr.getName()); + if (mr.getAngle() != null) { + result.setPos(mr.getAngle()); + } + return result; + } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGenericProtein.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGenericProtein.java index 84bca8ce5c144fab25ec3f04e390c4ad3f494166..a7625eefba91483854df0fb927b5eb844ab9cb49 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGenericProtein.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerGenericProtein.java @@ -13,60 +13,59 @@ import lcsb.mapviewer.model.map.species.GenericProtein; */ public class CellDesignerGenericProtein extends CellDesignerProtein<GenericProtein> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private transient Logger logger = Logger.getLogger(CellDesignerGenericProtein.class); + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private transient Logger logger = Logger.getLogger(CellDesignerGenericProtein.class); - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 1L; - /** - * Default constructor. - */ - public CellDesignerGenericProtein() { - super(); - } + /** + * Default constructor. + */ + public CellDesignerGenericProtein() { + super(); + } - /** - * Constructor that creates a copy of species. - * - * @param species - * original species - */ - public CellDesignerGenericProtein(CellDesignerSpecies<?> species) { - super(species); - } + /** + * Constructor that creates a copy of species. + * + * @param species + * original species + */ + public CellDesignerGenericProtein(CellDesignerSpecies<?> species) { + super(species); + } - /** - * Deafult constructor. - * - * @param id - * identifier of the protein - */ - public CellDesignerGenericProtein(String id) { - setElementId(id); - setName(id); - } + /** + * Default constructor. + * + * @param id + * identifier of the protein + */ + public CellDesignerGenericProtein(String id) { + setElementId(id); + setName(id); + } - @Override - public CellDesignerGenericProtein copy() { - if (this.getClass().equals(CellDesignerGenericProtein.class)) { - return new CellDesignerGenericProtein(this); - } else { - throw new NotImplementedException("Copy method for " + this.getClass() + " class not implemented"); - } - } + @Override + public CellDesignerGenericProtein copy() { + if (this.getClass().equals(CellDesignerGenericProtein.class)) { + return new CellDesignerGenericProtein(this); + } else { + throw new NotImplementedException("Copy method for " + this.getClass() + " class not implemented"); + } + } - @Override - public GenericProtein createModelElement(String aliasId) { - GenericProtein result = new GenericProtein(aliasId); - super.setModelObjectFields(result); - - return result; - } + @Override + public GenericProtein createModelElement(String aliasId) { + GenericProtein result = new GenericProtein(aliasId); + super.setModelObjectFields(result); + return result; + } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java index d94a1dc5381972c8515bccb8a85325e9e152da04..ae3677e954e3caf411d5af7276fedbabf42cfaf8 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerProtein.java @@ -18,136 +18,136 @@ import lcsb.mapviewer.model.map.species.Protein; * */ public class CellDesignerProtein<T extends Protein> extends CellDesignerSpecies<T> { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(CellDesignerProtein.class.getName()); - - /** - * State of the protein. - */ - private String structuralState = null; - - /** - * List of modifications for the Protein. - */ - private List<CellDesignerModificationResidue> modificationResidues = new ArrayList<CellDesignerModificationResidue>(); - - /** - * Constructor that initializes protein with the data passed in the argument. - * - * @param species - * original species used for data initialization - */ - public CellDesignerProtein(CellDesignerSpecies<?> species) { - super(species); - if (species instanceof CellDesignerProtein) { - CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; - if (protein.getStructuralState() != null) { - setStructuralState(new String(protein.getStructuralState())); - } - for (CellDesignerModificationResidue mr : protein.getModificationResidues()) { - addModificationResidue(new CellDesignerModificationResidue(mr)); - } - } - } - - @Override - public void update(CellDesignerSpecies<?> species) { - super.update(species); - if (species instanceof CellDesignerProtein) { - CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; - if (getStructuralState() == null || getStructuralState().equals("")) { - setStructuralState(protein.getStructuralState()); - } - for (CellDesignerModificationResidue mr : protein.getModificationResidues()) { - addModificationResidue(mr); - } - } - } - - /** - * Default constructor. - */ - public CellDesignerProtein() { - super(); - } - - @Override - public CellDesignerProtein<T> copy() { - if (this.getClass().equals(CellDesignerProtein.class)) { - return new CellDesignerProtein<T>(this); - } else { - throw new NotImplementedException("Copy method for " + this.getClass() + " class not implemented"); - } - } - - /** - * Adds modification to the protein. - * - * @param modificationResidue - * modification to add - */ - public void addModificationResidue(CellDesignerModificationResidue modificationResidue) { - for (CellDesignerModificationResidue mr : modificationResidues) { - if (mr.getIdModificationResidue().equals(modificationResidue.getIdModificationResidue())) { - mr.update(modificationResidue); - return; - } - } - modificationResidues.add(modificationResidue); - modificationResidue.setSpecies(this); - } - - /** - * @return the structuralState - * @see #structuralState - */ - public String getStructuralState() { - return structuralState; - } - - /** - * @param structuralState - * the structuralState to set - * @see #structuralState - */ - public void setStructuralState(String structuralState) { - if (this.structuralState != null && !this.structuralState.equals("") && !this.structuralState.equals(structuralState)) { - logger.warn("replacing structural state, Old: " + this.structuralState + " into new: " + structuralState); - } - this.structuralState = structuralState; - } - - /** - * @return the modificationResidues - * @see #modificationResidues - */ - public List<CellDesignerModificationResidue> getModificationResidues() { - return modificationResidues; - } - - /** - * @param modificationResidues - * the modificationResidues to set - * @see #modificationResidues - */ - public void setModificationResidues(List<CellDesignerModificationResidue> modificationResidues) { - this.modificationResidues = modificationResidues; - } - - @Override - protected void setModelObjectFields(T result) { - super.setModelObjectFields(result); - result.setStructuralState(structuralState); - for (CellDesignerModificationResidue mr : modificationResidues) { - result.addModificationResidue(mr.createModificationResidueAlias()); - } - } - + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(CellDesignerProtein.class.getName()); + + /** + * State of the protein. + */ + private String structuralState = null; + + /** + * List of modifications for the Protein. + */ + private List<CellDesignerModificationResidue> modificationResidues = new ArrayList<CellDesignerModificationResidue>(); + + /** + * Constructor that initializes protein with the data passed in the argument. + * + * @param species + * original species used for data initialization + */ + public CellDesignerProtein(CellDesignerSpecies<?> species) { + super(species); + if (species instanceof CellDesignerProtein) { + CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; + if (protein.getStructuralState() != null) { + setStructuralState(new String(protein.getStructuralState())); + } + for (CellDesignerModificationResidue mr : protein.getModificationResidues()) { + addModificationResidue(new CellDesignerModificationResidue(mr)); + } + } + } + + @Override + public void update(CellDesignerSpecies<?> species) { + super.update(species); + if (species instanceof CellDesignerProtein) { + CellDesignerProtein<?> protein = (CellDesignerProtein<?>) species; + if (getStructuralState() == null || getStructuralState().equals("")) { + setStructuralState(protein.getStructuralState()); + } + for (CellDesignerModificationResidue mr : protein.getModificationResidues()) { + addModificationResidue(mr); + } + } + } + + /** + * Default constructor. + */ + public CellDesignerProtein() { + super(); + } + + @Override + public CellDesignerProtein<T> copy() { + if (this.getClass().equals(CellDesignerProtein.class)) { + return new CellDesignerProtein<T>(this); + } else { + throw new NotImplementedException("Copy method for " + this.getClass() + " class not implemented"); + } + } + + /** + * Adds modification to the protein. + * + * @param modificationResidue + * modification to add + */ + public void addModificationResidue(CellDesignerModificationResidue modificationResidue) { + for (CellDesignerModificationResidue mr : modificationResidues) { + if (mr.getIdModificationResidue().equals(modificationResidue.getIdModificationResidue())) { + mr.update(modificationResidue); + return; + } + } + modificationResidues.add(modificationResidue); + modificationResidue.setSpecies(this); + } + + /** + * @return the structuralState + * @see #structuralState + */ + public String getStructuralState() { + return structuralState; + } + + /** + * @param structuralState + * the structuralState to set + * @see #structuralState + */ + public void setStructuralState(String structuralState) { + if (this.structuralState != null && !this.structuralState.equals("") + && !this.structuralState.equals(structuralState)) { + logger.warn("replacing structural state, Old: " + this.structuralState + " into new: " + structuralState); + } + this.structuralState = structuralState; + } + + /** + * @return the modificationResidues + * @see #modificationResidues + */ + public List<CellDesignerModificationResidue> getModificationResidues() { + return modificationResidues; + } + + /** + * @param modificationResidues + * the modificationResidues to set + * @see #modificationResidues + */ + public void setModificationResidues(List<CellDesignerModificationResidue> modificationResidues) { + this.modificationResidues = modificationResidues; + } + + @Override + protected void setModelObjectFields(T result) { + super.setModelObjectFields(result); + result.setStructuralState(structuralState); + for (CellDesignerModificationResidue mr : modificationResidues) { + result.addModificationResidue(mr.createModificationResidueAlias()); + } + } } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerSpecies.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerSpecies.java index a9b87f73c5f5531f5742b9b572f4a03b97686bd0..c28f67f2e13fef25719339fa268d4b0efd1ffe1e 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerSpecies.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/structure/CellDesignerSpecies.java @@ -5,6 +5,7 @@ import org.apache.log4j.Logger; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.kinetics.SbmlUnitType; import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.field.PositionToCompartment; @@ -17,464 +18,511 @@ import lcsb.mapviewer.model.map.species.field.PositionToCompartment; * */ public class CellDesignerSpecies<T extends Species> extends CellDesignerElement<T> { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(CellDesignerSpecies.class.getName()); - - /** - * Identifier of the species. It must be unique within the model. - */ - private String idSpecies; - - /** - * Initial amount of species. - */ - private Integer initialAmount = null; - - /** - * Charge of the species. - */ - private Integer charge = null; - - /** - * Initial concentration of species. - */ - private Integer initialConcentration = null; - - /** - * Is only substance units allowed. - */ - private Boolean onlySubstanceUnits = null; - - /** - * How many dimers are in this species. - */ - private int homodimer = 1; - - /** - * Position on the compartment. - */ - private PositionToCompartment positionToCompartment = null; - - /** - * Is species hypothetical. - */ - private Boolean hypothetical = null; - - /** - * Set hypothetical flag from text input. - * - * @param text - * string with true/false value that determines hypothetical state. - * @see #hypothetical - */ - public void setHypothetical(String text) { - hypothetical = text.equals("true"); - } - - /** - * Constructor that copies the data from species given in the argument. - * - * @param species - * parent species from which we want to copy data - */ - public CellDesignerSpecies(CellDesignerSpecies<?> species) { - super(species); - this.hypothetical = species.hypothetical; - this.idSpecies = species.idSpecies; - this.positionToCompartment = species.positionToCompartment; - this.initialAmount = species.initialAmount; - this.charge = species.charge; - this.initialConcentration = species.initialConcentration; - this.onlySubstanceUnits = species.onlySubstanceUnits; - this.homodimer = species.homodimer; - } - - /** - * Default constructor. - */ - public CellDesignerSpecies() { - super(); - idSpecies = ""; - } - - /** - * Default constructor with species identifier as a parameter. - * - * @param id - * species identifier - */ - public CellDesignerSpecies(String id) { - this(); - this.idSpecies = id; - this.setName(id); - } - - @Override - public CellDesignerSpecies<T> copy() { - CellDesignerSpecies<T> result = new CellDesignerSpecies<T>(this); - - result.idSpecies = idSpecies; - result.setNotes(getNotes()); - result.setHypothetical(hypothetical); - // correct this - - result.setParent(getParent()); - - result.charge = charge; - result.initialAmount = initialAmount; - result.initialConcentration = initialConcentration; - result.onlySubstanceUnits = onlySubstanceUnits; - result.positionToCompartment = positionToCompartment; - result.homodimer = homodimer; - return result; - } - - /** - * Updates species with the value from the species given in the parameter. - * - * @param species - * object from which we are updating information - */ - public void update(CellDesignerSpecies<?> species) { - if (getName() == null || getName().equals("")) { - setName(species.getName()); - } else if (!getName().trim().equals(species.getName().trim())) { - String id = species.getElementId(); - if (id == null || id.equals("")) { - id = getElementId(); - } - logger.warn("Two different names in species with id =" + id + ": \"" + species.getName() + "\", \"" + getName() + "\""); - setName(species.getName()); - } - if (idSpecies == null || idSpecies.equals("")) { - setElementId(species.getElementId()); - } - for (MiriamData md : species.getMiriamData()) { - if (!getMiriamData().contains(md)) { - addMiriamData(new MiriamData(md)); - } - } - if (this.getNotes() == null || this.getNotes().trim().equals("")) { - setNotes(species.getNotes()); - } else if (species.getNotes() != null && !species.getNotes().trim().equals("") && !this.getNotes().equals(species.getNotes())) { - String string1 = this.getNotes(); - - String string2 = species.getNotes(); - - string1 = string1.trim(); - string2 = string2.trim(); - if (string2.toLowerCase().contains(string1.toLowerCase())) { - setNotes(species.getNotes()); - } else if (!string1.toLowerCase().contains(string2.toLowerCase())) { - // insert new information - setNotes(string2 + getNotes()); - } - } - - if (getParent() == null) { - setParent(species.getParent()); - } - - if (species.getHypothetical() != null) { - setHypothetical(species.getHypothetical()); - } - - if (getSymbol() != null && !getSymbol().equals("")) { - if (species.getSymbol() != null && !species.getSymbol().equals("")) { - if (!species.getSymbol().equals(getSymbol())) { - logger.warn("Different symbol names: " + species.getSymbol() + ", " + getSymbol() + ". Ignoring..."); - } - } - } else { - setSymbol(species.getSymbol()); - } - - if (getFullName() != null && !getFullName().equals("")) { - if (species.getFullName() != null && !species.getFullName().equals("")) { - if (!species.getFullName().equals(getFullName())) { - logger.warn("Different symbol names: " + species.getFullName() + ", " + getFullName() + ". Ignoring..."); - } - } - } else { - setFullName(species.getFullName()); - } - - for (String string : species.getSynonyms()) { - if (!getSynonyms().contains(string)) { - getSynonyms().add(string); - } - } - - for (String string : species.getFormerSymbols()) { - if (!getFormerSymbols().contains(string)) { - getFormerSymbols().add(string); - } - } - if (species.getHomodimer() != 1) { - setHomodimer(species.getHomodimer()); - } - } - - /** - * Sets initial amount from text. - * - * @param text - * initial amount in string format - * @see #initialAmount - */ - - public void setInitialAmount(String text) { - if (text != null && !text.trim().equals("")) { - try { - initialAmount = Integer.parseInt(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid species amount: " + text, e); - } - } else { - initialAmount = null; - } - - } - - /** - * Sets charge from text. - * - * @param text - * charge in string format - * @see #charge - */ - public void setCharge(String text) { - if (text != null && !text.trim().equals("")) { - try { - charge = Integer.parseInt(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid species charge: " + text, e); - } - } else { - charge = null; - } - - } - - /** - * Sets OnlySubstanceUnits amount from text. - * - * @param text - * OnlySubstanceUnits in string format - * @see #onlySubstanceUnits - */ - public void setOnlySubstanceUnits(String text) { - if (text != null && !text.trim().equals("")) { - if (text.equalsIgnoreCase("TRUE")) { - onlySubstanceUnits = true; - } else if (text.equalsIgnoreCase("FALSE")) { - onlySubstanceUnits = false; - } else { - throw new InvalidArgumentException("Invalid species value for only substance unit boolean: " + text); - } - } else { - onlySubstanceUnits = null; - } - } - - /** - * Sets initial concentration amount from text. - * - * @param text - * initial concentration in string format - * @see #initialConcentration - */ - public void setInitialConcentration(String text) { - if (text != null && !text.trim().equals("")) { - try { - initialConcentration = Integer.parseInt(text); - } catch (NumberFormatException e) { - throw new InvalidArgumentException("Invalid species initial concentration: " + text, e); - } - } else { - initialConcentration = null; - } - } - - /** - * Is species hypothetical or not. - * - * @return <code>true</code> if species is hypothetical, <code>false</code> - * otherwise - */ - public boolean isHypothetical() { - if (hypothetical == null) { - return false; - } - return hypothetical; - } - - @Override - public String getElementId() { - return this.idSpecies; - } - - @Override - public void setElementId(String id) { - if (this.idSpecies.equals(id) || this.idSpecies.equals("")) { - this.idSpecies = id; - } else if (!id.equals("")) { - throw new InvalidArgumentException("Cannot change identifier of the species in the runtime. OLD: " + this.idSpecies + ", NEW: " + id); - } else { - this.idSpecies = id; - } - } - - /** - * @return the initialAmount - * @see #initialAmount - */ - public Integer getInitialAmount() { - return initialAmount; - } - - /** - * @param initialAmount - * the initialAmount to set - * @see #initialAmount - */ - public void setInitialAmount(Integer initialAmount) { - this.initialAmount = initialAmount; - } - - /** - * @return the charge - * @see #charge - */ - public Integer getCharge() { - return charge; - } - - /** - * @param charge - * the charge to set - * @see #charge - */ - public void setCharge(Integer charge) { - this.charge = charge; - } - - /** - * @return the onlySubstanceUnits - * @see #onlySubstanceUnits - */ - public Boolean getOnlySubstanceUnits() { - return onlySubstanceUnits; - } - - /** - * @param onlySubstanceUnits - * the onlySubstanceUnits to set - * @see #onlySubstanceUnits - */ - public void setOnlySubstanceUnits(Boolean onlySubstanceUnits) { - this.onlySubstanceUnits = onlySubstanceUnits; - } - - /** - * @return the initialConcentration - * @see #initialConcentration - */ - public Integer getInitialConcentration() { - return initialConcentration; - } - - /** - * @param initialConcentration - * the initialConcentration to set - * @see #initialConcentration - */ - public void setInitialConcentration(Integer initialConcentration) { - this.initialConcentration = initialConcentration; - } - - /** - * @return the hypothetical - * @see #hypothetical - */ - public Boolean getHypothetical() { - return hypothetical; - } - - /** - * @param hypothetical - * the hypothetical to set - * @see #hypothetical - */ - public void setHypothetical(Boolean hypothetical) { - this.hypothetical = hypothetical; - } - - /** - * @return the onlySubstanceUnits - * @see #onlySubstanceUnits - */ - public Boolean hasOnlySubstanceUnits() { - return onlySubstanceUnits; - } - - /** - * @return the positionToCompartment - * @see #positionToCompartment - */ - public PositionToCompartment getPositionToCompartment() { - return positionToCompartment; - } - - /** - * @param positionToCompartment - * the positionToCompartment to set - * @see #positionToCompartment - */ - public void setPositionToCompartment(PositionToCompartment positionToCompartment) { - this.positionToCompartment = positionToCompartment; - } - - /** - * @return the homodimer - * @see #homodimer - */ - public int getHomodimer() { - return homodimer; - } - - /** - * @param homodimer - * the homodimer to set - * @see #homodimer - */ - public void setHomodimer(int homodimer) { - this.homodimer = homodimer; - } - - @Override - public T createModelElement(String aliasId) { - throw new NotImplementedException("" + this.getClass()); - } - - @Override - protected void setModelObjectFields(T result) { - super.setModelObjectFields(result); - result.setInitialAmount(initialAmount); - result.setCharge(charge); - result.setInitialConcentration(initialConcentration); - result.setOnlySubstanceUnits(onlySubstanceUnits); - result.setHomodimer(homodimer); - result.setPositionToCompartment(positionToCompartment); - result.setHypothetical(hypothetical); - } + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(CellDesignerSpecies.class.getName()); + + /** + * Identifier of the species. It must be unique within the model. + */ + private String idSpecies; + + /** + * Initial amount of species. + */ + private Double initialAmount = null; + + /** + * Charge of the species. + */ + private Integer charge = null; + + /** + * Initial concentration of species. + */ + private Double initialConcentration = null; + + /** + * Is only substance units allowed. + */ + private Boolean onlySubstanceUnits = null; + + /** + * How many dimers are in this species. + */ + private int homodimer = 1; + + /** + * Position on the compartment. + */ + private PositionToCompartment positionToCompartment = null; + + /** + * Is species hypothetical. + */ + private Boolean hypothetical = null; + + private SbmlUnitType substanceUnits; + + private Boolean boundaryCondition; + + private Boolean constant; + + /** + * Set hypothetical flag from text input. + * + * @param text + * string with true/false value that determines hypothetical state. + * @see #hypothetical + */ + public void setHypothetical(String text) { + hypothetical = text.equals("true"); + } + + /** + * Constructor that copies the data from species given in the argument. + * + * @param species + * parent species from which we want to copy data + */ + public CellDesignerSpecies(CellDesignerSpecies<?> species) { + super(species); + this.hypothetical = species.hypothetical; + this.idSpecies = species.idSpecies; + this.positionToCompartment = species.positionToCompartment; + this.initialAmount = species.initialAmount; + this.charge = species.charge; + this.initialConcentration = species.initialConcentration; + this.onlySubstanceUnits = species.onlySubstanceUnits; + this.homodimer = species.homodimer; + this.constant = species.constant; + this.substanceUnits = species.substanceUnits; + this.boundaryCondition = species.boundaryCondition; + } + + /** + * Default constructor. + */ + public CellDesignerSpecies() { + super(); + idSpecies = ""; + } + + /** + * Default constructor with species identifier as a parameter. + * + * @param id + * species identifier + */ + public CellDesignerSpecies(String id) { + this(); + this.idSpecies = id; + this.setName(id); + } + + @Override + public CellDesignerSpecies<T> copy() { + CellDesignerSpecies<T> result = new CellDesignerSpecies<T>(this); + + result.idSpecies = idSpecies; + result.setNotes(getNotes()); + result.setHypothetical(hypothetical); + // correct this + + result.setParent(getParent()); + + return result; + } + + /** + * Updates species with the value from the species given in the parameter. + * + * @param species + * object from which we are updating information + */ + public void update(CellDesignerSpecies<?> species) { + if (getName() == null || getName().equals("")) { + setName(species.getName()); + } else if (!getName().trim().equals(species.getName().trim())) { + String id = species.getElementId(); + if (id == null || id.equals("")) { + id = getElementId(); + } + logger.warn( + "Two different names in species with id =" + id + ": \"" + species.getName() + "\", \"" + getName() + "\""); + setName(species.getName()); + } + if (idSpecies == null || idSpecies.equals("")) { + setElementId(species.getElementId()); + } + for (MiriamData md : species.getMiriamData()) { + if (!getMiriamData().contains(md)) { + addMiriamData(new MiriamData(md)); + } + } + if (this.getNotes() == null || this.getNotes().trim().equals("")) { + setNotes(species.getNotes()); + } else if (species.getNotes() != null && !species.getNotes().trim().equals("") + && !this.getNotes().equals(species.getNotes())) { + String string1 = this.getNotes(); + + String string2 = species.getNotes(); + + string1 = string1.trim(); + string2 = string2.trim(); + if (string2.toLowerCase().contains(string1.toLowerCase())) { + setNotes(species.getNotes()); + } else if (!string1.toLowerCase().contains(string2.toLowerCase())) { + // insert new information + setNotes(string2 + getNotes()); + } + } + + if (getParent() == null) { + setParent(species.getParent()); + } + + if (species.getHypothetical() != null) { + setHypothetical(species.getHypothetical()); + } + + if (getSymbol() != null && !getSymbol().equals("")) { + if (species.getSymbol() != null && !species.getSymbol().equals("")) { + if (!species.getSymbol().equals(getSymbol())) { + logger.warn("Different symbol names: " + species.getSymbol() + ", " + getSymbol() + ". Ignoring..."); + } + } + } else { + setSymbol(species.getSymbol()); + } + + if (getFullName() != null && !getFullName().equals("")) { + if (species.getFullName() != null && !species.getFullName().equals("")) { + if (!species.getFullName().equals(getFullName())) { + logger.warn("Different symbol names: " + species.getFullName() + ", " + getFullName() + ". Ignoring..."); + } + } + } else { + setFullName(species.getFullName()); + } + + for (String string : species.getSynonyms()) { + if (!getSynonyms().contains(string)) { + getSynonyms().add(string); + } + } + + for (String string : species.getFormerSymbols()) { + if (!getFormerSymbols().contains(string)) { + getFormerSymbols().add(string); + } + } + if (species.getHomodimer() != 1) { + setHomodimer(species.getHomodimer()); + } + } + + /** + * Sets initial amount from text. + * + * @param text + * initial amount in string format + * @see #initialAmount + */ + + public void setInitialAmount(String text) { + if (text != null && !text.trim().equals("")) { + try { + initialAmount = Double.parseDouble(text); + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid species amount: " + text, e); + } + } else { + initialAmount = null; + } + + } + + /** + * Sets charge from text. + * + * @param text + * charge in string format + * @see #charge + */ + public void setCharge(String text) { + if (text != null && !text.trim().equals("")) { + try { + charge = Integer.parseInt(text); + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid species charge: " + text, e); + } + } else { + charge = null; + } + + } + + /** + * Sets OnlySubstanceUnits amount from text. + * + * @param text + * OnlySubstanceUnits in string format + * @see #onlySubstanceUnits + */ + public void setOnlySubstanceUnits(String text) { + onlySubstanceUnits = textToBoolean(text, "Invalid species value for only substance unit boolean: " + text); + } + + /** + * Sets initial concentration amount from text. + * + * @param text + * initial concentration in string format + * @see #initialConcentration + */ + public void setInitialConcentration(String text) { + if (text != null && !text.trim().equals("")) { + try { + initialConcentration = Double.parseDouble(text); + } catch (NumberFormatException e) { + throw new InvalidArgumentException("Invalid species initial concentration: " + text, e); + } + } else { + initialConcentration = null; + } + } + + /** + * Is species hypothetical or not. + * + * @return <code>true</code> if species is hypothetical, <code>false</code> + * otherwise + */ + public boolean isHypothetical() { + if (hypothetical == null) { + return false; + } + return hypothetical; + } + + @Override + public String getElementId() { + return this.idSpecies; + } + + @Override + public void setElementId(String id) { + if (this.idSpecies.equals(id) || this.idSpecies.equals("")) { + this.idSpecies = id; + } else if (!id.equals("")) { + throw new InvalidArgumentException( + "Cannot change identifier of the species in the runtime. OLD: " + this.idSpecies + ", NEW: " + id); + } else { + this.idSpecies = id; + } + } + + /** + * @return the initialAmount + * @see #initialAmount + */ + public Double getInitialAmount() { + return initialAmount; + } + + /** + * @param initialAmount + * the initialAmount to set + * @see #initialAmount + */ + public void setInitialAmount(Double initialAmount) { + this.initialAmount = initialAmount; + } + + /** + * @return the charge + * @see #charge + */ + public Integer getCharge() { + return charge; + } + + /** + * @param charge + * the charge to set + * @see #charge + */ + public void setCharge(Integer charge) { + this.charge = charge; + } + + /** + * @return the onlySubstanceUnits + * @see #onlySubstanceUnits + */ + public Boolean getOnlySubstanceUnits() { + return onlySubstanceUnits; + } + + /** + * @param onlySubstanceUnits + * the onlySubstanceUnits to set + * @see #onlySubstanceUnits + */ + public void setOnlySubstanceUnits(Boolean onlySubstanceUnits) { + this.onlySubstanceUnits = onlySubstanceUnits; + } + + /** + * @return the initialConcentration + * @see #initialConcentration + */ + public Double getInitialConcentration() { + return initialConcentration; + } + + /** + * @param initialConcentration + * the initialConcentration to set + * @see #initialConcentration + */ + public void setInitialConcentration(Double initialConcentration) { + this.initialConcentration = initialConcentration; + } + + /** + * @return the hypothetical + * @see #hypothetical + */ + public Boolean getHypothetical() { + return hypothetical; + } + + /** + * @param hypothetical + * the hypothetical to set + * @see #hypothetical + */ + public void setHypothetical(Boolean hypothetical) { + this.hypothetical = hypothetical; + } + + /** + * @return the onlySubstanceUnits + * @see #onlySubstanceUnits + */ + public Boolean hasOnlySubstanceUnits() { + return onlySubstanceUnits; + } + + /** + * @return the positionToCompartment + * @see #positionToCompartment + */ + public PositionToCompartment getPositionToCompartment() { + return positionToCompartment; + } + + /** + * @param positionToCompartment + * the positionToCompartment to set + * @see #positionToCompartment + */ + public void setPositionToCompartment(PositionToCompartment positionToCompartment) { + this.positionToCompartment = positionToCompartment; + } + + /** + * @return the homodimer + * @see #homodimer + */ + public int getHomodimer() { + return homodimer; + } + + /** + * @param homodimer + * the homodimer to set + * @see #homodimer + */ + public void setHomodimer(int homodimer) { + this.homodimer = homodimer; + } + + @Override + public T createModelElement(String aliasId) { + throw new NotImplementedException("" + this.getClass()); + } + + @Override + protected void setModelObjectFields(T result) { + super.setModelObjectFields(result); + result.setInitialAmount(initialAmount); + result.setCharge(charge); + result.setInitialConcentration(initialConcentration); + result.setOnlySubstanceUnits(onlySubstanceUnits); + result.setConstant(constant); + result.setBoundaryCondition(boundaryCondition); + result.setSubstanceUnits(substanceUnits); + result.setHomodimer(homodimer); + result.setPositionToCompartment(positionToCompartment); + result.setHypothetical(hypothetical); + } + + public void setSubstanceUnits(SbmlUnitType substanceUnits) { + this.substanceUnits = substanceUnits; + } + + public SbmlUnitType getSubstanceUnit() { + return this.substanceUnits; + } + + public Boolean isBoundaryCondition() { + return boundaryCondition; + } + + public Boolean isConstant() { + return constant; + } + + public void setBoundaryCondition(String text) { + boundaryCondition = textToBoolean(text, "Invalid species value for only substance unit boolean: " + text); + } + + private Boolean textToBoolean(String text, String errorMessage) { + Boolean result; + if (text != null && !text.trim().equals("")) { + if (text.equalsIgnoreCase("TRUE")) { + result = true; + } else if (text.equalsIgnoreCase("FALSE")) { + result = false; + } else { + throw new InvalidArgumentException(errorMessage); + } + } else { + result = null; + } + return result; + } + + public void setConstant(String text) { + constant = textToBoolean(text, "Invalid species value for only constant boolean: " + text); + } + + public void setBoundaryCondition(Boolean boundaryCondition) { + this.boundaryCondition = boundaryCondition; + } + + public void setConstant(Boolean constant) { + this.constant = constant; + } } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java index b2686560126584ec847aa05c4c912b2b9e7b7c35..010a5dc8da7033b0052d0f34d2a4790992ed12e9 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/ComplexParserTests.java @@ -18,9 +18,11 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.kinetics.SbmlUnitType; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelComparator; import lcsb.mapviewer.model.map.model.ModelFullIndexed; @@ -75,6 +77,23 @@ public class ComplexParserTests extends CellDesignerTestFunctions { } } + @Test + public void testParseElementKinetics() throws Exception { + try { + Model model = getModelForFile("testFiles/elements_with_kinetic_data.xml"); + + GenericProtein protein1 = model.getElementByElementId("sa1"); + assertEquals(2.5, protein1.getInitialAmount(), Configuration.EPSILON); + assertTrue("hasOnlySubstance property is not parsed properly", protein1.hasOnlySubstanceUnits()); + assertTrue("boundaryCondition property is not parsed properly", protein1.isBoundaryCondition()); + assertTrue("constant property is not parsed properly", protein1.isConstant()); + assertEquals(SbmlUnitType.GRAM, protein1.getSubstanceUnits()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testParseUnits() throws Exception { try { diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParserTest.java index 24833a18ae2f1cb965a525d081cac0e87d101517..01d8192151ac435f98f1becce3118adca2e63db8 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/species/SpeciesSbmlParserTest.java @@ -20,6 +20,7 @@ import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; @@ -43,1052 +44,1095 @@ import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesigner import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerRnaRegion; import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState; +import lcsb.mapviewer.model.map.kinetics.SbmlUnitType; import lcsb.mapviewer.model.map.species.Gene; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Species; public class SpeciesSbmlParserTest extends CellDesignerTestFunctions { - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(SpeciesSbmlParserTest.class.getName()); - - SpeciesSbmlParser parser; - - String testDirectory = "testFiles" + System.getProperty("file.separator") + "xmlNodeTestExamples" - + System.getProperty("file.separator"); - String testGeneFile = "sbml_gene.xml"; - String testDegradedFile = "sbml_degraded.xml"; - String testDrugFile = "sbml_drug.xml"; - String testIonFile = "sbml_ion.xml"; - String testPhenotypeFile = "sbml_phenotype.xml"; - String testProteinFile = "sbml_protein.xml"; - String testRnaFile = "sbml_rna.xml"; - String testSimpleMoleculeFile = "sbml_simple_molecule.xml"; - String testUnknownFile = "sbml_unknown.xml"; - - CellDesignerElementCollection elements; - - int idCounter = 0; - - @Before - public void setUp() throws Exception { - elements = new CellDesignerElementCollection(); - parser = new SpeciesSbmlParser(elements); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testParseXmlSpeciesAntisenseRna() throws Exception { - try { - String xmlString = readFile(testDirectory + "sbml_antisense_rna.xml"); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerAntisenseRna species = (CellDesignerAntisenseRna) result.getRight(); - assertEquals("s2", species.getElementId()); - assertEquals("s3", species.getName()); - assertEquals(new Integer(2), species.getInitialAmount()); - assertEquals(Boolean.TRUE, species.hasOnlySubstanceUnits()); - assertEquals(new Integer(0), species.getCharge()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlAntisenseRna() throws Exception { - try { - String xmlString = readFile(testDirectory + "sbml_antisense_rna.xml"); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerAntisenseRna species = (CellDesignerAntisenseRna) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerAntisenseRna species2 = (CellDesignerAntisenseRna) result2.getRight(); - - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getPositionToCompartment(), species2.getPositionToCompartment()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesComplex() throws Exception { - try { - String xmlString = readFile(testDirectory + "sbml_complex.xml"); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerComplexSpecies species = (CellDesignerComplexSpecies) result.getRight(); - assertNotNull(species); - assertEquals("s6549", species.getElementId()); - assertEquals("LC3-II", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlComplex() throws Exception { - try { - String xmlString = readFile(testDirectory + "sbml_complex.xml"); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerComplexSpecies species = (CellDesignerComplexSpecies) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerComplexSpecies species2 = (CellDesignerComplexSpecies) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesDegraded() throws Exception { - try { - String xmlString = readFile(testDirectory + testDegradedFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerDegraded species = (CellDesignerDegraded) result.getRight(); - assertNotNull(species); - assertEquals("s1275", species.getElementId()); - assertEquals("s1275", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlDegraded() throws Exception { - try { - String xmlString = readFile(testDirectory + testDegradedFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerDegraded species = (CellDesignerDegraded) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerDegraded species2 = (CellDesignerDegraded) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesDrug() throws Exception { - try { - String xmlString = readFile(testDirectory + testDrugFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerDrug species = (CellDesignerDrug) result.getRight(); - assertEquals("s6104", species.getElementId()); - assertEquals("geldanamycin", species.getName()); - assertEquals(new Integer(0), species.getCharge()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlDrug() throws Exception { - try { - String xmlString = readFile(testDirectory + testDrugFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerDrug species = (CellDesignerDrug) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerDrug species2 = (CellDesignerDrug) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesGene() throws Exception { - try { - String xmlString = readFile(testDirectory + testGeneFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerGene species = (CellDesignerGene) result.getRight(); - - assertEquals("s5916", species.getElementId()); - assertEquals("Ptgr1", species.getName()); - assertEquals(new Integer(0), species.getCharge()); - assertEquals(new Integer(0), species.getInitialAmount()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesGeneWithModelUpdate() throws Exception { - try { - CellDesignerSpecies<?> gene = new CellDesignerGene(); - gene.setElementId("s5916"); - InternalModelSpeciesData modelData = new InternalModelSpeciesData(); - modelData.updateSpecies(gene, ""); - - SpeciesSbmlParser complexParser = new SpeciesSbmlParser(elements); - CellDesignerGene oldGene = new CellDesignerGene(); - oldGene.setElementId("s5916"); - oldGene.setName("Ptgr1"); - modelData.updateSpecies(oldGene, "gn95"); - - String xmlString = readFile(testDirectory + testGeneFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = complexParser.parseXmlElement(xmlString); - CellDesignerGene species = (CellDesignerGene) result.getRight(); - modelData.updateSpecies(species, result.getLeft()); - - assertEquals("s5916", species.getElementId()); - assertEquals("Ptgr1", species.getName()); - assertTrue(species.getNotes().contains("prostaglandin reductase 1")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlGene() throws Exception { - try { - String xmlString = readFile(testDirectory + testGeneFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerGene species = (CellDesignerGene) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerGene species2 = (CellDesignerGene) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertTrue(species2.getNotes().trim().contains(species.getNotes().trim())); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesIon() throws Exception { - try { - String xmlString = readFile(testDirectory + testIonFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerIon species = (CellDesignerIon) result.getRight(); - - assertEquals("s6029", species.getElementId()); - assertEquals("Pi", species.getName()); - assertEquals(new Integer(0), species.getCharge()); - assertEquals(new Integer(0), species.getInitialConcentration()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlIon() throws Exception { - try { - String xmlString = readFile(testDirectory + testIonFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerIon species = (CellDesignerIon) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(xmlString); - CellDesignerIon species2 = (CellDesignerIon) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getElementId(), species2.getElementId()); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); - assertEquals(species.getNotes().trim(), species2.getNotes().trim()); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesPhenotype() throws Exception { - try { - String xmlString = readFile(testDirectory + testPhenotypeFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerPhenotype species = (CellDesignerPhenotype) result.getRight(); - - assertEquals("s5462", species.getElementId()); - assertEquals("Neuronal damage and death", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlPhenotype() throws Exception { - try { - String xmlString = readFile(testDirectory + testPhenotypeFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerPhenotype species = (CellDesignerPhenotype) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerPhenotype species2 = (CellDesignerPhenotype) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); - assertEquals(species.getNotes(), species2.getNotes()); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesProtein() throws Exception { - try { - String xmlString = readFile(testDirectory + testProteinFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerProtein<?> species = (CellDesignerProtein<?>) result.getRight(); - - assertEquals("s5456", species.getElementId()); - assertEquals("PTPRC", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - assertEquals(new Integer(0), species.getCharge()); - assertTrue(species.getNotes().contains("protein tyrosine phosphatase, receptor type, C")); - assertNull(species.getStructuralState()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlProtein() throws Exception { - try { - String xmlString = readFile(testDirectory + testProteinFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerGenericProtein species = new CellDesignerGenericProtein(result.getRight()); - - String transformedXml = parser.toXml(species.createModelElement("" + idCounter++)); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement("" + idCounter++))); - CellDesignerProtein<?> species2 = (CellDesignerProtein<?>) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); - assertTrue(species2.getNotes().contains(species.getNotes())); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesRna() throws Exception { - try { - String xmlString = readFile(testDirectory + testRnaFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerRna species = (CellDesignerRna) result.getRight(); - - assertEquals("s5914", species.getElementId()); - assertEquals("Fmo3", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - assertEquals(new Integer(0), species.getCharge()); - assertTrue(species.getNotes().contains("Dimethylaniline monooxygenase [N-oxide-forming] 3")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlRna() throws Exception { - try { - String xmlString = readFile(testDirectory + testRnaFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerRna species = (CellDesignerRna) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerRna species2 = (CellDesignerRna) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); - assertTrue(species2.getNotes().trim().contains(species.getNotes().trim())); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesSimpleMolecule() throws Exception { - try { - String xmlString = readFile(testDirectory + testSimpleMoleculeFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerSimpleMolecule species = (CellDesignerSimpleMolecule) result.getRight(); - assertEquals("s5463", species.getElementId()); - assertEquals("Peroxides", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlSimpleMolecule() throws Exception { - try { - String xmlString = readFile(testDirectory + testSimpleMoleculeFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerSimpleMolecule species = (CellDesignerSimpleMolecule) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement("" + idCounter++)); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement("" + idCounter++))); - CellDesignerSimpleMolecule species2 = (CellDesignerSimpleMolecule) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); - assertEquals(species.getNotes(), species2.getNotes()); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseXmlSpeciesUnknown() throws Exception { - try { - String xmlString = readFile(testDirectory + testUnknownFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerUnknown species = (CellDesignerUnknown) result.getRight(); - assertEquals("s1356", species.getElementId()); - assertEquals("unidentified caspase acting on Occludin", species.getName()); - assertEquals(new Integer(0), species.getInitialAmount()); - assertEquals(new Integer(0), species.getCharge()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlUnknown() throws Exception { - try { - String xmlString = readFile(testDirectory + testUnknownFile); - Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); - CellDesignerUnknown species = (CellDesignerUnknown) result.getRight(); - - String transformedXml = parser.toXml(species.createModelElement()); - assertNotNull(transformedXml); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(transformedXml)); - Document doc = builder.parse(is); - NodeList root = doc.getChildNodes(); - assertEquals("species", root.item(0).getNodeName()); - - Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(parser.toXml(species.createModelElement())); - CellDesignerUnknown species2 = (CellDesignerUnknown) result2.getRight(); - - assertNotNull(species2); - assertEquals(species.getName(), species2.getName()); - assertEquals(species.getParent(), species2.getParent()); - assertEquals(species.getInitialAmount(), species2.getInitialAmount()); - assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); - assertEquals(species.getCharge(), species2.getCharge()); - assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); - assertEquals(species.getNotes(), species2.getNotes()); - assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("No annotation node")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid2() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein2.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("bla")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid3() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein3.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("unk_bla")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid4() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein4.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("No celldesigner:extension")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid5() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein5.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("ann_unk")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid6() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein6.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("No celldesigner:speciesIdentity")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid7() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein7.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("unkPos")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid8() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein8.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("Species node in Sbml model doesn't contain")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid9() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein9.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("unknown_protein_class")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid10() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein10.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("Wrong class type for protein reference")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid11() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein11.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("Wrong class type for gene reference")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid12() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein12.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("Wrong class type for rna reference")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid13() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein13.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("Wrong class type for antisense rna reference")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testParseInvalid14() throws Exception { - try { - String xmlString = readFile("testFiles/invalid/invalid_sbml_protein14.xml"); - parser.parseXmlElement(xmlString); - fail("Exception expected"); - } catch (InvalidXmlSchemaException e) { - assertTrue(e.getMessage().contains("uknNode")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToXmlWithDefaultCompartment() throws Exception { - try { - CellDesignerGenericProtein species = new CellDesignerGenericProtein(); - String xml = parser.toXml(species.createModelElement("EL_ID")); - assertTrue(xml.contains("EL_ID")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidSpeciesIdentityToXml() throws Exception { - try { - Species species = Mockito.mock(Species.class); - parser.speciesIdentityToXml(species); - fail("Excepiton expected"); - } catch (InvalidArgumentException e) { - assertTrue(e.getMessage().contains("Invalid species class")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSpeciesIdentityToXml() throws Exception { - try { - GenericProtein species = new GenericProtein("xx"); - species.setHypothetical(true); - String xml = parser.speciesIdentityToXml(species); - assertTrue(xml.contains("<celldesigner:hypothetical>true</celldesigner:hypothetical>")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSpeciesStateToXml() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.setHomodimer(2); - state.setStructuralState("xxxState"); - String xml = parser.speciesStateToXml(state); - assertTrue(xml.contains("xxxState")); - assertTrue(xml.contains("celldesigner:homodimer")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.addModificationResidue(new CellDesignerModificationResidue()); - CellDesignerComplexSpecies species = new CellDesignerComplexSpecies(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Modification not supported in Complex")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies2() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.setStructuralState("state"); - CellDesignerGene species = new CellDesignerGene(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("StructuralState not supported in Gene")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies3() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.setStructuralState("state"); - CellDesignerRna species = new CellDesignerRna(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Structural state not supported in RNA")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies4() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.addModificationResidue(new CellDesignerModificationResidue()); - CellDesignerSimpleMolecule species = new CellDesignerSimpleMolecule(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Modification not supported in SimpleMolecule")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies5() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.setStructuralState("state"); - CellDesignerSimpleMolecule species = new CellDesignerSimpleMolecule(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Structural state not supported in SimpleMolecule")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies6() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.setStructuralState("state"); - CellDesignerAntisenseRna species = new CellDesignerAntisenseRna(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Structural state not supported in AntisenseRna")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies7() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.setStructuralState("state"); - CellDesignerSpecies<?> species = new CellDesignerSpecies<Gene>(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Structural state not supported")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessInvalidStateDataInSpecies8() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.addModificationResidue(new CellDesignerModificationResidue()); - CellDesignerSpecies<?> species = new CellDesignerSpecies<Gene>(); - - parser.processStateDataInSpecies(species, state); - fail("Exception expected"); - } catch (NotImplementedException e) { - assertTrue(e.getMessage().contains("Modification not supported in")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProcessAntisenseRnaStateDataInSpecies() throws Exception { - try { - SpeciesState state = new SpeciesState(); - state.addModificationResidue(new CellDesignerModificationResidue()); - CellDesignerAntisenseRna species = new CellDesignerAntisenseRna(); - - parser.processStateDataInSpecies(species, state); - - assertEquals(1, species.getRegions().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCreateRnaRegion() throws Exception { - try { - CellDesignerModificationResidue mr = new CellDesignerModificationResidue(); - mr.setSize(1.0); - mr.setAngle(1.0); - - CellDesignerRnaRegion region = parser.createRnaRegion(mr); - assertNotNull(region.getPos()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCreateAntisenseRnaRegion() throws Exception { - try { - CellDesignerModificationResidue mr = new CellDesignerModificationResidue(); - mr.setSize(1.0); - mr.setAngle(1.0); - - CellDesignerAntisenseRnaRegion region = parser.createAntisenseRnaRegion(mr); - assertNotNull(region.getPos()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(SpeciesSbmlParserTest.class.getName()); + + SpeciesSbmlParser parser; + + String testDirectory = "testFiles" + System.getProperty("file.separator") + "xmlNodeTestExamples" + + System.getProperty("file.separator"); + String testGeneFile = "sbml_gene.xml"; + String testDegradedFile = "sbml_degraded.xml"; + String testDrugFile = "sbml_drug.xml"; + String testIonFile = "sbml_ion.xml"; + String testPhenotypeFile = "sbml_phenotype.xml"; + String testProteinFile = "sbml_protein.xml"; + String testRnaFile = "sbml_rna.xml"; + String testSimpleMoleculeFile = "sbml_simple_molecule.xml"; + String testUnknownFile = "sbml_unknown.xml"; + + CellDesignerElementCollection elements; + + int idCounter = 0; + + @Before + public void setUp() throws Exception { + elements = new CellDesignerElementCollection(); + parser = new SpeciesSbmlParser(elements); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testParseXmlSpeciesAntisenseRna() throws Exception { + try { + String xmlString = readFile(testDirectory + "sbml_antisense_rna.xml"); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerAntisenseRna species = (CellDesignerAntisenseRna) result.getRight(); + assertEquals("s2", species.getElementId()); + assertEquals("s3", species.getName()); + assertEquals(2, species.getInitialAmount(), Configuration.EPSILON); + assertEquals(Boolean.TRUE, species.hasOnlySubstanceUnits()); + assertEquals(new Integer(0), species.getCharge()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesWithKineticsData() throws Exception { + try { + String xmlString = readFile("testFiles/kinetics/species_with_kinetics_param.xml"); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerProtein<?> species = (CellDesignerProtein<?>) result.getRight(); + assertEquals(3.7, species.getInitialConcentration(), Configuration.EPSILON); + assertEquals(SbmlUnitType.MOLE, species.getSubstanceUnit()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesWithKineticsData2() throws Exception { + try { + String xmlString = readFile("testFiles/kinetics/species_with_kinetics_param2.xml"); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerProtein<?> species = (CellDesignerProtein<?>) result.getRight(); + assertEquals(2.5, species.getInitialAmount(), Configuration.EPSILON); + assertEquals(SbmlUnitType.GRAM, species.getSubstanceUnit()); + assertEquals(Boolean.TRUE, species.hasOnlySubstanceUnits()); + assertEquals("Boundary condition wasn't parsed", Boolean.TRUE, species.isBoundaryCondition()); + assertEquals("Constant property wasn't parsed", Boolean.TRUE, species.isConstant()); + assertEquals(new Integer(0), species.getCharge()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlAntisenseRna() throws Exception { + try { + String xmlString = readFile(testDirectory + "sbml_antisense_rna.xml"); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerAntisenseRna species = (CellDesignerAntisenseRna) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerAntisenseRna species2 = (CellDesignerAntisenseRna) result2.getRight(); + + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getPositionToCompartment(), species2.getPositionToCompartment()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesComplex() throws Exception { + try { + String xmlString = readFile(testDirectory + "sbml_complex.xml"); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerComplexSpecies species = (CellDesignerComplexSpecies) result.getRight(); + assertNotNull(species); + assertEquals("s6549", species.getElementId()); + assertEquals("LC3-II", species.getName()); + assertEquals(0.0, species.getInitialAmount(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlComplex() throws Exception { + try { + String xmlString = readFile(testDirectory + "sbml_complex.xml"); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerComplexSpecies species = (CellDesignerComplexSpecies) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerComplexSpecies species2 = (CellDesignerComplexSpecies) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesDegraded() throws Exception { + try { + String xmlString = readFile(testDirectory + testDegradedFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerDegraded species = (CellDesignerDegraded) result.getRight(); + assertNotNull(species); + assertEquals("s1275", species.getElementId()); + assertEquals("s1275", species.getName()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlDegraded() throws Exception { + try { + String xmlString = readFile(testDirectory + testDegradedFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerDegraded species = (CellDesignerDegraded) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerDegraded species2 = (CellDesignerDegraded) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesDrug() throws Exception { + try { + String xmlString = readFile(testDirectory + testDrugFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerDrug species = (CellDesignerDrug) result.getRight(); + assertEquals("s6104", species.getElementId()); + assertEquals("geldanamycin", species.getName()); + assertEquals(new Integer(0), species.getCharge()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlDrug() throws Exception { + try { + String xmlString = readFile(testDirectory + testDrugFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerDrug species = (CellDesignerDrug) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerDrug species2 = (CellDesignerDrug) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesGene() throws Exception { + try { + String xmlString = readFile(testDirectory + testGeneFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerGene species = (CellDesignerGene) result.getRight(); + + assertEquals("s5916", species.getElementId()); + assertEquals("Ptgr1", species.getName()); + assertEquals(new Integer(0), species.getCharge()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesGeneWithModelUpdate() throws Exception { + try { + CellDesignerSpecies<?> gene = new CellDesignerGene(); + gene.setElementId("s5916"); + InternalModelSpeciesData modelData = new InternalModelSpeciesData(); + modelData.updateSpecies(gene, ""); + + SpeciesSbmlParser complexParser = new SpeciesSbmlParser(elements); + CellDesignerGene oldGene = new CellDesignerGene(); + oldGene.setElementId("s5916"); + oldGene.setName("Ptgr1"); + modelData.updateSpecies(oldGene, "gn95"); + + String xmlString = readFile(testDirectory + testGeneFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = complexParser.parseXmlElement(xmlString); + CellDesignerGene species = (CellDesignerGene) result.getRight(); + modelData.updateSpecies(species, result.getLeft()); + + assertEquals("s5916", species.getElementId()); + assertEquals("Ptgr1", species.getName()); + assertTrue(species.getNotes().contains("prostaglandin reductase 1")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlGene() throws Exception { + try { + String xmlString = readFile(testDirectory + testGeneFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerGene species = (CellDesignerGene) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerGene species2 = (CellDesignerGene) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertTrue(species2.getNotes().trim().contains(species.getNotes().trim())); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesIon() throws Exception { + try { + String xmlString = readFile(testDirectory + testIonFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerIon species = (CellDesignerIon) result.getRight(); + + assertEquals("s6029", species.getElementId()); + assertEquals("Pi", species.getName()); + assertEquals(new Integer(0), species.getCharge()); + assertEquals(0, species.getInitialConcentration(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlIon() throws Exception { + try { + String xmlString = readFile(testDirectory + testIonFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerIon species = (CellDesignerIon) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser.parseXmlElement(xmlString); + CellDesignerIon species2 = (CellDesignerIon) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getElementId(), species2.getElementId()); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); + assertEquals(species.getNotes().trim(), species2.getNotes().trim()); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesPhenotype() throws Exception { + try { + String xmlString = readFile(testDirectory + testPhenotypeFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerPhenotype species = (CellDesignerPhenotype) result.getRight(); + + assertEquals("s5462", species.getElementId()); + assertEquals("Neuronal damage and death", species.getName()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlPhenotype() throws Exception { + try { + String xmlString = readFile(testDirectory + testPhenotypeFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerPhenotype species = (CellDesignerPhenotype) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerPhenotype species2 = (CellDesignerPhenotype) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); + assertEquals(species.getNotes(), species2.getNotes()); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesProtein() throws Exception { + try { + String xmlString = readFile(testDirectory + testProteinFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerProtein<?> species = (CellDesignerProtein<?>) result.getRight(); + + assertEquals("s5456", species.getElementId()); + assertEquals("PTPRC", species.getName()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + assertEquals(new Integer(0), species.getCharge()); + assertTrue(species.getNotes().contains("protein tyrosine phosphatase, receptor type, C")); + assertNull(species.getStructuralState()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlProtein() throws Exception { + try { + String xmlString = readFile(testDirectory + testProteinFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerGenericProtein species = new CellDesignerGenericProtein(result.getRight()); + + String transformedXml = parser.toXml(species.createModelElement("" + idCounter++)); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement("" + idCounter++))); + CellDesignerProtein<?> species2 = (CellDesignerProtein<?>) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); + assertTrue(species2.getNotes().contains(species.getNotes())); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesRna() throws Exception { + try { + String xmlString = readFile(testDirectory + testRnaFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerRna species = (CellDesignerRna) result.getRight(); + + assertEquals("s5914", species.getElementId()); + assertEquals("Fmo3", species.getName()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + assertEquals(new Integer(0), species.getCharge()); + assertTrue(species.getNotes().contains("Dimethylaniline monooxygenase [N-oxide-forming] 3")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlRna() throws Exception { + try { + String xmlString = readFile(testDirectory + testRnaFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerRna species = (CellDesignerRna) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerRna species2 = (CellDesignerRna) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); + assertTrue(species2.getNotes().trim().contains(species.getNotes().trim())); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesSimpleMolecule() throws Exception { + try { + String xmlString = readFile(testDirectory + testSimpleMoleculeFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerSimpleMolecule species = (CellDesignerSimpleMolecule) result.getRight(); + assertEquals("s5463", species.getElementId()); + assertEquals("Peroxides", species.getName()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlSimpleMolecule() throws Exception { + try { + String xmlString = readFile(testDirectory + testSimpleMoleculeFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerSimpleMolecule species = (CellDesignerSimpleMolecule) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement("" + idCounter++)); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement("" + idCounter++))); + CellDesignerSimpleMolecule species2 = (CellDesignerSimpleMolecule) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); + assertEquals(species.getNotes(), species2.getNotes()); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseXmlSpeciesUnknown() throws Exception { + try { + String xmlString = readFile(testDirectory + testUnknownFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerUnknown species = (CellDesignerUnknown) result.getRight(); + assertEquals("s1356", species.getElementId()); + assertEquals("unidentified caspase acting on Occludin", species.getName()); + assertEquals(0, species.getInitialAmount(), Configuration.EPSILON); + assertEquals(new Integer(0), species.getCharge()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlUnknown() throws Exception { + try { + String xmlString = readFile(testDirectory + testUnknownFile); + Pair<String, ? extends CellDesignerSpecies<?>> result = parser.parseXmlElement(xmlString); + CellDesignerUnknown species = (CellDesignerUnknown) result.getRight(); + + String transformedXml = parser.toXml(species.createModelElement()); + assertNotNull(transformedXml); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(transformedXml)); + Document doc = builder.parse(is); + NodeList root = doc.getChildNodes(); + assertEquals("species", root.item(0).getNodeName()); + + Pair<String, ? extends CellDesignerSpecies<?>> result2 = parser + .parseXmlElement(parser.toXml(species.createModelElement())); + CellDesignerUnknown species2 = (CellDesignerUnknown) result2.getRight(); + + assertNotNull(species2); + assertEquals(species.getName(), species2.getName()); + assertEquals(species.getParent(), species2.getParent()); + assertEquals(species.getInitialAmount(), species2.getInitialAmount()); + assertEquals(species.hasOnlySubstanceUnits(), species2.hasOnlySubstanceUnits()); + assertEquals(species.getCharge(), species2.getCharge()); + assertEquals(species.getInitialConcentration(), species2.getInitialConcentration()); + assertEquals(species.getNotes(), species2.getNotes()); + assertEquals(species.getMiriamData().size(), species2.getMiriamData().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("No annotation node")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid2() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein2.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("bla")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid3() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein3.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("unk_bla")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid4() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein4.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("No celldesigner:extension")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid5() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein5.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("ann_unk")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid6() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein6.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("No celldesigner:speciesIdentity")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid7() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein7.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("unkPos")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid8() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein8.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("Species node in Sbml model doesn't contain")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid9() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein9.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("unknown_protein_class")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid10() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein10.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("Wrong class type for protein reference")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid11() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein11.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("Wrong class type for gene reference")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid12() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein12.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("Wrong class type for rna reference")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid13() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein13.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("Wrong class type for antisense rna reference")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testParseInvalid14() throws Exception { + try { + String xmlString = readFile("testFiles/invalid/invalid_sbml_protein14.xml"); + parser.parseXmlElement(xmlString); + fail("Exception expected"); + } catch (InvalidXmlSchemaException e) { + assertTrue(e.getMessage().contains("uknNode")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToXmlWithDefaultCompartment() throws Exception { + try { + CellDesignerGenericProtein species = new CellDesignerGenericProtein(); + String xml = parser.toXml(species.createModelElement("EL_ID")); + assertTrue(xml.contains("EL_ID")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidSpeciesIdentityToXml() throws Exception { + try { + Species species = Mockito.mock(Species.class); + parser.speciesIdentityToXml(species); + fail("Excepiton expected"); + } catch (InvalidArgumentException e) { + assertTrue(e.getMessage().contains("Invalid species class")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSpeciesIdentityToXml() throws Exception { + try { + GenericProtein species = new GenericProtein("xx"); + species.setHypothetical(true); + String xml = parser.speciesIdentityToXml(species); + assertTrue(xml.contains("<celldesigner:hypothetical>true</celldesigner:hypothetical>")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSpeciesStateToXml() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.setHomodimer(2); + state.setStructuralState("xxxState"); + String xml = parser.speciesStateToXml(state); + assertTrue(xml.contains("xxxState")); + assertTrue(xml.contains("celldesigner:homodimer")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.addModificationResidue(new CellDesignerModificationResidue()); + CellDesignerComplexSpecies species = new CellDesignerComplexSpecies(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Modification not supported in Complex")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies2() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.setStructuralState("state"); + CellDesignerGene species = new CellDesignerGene(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("StructuralState not supported in Gene")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies3() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.setStructuralState("state"); + CellDesignerRna species = new CellDesignerRna(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Structural state not supported in RNA")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies4() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.addModificationResidue(new CellDesignerModificationResidue()); + CellDesignerSimpleMolecule species = new CellDesignerSimpleMolecule(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Modification not supported in SimpleMolecule")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies5() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.setStructuralState("state"); + CellDesignerSimpleMolecule species = new CellDesignerSimpleMolecule(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Structural state not supported in SimpleMolecule")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies6() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.setStructuralState("state"); + CellDesignerAntisenseRna species = new CellDesignerAntisenseRna(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Structural state not supported in AntisenseRna")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies7() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.setStructuralState("state"); + CellDesignerSpecies<?> species = new CellDesignerSpecies<Gene>(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Structural state not supported")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessInvalidStateDataInSpecies8() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.addModificationResidue(new CellDesignerModificationResidue()); + CellDesignerSpecies<?> species = new CellDesignerSpecies<Gene>(); + + parser.processStateDataInSpecies(species, state); + fail("Exception expected"); + } catch (NotImplementedException e) { + assertTrue(e.getMessage().contains("Modification not supported in")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProcessAntisenseRnaStateDataInSpecies() throws Exception { + try { + SpeciesState state = new SpeciesState(); + state.addModificationResidue(new CellDesignerModificationResidue()); + CellDesignerAntisenseRna species = new CellDesignerAntisenseRna(); + + parser.processStateDataInSpecies(species, state); + + assertEquals(1, species.getRegions().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCreateRnaRegion() throws Exception { + try { + CellDesignerModificationResidue mr = new CellDesignerModificationResidue(); + mr.setSize(1.0); + mr.setAngle(1.0); + + CellDesignerRnaRegion region = parser.createRnaRegion(mr); + assertNotNull(region.getPos()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCreateAntisenseRnaRegion() throws Exception { + try { + CellDesignerModificationResidue mr = new CellDesignerModificationResidue(); + mr.setSize(1.0); + mr.setAngle(1.0); + + CellDesignerAntisenseRnaRegion region = parser.createAntisenseRnaRegion(mr); + assertNotNull(region.getPos()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesTest.java index bbc8f26a2fa2badf0232812318b3316138577733..6bf57cf435dd744eda73613d04e1cda723da2f05 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/structure/SpeciesTest.java @@ -11,327 +11,348 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions; import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.kinetics.SbmlUnitType; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Rna; public class SpeciesTest extends CellDesignerTestFunctions { - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new CellDesignerSpecies<GenericProtein>()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - String elementId = "51"; - Integer initialAmount = 54; - Integer initialConcentration = 58; - Integer charge = 59; - Boolean onlySubstanceUnits = true; - - String trueStr = "true"; - assertFalse(species.isHypothetical()); - species.setHypothetical(trueStr); - assertTrue(species.isHypothetical()); - - species.setElementId(elementId); - assertEquals(elementId, species.getElementId()); - - species.setInitialAmount(initialAmount); - assertEquals(initialAmount, species.getInitialAmount()); - - species.setOnlySubstanceUnits(onlySubstanceUnits); - assertEquals(onlySubstanceUnits, species.getOnlySubstanceUnits()); - - species.setInitialConcentration(initialConcentration); - assertEquals(initialConcentration, species.getInitialConcentration()); - - species.setCharge(charge); - - assertEquals(charge, species.getCharge()); - - species.setElementId(""); - assertEquals("", species.getElementId()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - String id = "as_id"; - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(id); - assertEquals(id, species.getElementId()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetId() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setElementId(""); - species.setElementId("xx"); - try { - species.setElementId("yy"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - - } - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate1() { - try { - int warningsCount = getWarnings().size(); - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setName("A"); - species.setNotes("XXX"); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.setName("B"); - species.update(species2); - int warningsCount2 = getWarnings().size(); - assertEquals(1, warningsCount2 - warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate2() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setNotes("XXX"); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.addMiriamData(new MiriamData()); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate3() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setNotes("XXX"); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.setNotes("xx"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate4() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setNotes("XX"); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.setNotes("xxX"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - assertEquals(3, species.getNotes().length()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate5() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setNotes("XX"); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.setNotes("a as x"); - species2.setHypothetical(true); - species2.setSymbol("sym"); - species2.setHomodimer(2); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate6() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setSymbol("sym1"); - species.setFullName("a_sym1"); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.setSymbol("sym2"); - species2.setFullName("b_sym1"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(2, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate7() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); - species2.addSynonym("syn"); - species2.addFormerSymbol("sym"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetInitialAmount() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setInitialAmount("1"); - assertEquals((Integer) 1, species.getInitialAmount()); - try { - species.setInitialAmount("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setInitialAmount("1"); - species.setInitialAmount((String) null); - assertNull(species.getInitialAmount()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetCharge() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setCharge("1"); - assertEquals((Integer) 1, species.getCharge()); - try { - species.setCharge("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setCharge("1"); - species.setCharge((String) null); - assertNull(species.getCharge()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetOnlySubstanceUnits() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setOnlySubstanceUnits("true"); - assertTrue(species.getOnlySubstanceUnits()); - try { - species.setOnlySubstanceUnits("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setOnlySubstanceUnits("false"); - assertFalse(species.getOnlySubstanceUnits()); - species.setOnlySubstanceUnits((String) null); - assertNull(species.getOnlySubstanceUnits()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetInitialConcentration() { - try { - CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); - species.setInitialConcentration("1"); - assertEquals((Integer) 1, species.getInitialConcentration()); - try { - species.setInitialConcentration("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setInitialConcentration("1"); - species.setInitialConcentration((String) null); - assertNull(species.getInitialConcentration()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCreateInvalidElement() { - try { - CellDesignerSpecies<?> complex = new CellDesignerSpecies<Rna>(); - complex.createModelElement("id"); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new CellDesignerSpecies<GenericProtein>()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + String elementId = "51"; + Double initialAmount = 54.0; + Double initialConcentration = 58.0; + Integer charge = 59; + Boolean onlySubstanceUnits = true; + + String trueStr = "true"; + assertFalse(species.isHypothetical()); + species.setHypothetical(trueStr); + assertTrue(species.isHypothetical()); + + species.setElementId(elementId); + assertEquals(elementId, species.getElementId()); + + species.setInitialAmount(initialAmount); + assertEquals(initialAmount, species.getInitialAmount()); + + species.setOnlySubstanceUnits(onlySubstanceUnits); + assertEquals(onlySubstanceUnits, species.getOnlySubstanceUnits()); + + species.setInitialConcentration(initialConcentration); + assertEquals(initialConcentration, species.getInitialConcentration()); + + species.setCharge(charge); + + assertEquals(charge, species.getCharge()); + + species.setElementId(""); + assertEquals("", species.getElementId()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + String id = "as_id"; + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(id); + assertEquals(id, species.getElementId()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + String id = "as_id"; + CellDesignerSpecies<GenericProtein> species = new CellDesignerSpecies<>(id); + species.setBoundaryCondition(true); + species.setConstant(true); + species.setSubstanceUnits(SbmlUnitType.COULUMB); + CellDesignerSpecies<?> copy = species.copy(); + assertEquals(id, species.getElementId()); + assertEquals(Boolean.TRUE, copy.isBoundaryCondition()); + assertEquals(Boolean.TRUE, copy.isConstant()); + assertEquals(SbmlUnitType.COULUMB, copy.getSubstanceUnit()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetId() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setElementId(""); + species.setElementId("xx"); + try { + species.setElementId("yy"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate1() { + try { + int warningsCount = getWarnings().size(); + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setName("A"); + species.setNotes("XXX"); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.setName("B"); + species.update(species2); + int warningsCount2 = getWarnings().size(); + assertEquals(1, warningsCount2 - warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate2() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setNotes("XXX"); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.addMiriamData(new MiriamData()); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate3() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setNotes("XXX"); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.setNotes("xx"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate4() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setNotes("XX"); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.setNotes("xxX"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + assertEquals(3, species.getNotes().length()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate5() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setNotes("XX"); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.setNotes("a as x"); + species2.setHypothetical(true); + species2.setSymbol("sym"); + species2.setHomodimer(2); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate6() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setSymbol("sym1"); + species.setFullName("a_sym1"); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.setSymbol("sym2"); + species2.setFullName("b_sym1"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(2, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate7() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + CellDesignerSpecies<?> species2 = new CellDesignerSpecies<GenericProtein>(); + species2.addSynonym("syn"); + species2.addFormerSymbol("sym"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetInitialAmount() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setInitialAmount("1"); + assertEquals(1, species.getInitialAmount(), Configuration.EPSILON); + try { + species.setInitialAmount("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setInitialAmount("1"); + species.setInitialAmount((String) null); + assertNull(species.getInitialAmount()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetCharge() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setCharge("1"); + assertEquals((Integer) 1, species.getCharge()); + try { + species.setCharge("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setCharge("1"); + species.setCharge((String) null); + assertNull(species.getCharge()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetOnlySubstanceUnits() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setOnlySubstanceUnits("true"); + assertTrue(species.getOnlySubstanceUnits()); + try { + species.setOnlySubstanceUnits("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setOnlySubstanceUnits("false"); + assertFalse(species.getOnlySubstanceUnits()); + species.setOnlySubstanceUnits((String) null); + assertNull(species.getOnlySubstanceUnits()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetInitialConcentration() { + try { + CellDesignerSpecies<?> species = new CellDesignerSpecies<GenericProtein>(); + species.setInitialConcentration("1"); + assertEquals(1, species.getInitialConcentration(), Configuration.EPSILON); + try { + species.setInitialConcentration("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setInitialConcentration("1"); + species.setInitialConcentration((String) null); + assertNull(species.getInitialConcentration()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCreateInvalidElement() { + try { + CellDesignerSpecies<?> complex = new CellDesignerSpecies<Rna>(); + complex.createModelElement("id"); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/converter-CellDesigner/testFiles/elements_with_kinetic_data.xml b/converter-CellDesigner/testFiles/elements_with_kinetic_data.xml new file mode 100644 index 0000000000000000000000000000000000000000..19cbcdbf58dbd89805b4e9632c35c6037b287510 --- /dev/null +++ b/converter-CellDesigner/testFiles/elements_with_kinetic_data.xml @@ -0,0 +1,117 @@ +<?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="172.0" y="155.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="308.0" y="154.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:protein id="pr2" name="s2" type="GENERIC"/> +</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="2.5" substanceUnits="gram" hasOnlySubstanceUnits="true" boundaryCondition="true" charge="0" constant="true"> +<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="s2" compartment="default" initialConcentration="3.7" substanceUnits="mole" charge="0"> +<annotation> +<celldesigner:extension> +<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment> +<celldesigner:speciesIdentity> +<celldesigner:class>PROTEIN</celldesigner:class> +<celldesigner:proteinReference>pr2</celldesigner:proteinReference> +</celldesigner:speciesIdentity> +</celldesigner:extension> +</annotation> +</species> +</listOfSpecies> +</model> +</sbml> diff --git a/converter-CellDesigner/testFiles/kinetics/species_with_kinetics_param.xml b/converter-CellDesigner/testFiles/kinetics/species_with_kinetics_param.xml new file mode 100644 index 0000000000000000000000000000000000000000..c518b80d9dfe16058e338208460a784aa44e5710 --- /dev/null +++ b/converter-CellDesigner/testFiles/kinetics/species_with_kinetics_param.xml @@ -0,0 +1,11 @@ +<species metaid="s2" id="s2" name="s2" compartment="default" initialConcentration="3.7" substanceUnits="mole" charge="0"> +<annotation> +<celldesigner:extension> +<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment> +<celldesigner:speciesIdentity> +<celldesigner:class>PROTEIN</celldesigner:class> +<celldesigner:proteinReference>pr2</celldesigner:proteinReference> +</celldesigner:speciesIdentity> +</celldesigner:extension> +</annotation> +</species> diff --git a/converter-CellDesigner/testFiles/kinetics/species_with_kinetics_param2.xml b/converter-CellDesigner/testFiles/kinetics/species_with_kinetics_param2.xml new file mode 100644 index 0000000000000000000000000000000000000000..c83c5c0b21a3659fb30ce323d06b1b9a09c4f6aa --- /dev/null +++ b/converter-CellDesigner/testFiles/kinetics/species_with_kinetics_param2.xml @@ -0,0 +1,11 @@ +<species metaid="s1" id="s1" name="s1" compartment="default" initialAmount="2.5" substanceUnits="gram" hasOnlySubstanceUnits="true" boundaryCondition="true" charge="0" constant="true"> +<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> diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/GenericProtein.java b/model/src/main/java/lcsb/mapviewer/model/map/species/GenericProtein.java index 428c069554b76f5326e73dc1f5832d705447936b..d3b1db81c7e052d1e07fdde67aab58b04b2447d2 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/GenericProtein.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/GenericProtein.java @@ -15,44 +15,44 @@ import lcsb.mapviewer.common.exception.NotImplementedException; @DiscriminatorValue("GENERIC_PROTEIN_ALIAS") public class GenericProtein extends Protein { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Empty constructor required by hibernate. - */ - GenericProtein() { - } - - /** - * Default constructor. - * - * @param elementId - * uniqe (within model) element identifier - */ - public GenericProtein(String elementId) { - super(elementId); - } - - /** - * Constructor that creates a copy of the element given in the parameter. - * - * @param original - * original object that will be used for creating copy - */ - public GenericProtein(GenericProtein original) { - super(original); - } - - @Override - public GenericProtein copy() { - if (this.getClass() == GenericProtein.class) { - return new GenericProtein(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Empty constructor required by hibernate. + */ + GenericProtein() { + } + + /** + * Default constructor. + * + * @param elementId + * unique (within model) element identifier + */ + public GenericProtein(String elementId) { + super(elementId); + } + + /** + * Constructor that creates a copy of the element given in the parameter. + * + * @param original + * original object that will be used for creating copy + */ + public GenericProtein(GenericProtein original) { + super(original); + } + + @Override + public GenericProtein copy() { + if (this.getClass() == GenericProtein.class) { + return new GenericProtein(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java index 7fadc2e18f348c095c984d176ebb93d2b2a3643a..9e891ddd9df99c9d85a2449c86e9a43128b29295 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Protein.java @@ -24,101 +24,102 @@ import lcsb.mapviewer.model.map.species.field.ModificationResidue; @DiscriminatorValue("PROTEIN_ALIAS") public abstract class Protein extends Species { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * State of the protein. - */ - private String structuralState = null; - - /** - * List of modifications for the Protein. - */ - @Cascade({ CascadeType.ALL }) - @OneToMany(mappedBy = "species", orphanRemoval = true) - @LazyCollection(LazyCollectionOption.FALSE) - private List<ModificationResidue> modificationResidues = new ArrayList<>(); - - /** - * Empty constructor required by hibernate. - */ - Protein() { - } - - /** - * Constructor that creates a copy of the element given in the parameter. - * - * @param original - * original object that will be used for creating copy - */ - protected Protein(Protein original) { - super(original); - this.structuralState = original.getStructuralState(); - for (ModificationResidue mr : original.getModificationResidues()) { - addModificationResidue(new ModificationResidue(mr)); - } - } - - - /** - * Default constructor. - * - * @param elementId - * uniqe (within model) element identifier - */ - protected Protein(String elementId) { - super(elementId); - } - - /** - * Adds modification to the protein. - * - * @param modificationResidue - * modification to add - */ - public void addModificationResidue(ModificationResidue modificationResidue) { - modificationResidues.add(modificationResidue); - modificationResidue.setSpecies(this); - } - - /** - * @return the modificationResidues - * @see #modificationResidues - */ - public List<ModificationResidue> getModificationResidues() { - return modificationResidues; - } - - /** - * @param modificationResidues the modificationResidues to set - * @see #modificationResidues - */ - public void setModificationResidues(List<ModificationResidue> modificationResidues) { - this.modificationResidues = modificationResidues; - } - - /** - * @return the structuralState - * @see #structuralState - */ - public String getStructuralState() { - return structuralState; - } - - /** - * @param structuralState the structuralState to set - * @see #structuralState - */ - public void setStructuralState(String structuralState) { - this.structuralState = structuralState; - } - - @Override - public String getStringType() { - return "Protein"; - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * State of the protein. + */ + private String structuralState = null; + + /** + * List of modifications for the Protein. + */ + @Cascade({ CascadeType.ALL }) + @OneToMany(mappedBy = "species", orphanRemoval = true) + @LazyCollection(LazyCollectionOption.FALSE) + private List<ModificationResidue> modificationResidues = new ArrayList<>(); + + /** + * Empty constructor required by hibernate. + */ + Protein() { + } + + /** + * Constructor that creates a copy of the element given in the parameter. + * + * @param original + * original object that will be used for creating copy + */ + protected Protein(Protein original) { + super(original); + this.structuralState = original.getStructuralState(); + for (ModificationResidue mr : original.getModificationResidues()) { + addModificationResidue(new ModificationResidue(mr)); + } + } + + /** + * Default constructor. + * + * @param elementId + * unique (within model) element identifier + */ + protected Protein(String elementId) { + super(elementId); + } + + /** + * Adds modification to the protein. + * + * @param modificationResidue + * modification to add + */ + public void addModificationResidue(ModificationResidue modificationResidue) { + modificationResidues.add(modificationResidue); + modificationResidue.setSpecies(this); + } + + /** + * @return the modificationResidues + * @see #modificationResidues + */ + public List<ModificationResidue> getModificationResidues() { + return modificationResidues; + } + + /** + * @param modificationResidues + * the modificationResidues to set + * @see #modificationResidues + */ + public void setModificationResidues(List<ModificationResidue> modificationResidues) { + this.modificationResidues = modificationResidues; + } + + /** + * @return the structuralState + * @see #structuralState + */ + public String getStructuralState() { + return structuralState; + } + + /** + * @param structuralState + * the structuralState to set + * @see #structuralState + */ + public void setStructuralState(String structuralState) { + this.structuralState = structuralState; + } + + @Override + public String getStringType() { + return "Protein"; + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Species.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Species.java index f1acb7f47bcdd6dc4fe20a5dcf2898965f189ba6..5f8e2f0b25a71707b272617b7c86e8e7390505ed 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Species.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Species.java @@ -16,6 +16,8 @@ import org.apache.log4j.Logger; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; +import lcsb.mapviewer.model.map.kinetics.SbmlUnit; +import lcsb.mapviewer.model.map.kinetics.SbmlUnitType; import lcsb.mapviewer.model.map.species.field.PositionToCompartment; import lcsb.mapviewer.model.map.species.field.UniprotRecord; @@ -81,7 +83,7 @@ public abstract class Species extends Element { /** * Initial amount of species. */ - private Integer initialAmount = null; + private Double initialAmount = null; /** * Charge of the species. @@ -91,7 +93,7 @@ public abstract class Species extends Element { /** * Initial concentration of species. */ - private Integer initialConcentration = null; + private Double initialConcentration = null; /** * Is only substance units allowed. @@ -121,6 +123,12 @@ public abstract class Species extends Element { @OneToMany(fetch = FetchType.EAGER, mappedBy = "species", orphanRemoval = true) private Set<UniprotRecord> uniprots = new HashSet<>(); + private Boolean boundaryCondition; + + private Boolean constant; + + private SbmlUnitType substanceUnits; + /** * Constructor that set element identifier. * @@ -167,6 +175,9 @@ public abstract class Species extends Element { homodimer = original.getHomodimer(); positionToCompartment = original.getPositionToCompartment(); hypothetical = original.getHypothetical(); + boundaryCondition = original.getBoundaryCondition(); + constant = original.getConstant(); + substanceUnits = original.getSubstanceUnits(); uniprots = original.getUniprots(); @@ -282,7 +293,7 @@ public abstract class Species extends Element { * @return the initialAmount * @see #initialAmount */ - public Integer getInitialAmount() { + public Double getInitialAmount() { return initialAmount; } @@ -291,7 +302,7 @@ public abstract class Species extends Element { * the initialAmount to set * @see #initialAmount */ - public void setInitialAmount(Integer initialAmount) { + public void setInitialAmount(Double initialAmount) { this.initialAmount = initialAmount; } @@ -316,7 +327,7 @@ public abstract class Species extends Element { * @return the initialConcentration * @see #initialConcentration */ - public Integer getInitialConcentration() { + public Double getInitialConcentration() { return initialConcentration; } @@ -325,7 +336,7 @@ public abstract class Species extends Element { * the initialConcentration to set * @see #initialConcentration */ - public void setInitialConcentration(Integer initialConcentration) { + public void setInitialConcentration(Double initialConcentration) { this.initialConcentration = initialConcentration; } @@ -435,4 +446,42 @@ public abstract class Species extends Element { return hypothetical; } + public boolean isBoundaryCondition() { + if (boundaryCondition == null) { + return false; + } + return boundaryCondition; + } + + public Boolean getBoundaryCondition() { + return boundaryCondition; + } + + public void setBoundaryCondition(Boolean boundaryCondition) { + this.boundaryCondition = boundaryCondition; + } + + public boolean isConstant() { + if (constant == null) { + return false; + } + return constant; + } + + public Boolean getConstant() { + return constant; + } + + public SbmlUnitType getSubstanceUnits() { + return substanceUnits; + } + + public void setConstant(Boolean constant) { + this.constant = constant; + } + + public void setSubstanceUnits(SbmlUnitType substanceUnits) { + this.substanceUnits = substanceUnits; + } + } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java index c3e6141b3b7c8a617dabd4e661ea7d8cfa2b5b3e..39434f3526dbacd60c944d2d3054d2aa5ef24f6a 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java @@ -87,9 +87,9 @@ public class SpeciesComparator extends Comparator<Species> { return stringComparator.compare(arg0.getStatePrefix(), arg1.getStatePrefix()); } - if (integerComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()) != 0) { + if (doubleComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()) != 0) { logger.debug("Initial amount different: " + arg0.getInitialAmount() + ", " + arg1.getInitialAmount()); - return integerComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()); + return doubleComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()); } if (integerComparator.compare(arg0.getCharge(), arg1.getCharge()) != 0) { @@ -102,10 +102,10 @@ public class SpeciesComparator extends Comparator<Species> { return integerComparator.compare(arg0.getHomodimer(), arg1.getHomodimer()); } - if (integerComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()) != 0) { + if (doubleComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()) != 0) { logger.debug( "Initial concentration different: " + arg0.getInitialConcentration() + ", " + arg1.getInitialConcentration()); - return integerComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()); + return doubleComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()); } if (booleanComparator.compare(arg0.hasOnlySubstanceUnits(), arg1.hasOnlySubstanceUnits()) != 0) { diff --git a/model/src/test/java/lcsb/mapviewer/AllTests.java b/model/src/test/java/lcsb/mapviewer/AllTests.java index 95fc5378830086cd2232c50cce02ef7ab459c59b..cfbbd296b9afd343f69799326901595767c227c5 100644 --- a/model/src/test/java/lcsb/mapviewer/AllTests.java +++ b/model/src/test/java/lcsb/mapviewer/AllTests.java @@ -8,8 +8,8 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ AllModelTests.class,// - AllMapUtilTests.class,// +@SuiteClasses({ AllModelTests.class, // + AllMapUtilTests.class,// }) public class AllTests { diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/ElementComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/ElementComparatorTest.java index 7a6bdc24d0d6d341dcc54f14d386f532ac75b869..19058bdb84912d2348935f323bebf8ccbc274d5b 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/ElementComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/ElementComparatorTest.java @@ -27,296 +27,295 @@ import lcsb.mapviewer.model.map.species.field.PositionToCompartment; public class ElementComparatorTest { - ElementComparator comparator = new ElementComparator(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testCompareException() throws Exception { - try { - comparator.compare(Mockito.mock(Element.class), Mockito.mock(Element.class)); - - fail("Exception should occur"); - } catch (NotImplementedException e) { - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testDifferent() throws Exception { - try { - assertTrue(comparator.compare(new GenericProtein("id2"), new GenericProtein("id1")) != 0); - - assertTrue(comparator.compare(null, new GenericProtein()) != 0); - assertTrue(comparator.compare(new GenericProtein(), null) != 0); - assertTrue(comparator.compare(new GenericProtein(), new Complex()) != 0); - - Species sa1 = new GenericProtein("id2"); - Species sa2 = new GenericProtein("id2"); - sa2.setX(2); - assertTrue(comparator.compare(sa1, sa2) != 0); - - sa1 = new GenericProtein("id2"); - sa2 = new GenericProtein("id2"); - sa2.setY(2); - assertTrue(comparator.compare(sa1, sa2) != 0); - - sa1 = new GenericProtein("id2"); - sa2 = new GenericProtein("id2"); - sa2.setHeight(2); - assertTrue(comparator.compare(sa1, sa2) != 0); - - sa1 = new GenericProtein("id2"); - sa2 = new GenericProtein("id2"); - sa2.setFontSize(2); - assertTrue(comparator.compare(sa1, sa2) != 0); - - sa1 = new GenericProtein("id2"); - sa2 = new GenericProtein("id2"); - sa2.setColor(Color.BLUE); - assertTrue(comparator.compare(sa1, sa2) != 0); - - sa1 = new GenericProtein("id2"); - sa2 = new GenericProtein("id2"); - sa2.setVisibilityLevel(6); - assertTrue(comparator.compare(sa1, sa2) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCompareSubmodel() throws Exception { - try { - Element element1 = createElement(); - Element element2 = createElement(); - assertEquals(0, comparator.compare(element1, element2)); - - element1.setSubmodel(null); - assertTrue(comparator.compare(element1, element2) != 0); - assertTrue(comparator.compare(element2, element1) != 0); - - element1 = createElement(); - element2 = createElement(); - - element1.getSubmodel().setName("Na"); - - assertTrue(comparator.compare(element1, element2) != 0); - assertTrue(comparator.compare(element2, element1) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - private Element createElement() { - Element result = new GenericProtein("id2"); - ElementSubmodelConnection submodel = new ElementSubmodelConnection(getModel(), SubmodelType.DOWNSTREAM_TARGETS); - result.setSubmodel(submodel); - return result; - } - - private Model getModel() { - Model model = new ModelFullIndexed(null); - - model.setNotes("Some description"); - GenericProtein protein = new GenericProtein("A"); - protein.setName("ad"); - model.addElement(protein); - - Protein protein2 = new GenericProtein("a_id"); - protein2.setName("ad"); - model.addElement(protein2); - - model.addElement(new Compartment("default")); - - Layer layer = new Layer(); - layer.setName("layer name"); - model.addLayer(layer); - - model.addReaction(new Reaction()); - return model; - } - - - @Test - public void testException() { - try { - Element el = Mockito.mock(Element.class); - comparator.compare(el, el); - - fail("Exception should occur"); - } catch (NotImplementedException e) { - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInternalCompare() { - try { - SimpleMolecule species1 = createSimpleMolecule(); - assertTrue(comparator.internalCompare(species1, null) != 0); - assertTrue(comparator.internalCompare(null, species1) != 0); - - assertEquals(0, comparator.internalCompare(null, null)); - - } catch (InvalidClassException e) { - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testDifferent2() { - try { - SimpleMolecule species1 = createSimpleMolecule(); - SimpleMolecule species2 = createSimpleMolecule(); - - species1.setCharge(99); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setHomodimer(233); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setFormula("a"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setElementId(""); - species1.setElementId("ASD"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setNotes("ASD"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setPositionToCompartment(PositionToCompartment.INSIDE); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.getMiriamData().clear(); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.getMiriamData().iterator().next().setRelationType(MiriamRelationType.BQ_BIOL_HAS_PART); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.addMiriamData(new MiriamData()); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - assertTrue(comparator.compare(species1, null) != 0); - assertTrue(comparator.compare(null, species1) != 0); - - } catch (Exception e) { - e.printStackTrace(); - fail("Unkowne exception"); - } - } - - @Test - public void testDifferentNewFields() throws Exception { - try { - SimpleMolecule species1 = createSimpleMolecule(); - SimpleMolecule species2 = createSimpleMolecule(); - - species1.setSymbol("some symbol"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - - species1.setFullName("some symbol"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - - species1.getSynonyms().add("asd"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - - species1.getFormerSymbols().add("asd"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - public SimpleMolecule createSimpleMolecule() { - SimpleMolecule result = new SimpleMolecule("id"); - result.setHomodimer(12); - result.setName("id"); - result.setInitialAmount(12); - result.setCharge(13); - result.setInitialConcentration(14); - result.setOnlySubstanceUnits(true); - result.setPositionToCompartment(PositionToCompartment.TRANSMEMBRANE); - result.setNotes("id"); - MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "c"); - result.addMiriamData(md); - return result; - } - - @Test - public void testDifferentNewReconFields() throws Exception { - try { - SimpleMolecule element1 = createSimpleMolecule(); - - SimpleMolecule element2 = createSimpleMolecule(); - element2.setAbbreviation("ABRR"); - - assertTrue(comparator.compare(element1, element2) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + ElementComparator comparator = new ElementComparator(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testCompareException() throws Exception { + try { + comparator.compare(Mockito.mock(Element.class), Mockito.mock(Element.class)); + + fail("Exception should occur"); + } catch (NotImplementedException e) { + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testDifferent() throws Exception { + try { + assertTrue(comparator.compare(new GenericProtein("id2"), new GenericProtein("id1")) != 0); + + assertTrue(comparator.compare(null, new GenericProtein()) != 0); + assertTrue(comparator.compare(new GenericProtein(), null) != 0); + assertTrue(comparator.compare(new GenericProtein(), new Complex()) != 0); + + Species sa1 = new GenericProtein("id2"); + Species sa2 = new GenericProtein("id2"); + sa2.setX(2); + assertTrue(comparator.compare(sa1, sa2) != 0); + + sa1 = new GenericProtein("id2"); + sa2 = new GenericProtein("id2"); + sa2.setY(2); + assertTrue(comparator.compare(sa1, sa2) != 0); + + sa1 = new GenericProtein("id2"); + sa2 = new GenericProtein("id2"); + sa2.setHeight(2); + assertTrue(comparator.compare(sa1, sa2) != 0); + + sa1 = new GenericProtein("id2"); + sa2 = new GenericProtein("id2"); + sa2.setFontSize(2); + assertTrue(comparator.compare(sa1, sa2) != 0); + + sa1 = new GenericProtein("id2"); + sa2 = new GenericProtein("id2"); + sa2.setColor(Color.BLUE); + assertTrue(comparator.compare(sa1, sa2) != 0); + + sa1 = new GenericProtein("id2"); + sa2 = new GenericProtein("id2"); + sa2.setVisibilityLevel(6); + assertTrue(comparator.compare(sa1, sa2) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCompareSubmodel() throws Exception { + try { + Element element1 = createElement(); + Element element2 = createElement(); + assertEquals(0, comparator.compare(element1, element2)); + + element1.setSubmodel(null); + assertTrue(comparator.compare(element1, element2) != 0); + assertTrue(comparator.compare(element2, element1) != 0); + + element1 = createElement(); + element2 = createElement(); + + element1.getSubmodel().setName("Na"); + + assertTrue(comparator.compare(element1, element2) != 0); + assertTrue(comparator.compare(element2, element1) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private Element createElement() { + Element result = new GenericProtein("id2"); + ElementSubmodelConnection submodel = new ElementSubmodelConnection(getModel(), SubmodelType.DOWNSTREAM_TARGETS); + result.setSubmodel(submodel); + return result; + } + + private Model getModel() { + Model model = new ModelFullIndexed(null); + + model.setNotes("Some description"); + GenericProtein protein = new GenericProtein("A"); + protein.setName("ad"); + model.addElement(protein); + + Protein protein2 = new GenericProtein("a_id"); + protein2.setName("ad"); + model.addElement(protein2); + + model.addElement(new Compartment("default")); + + Layer layer = new Layer(); + layer.setName("layer name"); + model.addLayer(layer); + + model.addReaction(new Reaction()); + return model; + } + + @Test + public void testException() { + try { + Element el = Mockito.mock(Element.class); + comparator.compare(el, el); + + fail("Exception should occur"); + } catch (NotImplementedException e) { + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInternalCompare() { + try { + SimpleMolecule species1 = createSimpleMolecule(); + assertTrue(comparator.internalCompare(species1, null) != 0); + assertTrue(comparator.internalCompare(null, species1) != 0); + + assertEquals(0, comparator.internalCompare(null, null)); + + } catch (InvalidClassException e) { + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testDifferent2() { + try { + SimpleMolecule species1 = createSimpleMolecule(); + SimpleMolecule species2 = createSimpleMolecule(); + + species1.setCharge(99); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setHomodimer(233); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setFormula("a"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setElementId(""); + species1.setElementId("ASD"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setNotes("ASD"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setPositionToCompartment(PositionToCompartment.INSIDE); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.getMiriamData().clear(); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.getMiriamData().iterator().next().setRelationType(MiriamRelationType.BQ_BIOL_HAS_PART); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.addMiriamData(new MiriamData()); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + assertTrue(comparator.compare(species1, null) != 0); + assertTrue(comparator.compare(null, species1) != 0); + + } catch (Exception e) { + e.printStackTrace(); + fail("Unkowne exception"); + } + } + + @Test + public void testDifferentNewFields() throws Exception { + try { + SimpleMolecule species1 = createSimpleMolecule(); + SimpleMolecule species2 = createSimpleMolecule(); + + species1.setSymbol("some symbol"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + + species1.setFullName("some symbol"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + + species1.getSynonyms().add("asd"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + + species1.getFormerSymbols().add("asd"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + public SimpleMolecule createSimpleMolecule() { + SimpleMolecule result = new SimpleMolecule("id"); + result.setHomodimer(12); + result.setName("id"); + result.setInitialAmount(12.0); + result.setCharge(13); + result.setInitialConcentration(14.0); + result.setOnlySubstanceUnits(true); + result.setPositionToCompartment(PositionToCompartment.TRANSMEMBRANE); + result.setNotes("id"); + MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "c"); + result.addMiriamData(md); + return result; + } + + @Test + public void testDifferentNewReconFields() throws Exception { + try { + SimpleMolecule element1 = createSimpleMolecule(); + + SimpleMolecule element2 = createSimpleMolecule(); + element2.setAbbreviation("ABRR"); + + assertTrue(comparator.compare(element1, element2) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesComparatorTest.java index 68c0c063dab9fe368b8e8c708ca1778266f6e8a8..869efc203a3383e76b9cf9f1563f2c35a1f40be7 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesComparatorTest.java @@ -19,270 +19,270 @@ import lcsb.mapviewer.model.map.species.field.PositionToCompartment; public class SpeciesComparatorTest { - SpeciesComparator comparator = new SpeciesComparator(); + SpeciesComparator comparator = new SpeciesComparator(); - @Before - public void setUp() throws Exception { - } + @Before + public void setUp() throws Exception { + } - @After - public void tearDown() throws Exception { - } + @After + public void tearDown() throws Exception { + } - @Test - public void testEquals() { - try { - Species species1 = createSpecies(); - Species species2 = createSpecies(); + @Test + public void testEquals() { + try { + Species species1 = createSpecies(); + Species species2 = createSpecies(); - assertEquals(0, comparator.compare(species1, species2)); + assertEquals(0, comparator.compare(species1, species2)); - assertEquals(0, comparator.compare(null, null)); + assertEquals(0, comparator.compare(null, null)); - assertEquals(0, comparator.compare(new Complex(), new Complex())); + assertEquals(0, comparator.compare(new Complex(), new Complex())); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - @Test - public void testCompareInvalid() { - try { + @Test + public void testCompareInvalid() { + try { - Species speciesMock = Mockito.mock(Species.class); - comparator.compare(speciesMock, speciesMock); - fail("Exception expected"); + Species speciesMock = Mockito.mock(Species.class); + comparator.compare(speciesMock, speciesMock); + fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - fail("Unkowne exception"); - } - } + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + fail("Unkowne exception"); + } + } - private Species createSpecies() { - GenericProtein result = new GenericProtein(); - result.setName("a"); + private Species createSpecies() { + GenericProtein result = new GenericProtein(); + result.setName("a"); - result.setElementId("asd"); - result.setX(12.0); - result.setY(123.0); - result.setWidth(4); - result.setHeight(5); - result.setFontSize(9.0); - result.setColor(Color.BLUE); - result.setVisibilityLevel(14); - result.setStateLabel("123"); - result.setStatePrefix("1234"); + result.setElementId("asd"); + result.setX(12.0); + result.setY(123.0); + result.setWidth(4); + result.setHeight(5); + result.setFontSize(9.0); + result.setColor(Color.BLUE); + result.setVisibilityLevel(14); + result.setStateLabel("123"); + result.setStatePrefix("1234"); - return result; - } + return result; + } - @Test - public void testDifferent() throws Exception { - try { - Species species1 = createSpecies(); - Species species2 = createSpecies(); + @Test + public void testDifferent() throws Exception { + try { + Species species1 = createSpecies(); + Species species2 = createSpecies(); - assertTrue(comparator.compare(species1, null) != 0); - assertTrue(comparator.compare(null, species1) != 0); + assertTrue(comparator.compare(species1, null) != 0); + assertTrue(comparator.compare(null, species1) != 0); - assertTrue(comparator.compare(new Complex(), species1) != 0); + assertTrue(comparator.compare(new Complex(), species1) != 0); - species1 = createSpecies(); - species2 = createSpecies(); + species1 = createSpecies(); + species2 = createSpecies(); - species1.setElementId("tmp"); + species1.setElementId("tmp"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); - species1 = createSpecies(); - species2 = createSpecies(); + species1 = createSpecies(); + species2 = createSpecies(); - species1.setStateLabel("tmp"); + species1.setStateLabel("tmp"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); - species1 = createSpecies(); - species2 = createSpecies(); + species1 = createSpecies(); + species2 = createSpecies(); - species1.setStatePrefix("tmp"); - - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSpecies(); - species2 = createSpecies(); - - species1.setName("new namne"); - - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSpecies(); - species2 = createSpecies(); - - species1.setActivity(true); - - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSpecies(); - species2 = createSpecies(); - - species1.setLineWidth(453.75); - - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testException() { - try { - Species mock = Mockito.mock(Species.class); - comparator.compare(mock, mock); - - fail("Exception expected"); - } catch (NotImplementedException e) { - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testEquals2() { - try { - SimpleMolecule species1 = createSimpleMolecule(); - SimpleMolecule species2 = createSimpleMolecule(); - assertEquals(0, comparator.compare(species1, species2)); - - assertEquals(0, comparator.compare(null, null)); - - assertEquals(0, comparator.compare(new AntisenseRna(), new AntisenseRna())); - assertEquals(0, comparator.compare(new Degraded(), new Degraded())); - assertEquals(0, comparator.compare(new Drug(), new Drug())); - assertEquals(0, comparator.compare(new Ion(), new Ion())); - assertEquals(0, comparator.compare(new Phenotype(), new Phenotype())); - assertEquals(0, comparator.compare(new Rna(), new Rna())); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testDifferent2() { - try { - SimpleMolecule species1 = createSimpleMolecule(); - SimpleMolecule species2 = createSimpleMolecule(); - - species1.setCharge(99); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - assertTrue(comparator.compare(null, species1) != 0); - assertTrue(comparator.compare(species1, null) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setHomodimer(1233); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setElementId(""); - species1.setElementId("ASD"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setNotes("ASD"); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setPositionToCompartment(PositionToCompartment.TRANSMEMBRANE); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.getMiriamData().clear(); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setInitialAmount(4); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setInitialConcentration(4); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setOnlySubstanceUnits(false); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.setHypothetical(true); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.getMiriamData().iterator().next().setRelationType(MiriamRelationType.BQ_BIOL_IS); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - species1 = createSimpleMolecule(); - species2 = createSimpleMolecule(); - species1.addMiriamData(new MiriamData()); - assertTrue(comparator.compare(species1, species2) != 0); - assertTrue(comparator.compare(species2, species1) != 0); - - assertTrue(comparator.compare(new Rna(), new Drug()) != 0); - - } catch (Exception e) { - e.printStackTrace(); - fail("Unkowne exception"); - } - } - - public SimpleMolecule createSimpleMolecule() { - SimpleMolecule result = new SimpleMolecule(); - result.setHomodimer(12); - result.setElementId("id"); - result.setName("id"); - result.setInitialAmount(12); - result.setCharge(13); - result.setInitialConcentration(14); - result.setOnlySubstanceUnits(true); - result.setPositionToCompartment(PositionToCompartment.INSIDE); - result.setNotes("id"); - MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.UNKNOWN, "c"); - result.addMiriamData(md); - return result; - } + species1.setStatePrefix("tmp"); + + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSpecies(); + species2 = createSpecies(); + + species1.setName("new namne"); + + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSpecies(); + species2 = createSpecies(); + + species1.setActivity(true); + + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSpecies(); + species2 = createSpecies(); + + species1.setLineWidth(453.75); + + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testException() { + try { + Species mock = Mockito.mock(Species.class); + comparator.compare(mock, mock); + + fail("Exception expected"); + } catch (NotImplementedException e) { + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testEquals2() { + try { + SimpleMolecule species1 = createSimpleMolecule(); + SimpleMolecule species2 = createSimpleMolecule(); + assertEquals(0, comparator.compare(species1, species2)); + + assertEquals(0, comparator.compare(null, null)); + + assertEquals(0, comparator.compare(new AntisenseRna(), new AntisenseRna())); + assertEquals(0, comparator.compare(new Degraded(), new Degraded())); + assertEquals(0, comparator.compare(new Drug(), new Drug())); + assertEquals(0, comparator.compare(new Ion(), new Ion())); + assertEquals(0, comparator.compare(new Phenotype(), new Phenotype())); + assertEquals(0, comparator.compare(new Rna(), new Rna())); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testDifferent2() { + try { + SimpleMolecule species1 = createSimpleMolecule(); + SimpleMolecule species2 = createSimpleMolecule(); + + species1.setCharge(99); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + assertTrue(comparator.compare(null, species1) != 0); + assertTrue(comparator.compare(species1, null) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setHomodimer(1233); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setElementId(""); + species1.setElementId("ASD"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setNotes("ASD"); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setPositionToCompartment(PositionToCompartment.TRANSMEMBRANE); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.getMiriamData().clear(); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setInitialAmount(4.0); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setInitialConcentration(4.0); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setOnlySubstanceUnits(false); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.setHypothetical(true); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.getMiriamData().iterator().next().setRelationType(MiriamRelationType.BQ_BIOL_IS); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + species1 = createSimpleMolecule(); + species2 = createSimpleMolecule(); + species1.addMiriamData(new MiriamData()); + assertTrue(comparator.compare(species1, species2) != 0); + assertTrue(comparator.compare(species2, species1) != 0); + + assertTrue(comparator.compare(new Rna(), new Drug()) != 0); + + } catch (Exception e) { + e.printStackTrace(); + fail("Unkowne exception"); + } + } + + public SimpleMolecule createSimpleMolecule() { + SimpleMolecule result = new SimpleMolecule(); + result.setHomodimer(12); + result.setElementId("id"); + result.setName("id"); + result.setInitialAmount(12.0); + result.setCharge(13); + result.setInitialConcentration(14.0); + result.setOnlySubstanceUnits(true); + result.setPositionToCompartment(PositionToCompartment.INSIDE); + result.setNotes("id"); + MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.UNKNOWN, "c"); + result.addMiriamData(md); + return result; + } } diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java index 07af12f8031e03b52279f429e99ffad42999dac4..1aefeefe0383b3e6b860bbe77ab348f73461bc50 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AliasDaoTest2.java @@ -29,283 +29,283 @@ import lcsb.mapviewer.model.map.species.field.RnaRegion; import lcsb.mapviewer.persist.PersistTestFunctions; public class AliasDaoTest2 extends PersistTestFunctions { - static Logger logger = Logger.getLogger(AliasDaoTest.class); - - private Integer testChargeVal = 1; - private String testIdAlias = "a"; - private Integer testInitialAmount = 2; - private Integer testInitialConcentration = 3; - private String testName = "d"; - private String testNotes = "e"; - private Boolean testOnlySubstanceunits = true; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAdd() throws Exception { - try { - - GenericProtein sp = new GenericProtein(testIdAlias); - sp.setCharge(testChargeVal); - sp.setInitialAmount(testInitialAmount); - sp.setInitialConcentration(testInitialConcentration); - sp.setName(testName); - sp.setNotes(testNotes); - sp.setOnlySubstanceUnits(testOnlySubstanceunits); - - Compartment parent = new Compartment("comp id"); - sp.setCompartment(parent); - - MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.UNKNOWN, "c"); - sp.addMiriamData(md); - - aliasDao.add(sp); - - Species sp2 = (Species) aliasDao.getById(sp.getId()); - assertNotNull(sp2); - assertEquals(sp.getCharge(), sp2.getCharge()); - assertEquals(sp.getElementId(), sp2.getElementId()); - assertEquals(sp.getInitialAmount(), sp2.getInitialAmount()); - assertEquals(sp.getInitialConcentration(), sp2.getInitialConcentration()); - assertEquals(sp.getName(), sp2.getName()); - assertEquals(sp.getNotes(), sp2.getNotes()); - assertEquals(sp.hasOnlySubstanceUnits(), sp2.hasOnlySubstanceUnits()); - - Compartment parent2 = sp2.getCompartment(); - assertNotNull(parent2); - assertEquals("comp id", parent2.getElementId()); - - assertNotNull(sp2.getMiriamData()); - - MiriamData md2 = sp2.getMiriamData().iterator().next(); - assertNotNull(md2); - assertEquals(md.getDataType(), md2.getDataType()); - assertEquals(md.getRelationType(), md2.getRelationType()); - assertEquals(md.getResource(), md2.getResource()); - - aliasDao.delete(sp); - sp2 = (Species) aliasDao.getById(sp.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testProtein() throws Exception { - try { - - Protein protein = new GenericProtein(testIdAlias); - ModificationResidue mr = new ModificationResidue(); - mr.setAngle(2.0); - mr.setName("name"); - mr.setSide("side"); - mr.setSize(3.0); - mr.setState(ModificationState.GLYCOSYLATED); - protein.addModificationResidue(mr); - - aliasDao.add(protein); - - Protein sp2 = (Protein) aliasDao.getById(protein.getId()); - assertNotNull(sp2); - assertEquals(protein.getElementId(), sp2.getElementId()); - - assertNotNull(sp2.getModificationResidues()); - assertEquals(1, sp2.getModificationResidues().size()); - - assertEquals(sp2.getModificationResidues().get(0).getAngle(), mr.getAngle()); - assertEquals(sp2.getModificationResidues().get(0).getIdModificationResidue(), mr.getIdModificationResidue()); - assertEquals(sp2.getModificationResidues().get(0).getName(), mr.getName()); - assertEquals(sp2.getModificationResidues().get(0).getSide(), mr.getSide()); - assertEquals(sp2.getModificationResidues().get(0).getSize(), mr.getSize()); - assertEquals(sp2.getModificationResidues().get(0).getState(), mr.getState()); - - aliasDao.delete(sp2); - sp2 = (Protein) aliasDao.getById(protein.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRna() throws Exception { - try { - - Rna sp = new Rna(testIdAlias); - RnaRegion mr = new RnaRegion(); - mr.setName("name"); - mr.setSize(3.0); - mr.setState(ModificationState.DONT_CARE); - sp.addRegion(mr); - - aliasDao.add(sp); - aliasDao.evict(sp); - - Rna sp2 = (Rna) aliasDao.getById(sp.getId()); - assertNotNull(sp2); - assertEquals(sp.getElementId(), sp2.getElementId()); - - assertNotNull(sp2.getRegions()); - assertEquals(1, sp2.getRegions().size()); - - assertEquals(sp2.getRegions().get(0).getId(), mr.getId()); - assertEquals(sp2.getRegions().get(0).getName(), mr.getName()); - assertEquals(sp2.getRegions().get(0).getSize(), mr.getSize(), EPSILON); - assertEquals(sp2.getRegions().get(0).getState(), mr.getState()); - - aliasDao.delete(sp2); - sp2 = (Rna) aliasDao.getById(sp.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAntisenseRna() throws Exception { - try { - - AntisenseRna sp = new AntisenseRna(testIdAlias); - AntisenseRnaRegion mr = new AntisenseRnaRegion(); - mr.setName("name"); - mr.setSize(3.0); - mr.setType(AntisenseRnaRegionType.MODIFICATION_SITE); - mr.setState(ModificationState.UNKNOWN); - sp.addRegion(mr); - - aliasDao.add(sp); - aliasDao.evict(sp); - - AntisenseRna sp2 = (AntisenseRna) aliasDao.getById(sp.getId()); - assertNotNull(sp2); - assertEquals(sp.getElementId(), sp2.getElementId()); - - assertNotNull(sp2.getRegions()); - assertEquals(1, sp2.getRegions().size()); - - assertEquals(sp2.getRegions().get(0).getIdAntisenseRnaRegion(), mr.getIdAntisenseRnaRegion()); - assertEquals(sp2.getRegions().get(0).getName(), mr.getName()); - assertEquals(sp2.getRegions().get(0).getSize(), mr.getSize(), EPSILON); - assertEquals(sp2.getRegions().get(0).getState(), mr.getState()); - assertEquals(sp2.getRegions().get(0).getType(), mr.getType()); - - aliasDao.delete(sp2); - sp2 = (AntisenseRna) aliasDao.getById(sp.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSynonymsInAlias() throws Exception { - try { - Protein protein = new GenericProtein(testIdAlias); - protein.addSynonym("Synonym"); - protein.addSynonym("Synonym A"); - protein.addSynonym("A"); - - protein.addFormerSymbol("Sym"); - protein.addFormerSymbol("Sym A"); - protein.addFormerSymbol("DD"); - - aliasDao.add(protein); - aliasDao.flush(); - - aliasDao.evict(protein); - Protein sp2 = (Protein) aliasDao.getById(protein.getId()); - - assertNotNull(sp2.getSynonyms()); - assertEquals(protein.getSynonyms().size(), sp2.getSynonyms().size()); - - for (int i = 0; i < protein.getSynonyms().size(); i++) { - assertEquals(protein.getSynonyms().get(i), sp2.getSynonyms().get(i)); - } - - assertNotNull(sp2.getFormerSymbols()); - assertEquals(protein.getFormerSymbols().size(), sp2.getFormerSymbols().size()); - - for (int i = 0; i < protein.getFormerSymbols().size(); i++) { - assertEquals(protein.getFormerSymbols().get(i), sp2.getFormerSymbols().get(i)); - } - - aliasDao.delete(sp2); - sp2 = (Protein) aliasDao.getById(protein.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testChemicals() throws Exception { - try { - Chemical ion = new Ion(testIdAlias); - ion.setInChI("come inchi"); - ion.setInChIKey("keyyy"); - ion.setSmiles("smile"); - - aliasDao.add(ion); - aliasDao.flush(); - - aliasDao.evict(ion); - Ion sp2 = (Ion) aliasDao.getById(ion.getId()); - - assertNotNull(sp2.getSynonyms()); - assertEquals(ion.getSynonyms().size(), sp2.getSynonyms().size()); - - assertEquals(ion.getSmiles(), sp2.getSmiles()); - assertEquals(ion.getInChIKey(), sp2.getInChIKey()); - assertEquals(ion.getInChI(), sp2.getInChI()); - - aliasDao.delete(sp2); - sp2 = (Ion) aliasDao.getById(ion.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testPhenotype() throws Exception { - try { - Phenotype phenotype = new Phenotype(testIdAlias); - - aliasDao.add(phenotype); - aliasDao.flush(); - - aliasDao.evict(phenotype); - Phenotype sp2 = (Phenotype) aliasDao.getById(phenotype.getId()); - - assertNotNull(sp2.getSynonyms()); - assertEquals(phenotype.getSynonyms().size(), phenotype.getSynonyms().size()); - - aliasDao.delete(sp2); - sp2 = (Phenotype) aliasDao.getById(phenotype.getId()); - assertNull(sp2); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + static Logger logger = Logger.getLogger(AliasDaoTest.class); + + private Integer testChargeVal = 1; + private String testIdAlias = "a"; + private Double testInitialAmount = 2.0; + private Double testInitialConcentration = 3.0; + private String testName = "d"; + private String testNotes = "e"; + private Boolean testOnlySubstanceunits = true; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testAdd() throws Exception { + try { + + GenericProtein sp = new GenericProtein(testIdAlias); + sp.setCharge(testChargeVal); + sp.setInitialAmount(testInitialAmount); + sp.setInitialConcentration(testInitialConcentration); + sp.setName(testName); + sp.setNotes(testNotes); + sp.setOnlySubstanceUnits(testOnlySubstanceunits); + + Compartment parent = new Compartment("comp id"); + sp.setCompartment(parent); + + MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.UNKNOWN, "c"); + sp.addMiriamData(md); + + aliasDao.add(sp); + + Species sp2 = (Species) aliasDao.getById(sp.getId()); + assertNotNull(sp2); + assertEquals(sp.getCharge(), sp2.getCharge()); + assertEquals(sp.getElementId(), sp2.getElementId()); + assertEquals(sp.getInitialAmount(), sp2.getInitialAmount()); + assertEquals(sp.getInitialConcentration(), sp2.getInitialConcentration()); + assertEquals(sp.getName(), sp2.getName()); + assertEquals(sp.getNotes(), sp2.getNotes()); + assertEquals(sp.hasOnlySubstanceUnits(), sp2.hasOnlySubstanceUnits()); + + Compartment parent2 = sp2.getCompartment(); + assertNotNull(parent2); + assertEquals("comp id", parent2.getElementId()); + + assertNotNull(sp2.getMiriamData()); + + MiriamData md2 = sp2.getMiriamData().iterator().next(); + assertNotNull(md2); + assertEquals(md.getDataType(), md2.getDataType()); + assertEquals(md.getRelationType(), md2.getRelationType()); + assertEquals(md.getResource(), md2.getResource()); + + aliasDao.delete(sp); + sp2 = (Species) aliasDao.getById(sp.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testProtein() throws Exception { + try { + + Protein protein = new GenericProtein(testIdAlias); + ModificationResidue mr = new ModificationResidue(); + mr.setAngle(2.0); + mr.setName("name"); + mr.setSide("side"); + mr.setSize(3.0); + mr.setState(ModificationState.GLYCOSYLATED); + protein.addModificationResidue(mr); + + aliasDao.add(protein); + + Protein sp2 = (Protein) aliasDao.getById(protein.getId()); + assertNotNull(sp2); + assertEquals(protein.getElementId(), sp2.getElementId()); + + assertNotNull(sp2.getModificationResidues()); + assertEquals(1, sp2.getModificationResidues().size()); + + assertEquals(sp2.getModificationResidues().get(0).getAngle(), mr.getAngle()); + assertEquals(sp2.getModificationResidues().get(0).getIdModificationResidue(), mr.getIdModificationResidue()); + assertEquals(sp2.getModificationResidues().get(0).getName(), mr.getName()); + assertEquals(sp2.getModificationResidues().get(0).getSide(), mr.getSide()); + assertEquals(sp2.getModificationResidues().get(0).getSize(), mr.getSize()); + assertEquals(sp2.getModificationResidues().get(0).getState(), mr.getState()); + + aliasDao.delete(sp2); + sp2 = (Protein) aliasDao.getById(protein.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testRna() throws Exception { + try { + + Rna sp = new Rna(testIdAlias); + RnaRegion mr = new RnaRegion(); + mr.setName("name"); + mr.setSize(3.0); + mr.setState(ModificationState.DONT_CARE); + sp.addRegion(mr); + + aliasDao.add(sp); + aliasDao.evict(sp); + + Rna sp2 = (Rna) aliasDao.getById(sp.getId()); + assertNotNull(sp2); + assertEquals(sp.getElementId(), sp2.getElementId()); + + assertNotNull(sp2.getRegions()); + assertEquals(1, sp2.getRegions().size()); + + assertEquals(sp2.getRegions().get(0).getId(), mr.getId()); + assertEquals(sp2.getRegions().get(0).getName(), mr.getName()); + assertEquals(sp2.getRegions().get(0).getSize(), mr.getSize(), EPSILON); + assertEquals(sp2.getRegions().get(0).getState(), mr.getState()); + + aliasDao.delete(sp2); + sp2 = (Rna) aliasDao.getById(sp.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAntisenseRna() throws Exception { + try { + + AntisenseRna sp = new AntisenseRna(testIdAlias); + AntisenseRnaRegion mr = new AntisenseRnaRegion(); + mr.setName("name"); + mr.setSize(3.0); + mr.setType(AntisenseRnaRegionType.MODIFICATION_SITE); + mr.setState(ModificationState.UNKNOWN); + sp.addRegion(mr); + + aliasDao.add(sp); + aliasDao.evict(sp); + + AntisenseRna sp2 = (AntisenseRna) aliasDao.getById(sp.getId()); + assertNotNull(sp2); + assertEquals(sp.getElementId(), sp2.getElementId()); + + assertNotNull(sp2.getRegions()); + assertEquals(1, sp2.getRegions().size()); + + assertEquals(sp2.getRegions().get(0).getIdAntisenseRnaRegion(), mr.getIdAntisenseRnaRegion()); + assertEquals(sp2.getRegions().get(0).getName(), mr.getName()); + assertEquals(sp2.getRegions().get(0).getSize(), mr.getSize(), EPSILON); + assertEquals(sp2.getRegions().get(0).getState(), mr.getState()); + assertEquals(sp2.getRegions().get(0).getType(), mr.getType()); + + aliasDao.delete(sp2); + sp2 = (AntisenseRna) aliasDao.getById(sp.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSynonymsInAlias() throws Exception { + try { + Protein protein = new GenericProtein(testIdAlias); + protein.addSynonym("Synonym"); + protein.addSynonym("Synonym A"); + protein.addSynonym("A"); + + protein.addFormerSymbol("Sym"); + protein.addFormerSymbol("Sym A"); + protein.addFormerSymbol("DD"); + + aliasDao.add(protein); + aliasDao.flush(); + + aliasDao.evict(protein); + Protein sp2 = (Protein) aliasDao.getById(protein.getId()); + + assertNotNull(sp2.getSynonyms()); + assertEquals(protein.getSynonyms().size(), sp2.getSynonyms().size()); + + for (int i = 0; i < protein.getSynonyms().size(); i++) { + assertEquals(protein.getSynonyms().get(i), sp2.getSynonyms().get(i)); + } + + assertNotNull(sp2.getFormerSymbols()); + assertEquals(protein.getFormerSymbols().size(), sp2.getFormerSymbols().size()); + + for (int i = 0; i < protein.getFormerSymbols().size(); i++) { + assertEquals(protein.getFormerSymbols().get(i), sp2.getFormerSymbols().get(i)); + } + + aliasDao.delete(sp2); + sp2 = (Protein) aliasDao.getById(protein.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testChemicals() throws Exception { + try { + Chemical ion = new Ion(testIdAlias); + ion.setInChI("come inchi"); + ion.setInChIKey("keyyy"); + ion.setSmiles("smile"); + + aliasDao.add(ion); + aliasDao.flush(); + + aliasDao.evict(ion); + Ion sp2 = (Ion) aliasDao.getById(ion.getId()); + + assertNotNull(sp2.getSynonyms()); + assertEquals(ion.getSynonyms().size(), sp2.getSynonyms().size()); + + assertEquals(ion.getSmiles(), sp2.getSmiles()); + assertEquals(ion.getInChIKey(), sp2.getInChIKey()); + assertEquals(ion.getInChI(), sp2.getInChI()); + + aliasDao.delete(sp2); + sp2 = (Ion) aliasDao.getById(ion.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testPhenotype() throws Exception { + try { + Phenotype phenotype = new Phenotype(testIdAlias); + + aliasDao.add(phenotype); + aliasDao.flush(); + + aliasDao.evict(phenotype); + Phenotype sp2 = (Phenotype) aliasDao.getById(phenotype.getId()); + + assertNotNull(sp2.getSynonyms()); + assertEquals(phenotype.getSynonyms().size(), phenotype.getSynonyms().size()); + + aliasDao.delete(sp2); + sp2 = (Phenotype) aliasDao.getById(phenotype.getId()); + assertNull(sp2); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/service/src/main/java/lcsb/mapviewer/services/search/data/FullAliasView.java b/service/src/main/java/lcsb/mapviewer/services/search/data/FullAliasView.java index 3fdec74966cd3d723b2b40340ada9cd3328cb9d2..587ba905d8508e604613c718b66b25188047f624 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/data/FullAliasView.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/data/FullAliasView.java @@ -22,611 +22,611 @@ import lcsb.mapviewer.services.view.AnnotationView; */ public class FullAliasView extends LightAliasView implements IHeavyView { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(FullAliasView.class); - - /** - * This class represents posttransational modification of the element. - * - * @author Piotr Gawron - * - */ - public static class PosttransationalModification implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Name of the modification. - */ - private String name; - - /** - * Position where the modification occurred. - */ - private String position; - - /** - * @return the name - * @see #name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - * @see #name - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the position - * @see #position - */ - public String getPosition() { - return position; - } - - /** - * @param position - * the position to set - * @see #position - */ - public void setPosition(String position) { - this.position = position; - } - } - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Description. - * - * @see Element#notes - */ - private String notes; - - /** - * Type of the alias. - * - * @see Element#getStringType() - */ - private String type; - - /** - * Symbol of the element. - * - * @see Element#symbol - */ - private String symbol; - - /** - * Full name of the element. - * - * @see Element#fullName - */ - private String fullName; - - /** - * Abbreviation of the element. - * - * @see Element#abbreviation - */ - private String abbreviation; - - /** - * Formula describing the element. - * - * @see Element#formula - */ - private String formula; - - /** - * Charge of the element. - * - * @see Species#charge - */ - private Integer charge; - - /** - * Initial amount of species. - * - * @see Species#initialAmount - */ - private Integer initialAmount = null; - - private String visibilityLevel = null; - - /** - * Initial concentration of species. - * - * @see Species#initialConcentration - */ - private Integer initialConcentration = null; - - /** - * Is only substance units allowed in a species. - * - * @see Species#onlySubstanceUnits - */ - private Boolean onlySubstanceUnits = null; - - /** - * Name of the element. - * - * @see Element#name - */ - private String name = ""; - - /** - * Name of the {@link Element#model}. - */ - private String modelName; - - /** - * Name of the {@link Element#submodel}. - */ - private String submodelName; - - /** - * Id of the {@link Element#submodel}. - */ - private String submodelId; - - /** - * List of synonyms of the element. - * - * @see Element#synonyms - */ - private List<String> synonyms = new ArrayList<>(); - - /** - * List of former symbols used by the entity represented by this element. - * - * @see Element#formerSymbols - */ - private List<String> formerSymbols = new ArrayList<>(); - - /** - * List of references for this element. - * - * @see Element#miriamData - */ - private List<AnnotationView> references = new ArrayList<>(); - - /** - * List of other unstructurized feuters, specific for some subclases of Alias. - * - */ - private Map<String, Object> other = new HashMap<>(); - - /** - * Default constructor. - * - * @param element - * original object from which this element is created - * @param icon - * string with icon that should be used to visualize this alias - */ - protected FullAliasView(Element element, String icon) { - super(element, icon); - setModelName(element.getModel().getName()); - if (element != null) { - setAbbreviation(element.getAbbreviation()); - addFormerSymbols(element.getFormerSymbols()); - setFormula(element.getFormula()); - setFullName(element.getFullName()); - setName(element.getName()); - setNotes(element.getNotes()); - setSymbol(element.getSymbol()); - addSynonyms(element.getSynonyms()); - setType(element.getStringType()); - setVisibilityLevel(element.getVisibilityLevel()); - if (element instanceof Species) { - Species species = (Species) element; - setCharge(species.getCharge()); - setInitialAmount(species.getInitialAmount()); - setInitialConcentration(species.getInitialConcentration()); - setOnlySubstanceUnits(species.getOnlySubstanceUnits()); - if (element.getSubmodel() != null && element.getSubmodel().getSubmodel() != null) { - setSubmodelName(element.getSubmodel().getSubmodel().getName()); - setSubmodelId(element.getSubmodel().getSubmodel().getId() + ""); - } - } - } - } - - /** - * Constructor that should be used only by the deserialization method. - */ - protected FullAliasView() { - } - - /** - * Adds elements to {@link #synonyms} list. - * - * @param synonyms2 - * list of elements to add - */ - private void addSynonyms(List<String> synonyms2) { - synonyms.addAll(synonyms2); - } - - /** - * Adds elements to {@link #formerSymbols} list. - * - * @param formerSymbols2 - * list of elements to add - */ - private void addFormerSymbols(List<String> formerSymbols2) { - formerSymbols.addAll(formerSymbols2); - } - - /** - * @return the notes - * @see #notes - */ - public String getNotes() { - return notes; - } - - /** - * @param notes - * the notes to set - * @see #notes - */ - public void setNotes(String notes) { - this.notes = notes; - } - - /** - * @return the symbol - * @see #symbol - */ - public String getSymbol() { - return symbol; - } - - /** - * @param symbol - * the symbol to set - * @see #symbol - */ - public void setSymbol(String symbol) { - this.symbol = symbol; - } - - /** - * @return the fullName - * @see #fullName - */ - public String getFullName() { - return fullName; - } - - /** - * @param fullName - * the fullName to set - * @see #fullName - */ - public void setFullName(String fullName) { - this.fullName = fullName; - } - - /** - * @return the abbreviation - * @see #abbreviation - */ - public String getAbbreviation() { - return abbreviation; - } - - /** - * @param abbreviation - * the abbreviation to set - * @see #abbreviation - */ - public void setAbbreviation(String abbreviation) { - this.abbreviation = abbreviation; - } - - /** - * @return the formula - * @see #formula - */ - public String getFormula() { - return formula; - } - - /** - * @param formula - * the formula to set - * @see #formula - */ - public void setFormula(String formula) { - this.formula = formula; - } - - /** - * @return the name - * @see #name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - * @see #name - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the synonyms - * @see #synonyms - */ - public List<String> getSynonyms() { - return synonyms; - } - - /** - * @param synonyms - * the synonyms to set - * @see #synonyms - */ - public void setSynonyms(List<String> synonyms) { - this.synonyms = synonyms; - } - - /** - * @return the formerSymbols - * @see #formerSymbols - */ - public List<String> getFormerSymbols() { - return formerSymbols; - } - - /** - * @param formerSymbols - * the formerSymbols to set - * @see #formerSymbols - */ - public void setFormerSymbols(List<String> formerSymbols) { - this.formerSymbols = formerSymbols; - } - - /** - * @return the references - * @see #references - */ - public List<AnnotationView> getReferences() { - return references; - } - - /** - * @param references - * the references to set - * @see #references - */ - public void setReferences(List<AnnotationView> references) { - this.references = references; - } - - /** - * @return the other - * @see #other - */ - public Map<String, Object> getOther() { - return other; - } - - /** - * Returns other (additional element) by the name. - * - * @param key - * key identifing the feature. - * @return other (additional element) by the name - */ - public Object getOther(String key) { - return other.get(key); - } - - /** - * @param other - * the other to set - * @see #other - */ - public void setOther(Map<String, Object> other) { - this.other = other; - } - - /** - * @return the type - * @see #type - */ - public String getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(String type) { - this.type = type; - } - - /** - * Adds elements to {@link #references} list. - * - * @param newReferences - * list of elements to add - */ - public void addReferences(List<AnnotationView> newReferences) { - references.addAll(newReferences); - } - - /** - * Addsother (additional element) by the name. - * - * @param key - * name of the feature - * @param value - * object representing data of the feature - */ - public void addOther(String key, Object value) { - other.put(key, value); - } - - /** - * @return the modelName - * @see #modelName - */ - public String getModelName() { - return modelName; - } - - /** - * @param modelName - * the modelName to set - * @see #modelName - */ - public void setModelName(String modelName) { - this.modelName = modelName; - } - - /** - * @return the charge - * @see #charge - */ - public Integer getCharge() { - return charge; - } - - /** - * @param charge - * the charge to set - * @see #charge - */ - public void setCharge(Integer charge) { - this.charge = charge; - } - - /** - * @return the initialAmount - * @see #initialAmount - */ - public Integer getInitialAmount() { - return initialAmount; - } - - /** - * @param initialAmount - * the initialAmount to set - * @see #initialAmount - */ - public void setInitialAmount(Integer initialAmount) { - this.initialAmount = initialAmount; - } - - /** - * @return the initialConcentration - * @see #initialConcentration - */ - public Integer getInitialConcentration() { - return initialConcentration; - } - - /** - * @param initialConcentration - * the initialConcentration to set - * @see #initialConcentration - */ - public void setInitialConcentration(Integer initialConcentration) { - this.initialConcentration = initialConcentration; - } - - /** - * @return the onlySubstanceUnits - * @see #onlySubstanceUnits - */ - public Boolean getOnlySubstanceUnits() { - return onlySubstanceUnits; - } - - /** - * @param onlySubstanceUnits - * the onlySubstanceUnits to set - * @see #onlySubstanceUnits - */ - public void setOnlySubstanceUnits(Boolean onlySubstanceUnits) { - this.onlySubstanceUnits = onlySubstanceUnits; - } - - /** - * @return the submodelName - * @see #submodelName - */ - public String getSubmodelName() { - return submodelName; - } - - /** - * @param submodelName - * the submodelName to set - * @see #submodelName - */ - public void setSubmodelName(String submodelName) { - this.submodelName = submodelName; - } - - /** - * @return the submodelId - * @see #submodelId - */ - public String getSubmodelId() { - return submodelId; - } - - /** - * @param submodelId - * the submodelId to set - * @see #submodelId - */ - public void setSubmodelId(String submodelId) { - this.submodelId = submodelId; - } - - /** - * @return the visibilityLevel - * @see #visibilityLevel - */ - public String getVisibilityLevel() { - return visibilityLevel; - } - - /** - * @param visibilityLevel - * the visibilityLevel to set - * @see #visibilityLevel - */ - public void setVisibilityLevel(String visibilityLevel) { - this.visibilityLevel = visibilityLevel; - } + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(FullAliasView.class); + + /** + * This class represents posttransational modification of the element. + * + * @author Piotr Gawron + * + */ + public static class PosttransationalModification implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Name of the modification. + */ + private String name; + + /** + * Position where the modification occurred. + */ + private String position; + + /** + * @return the name + * @see #name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + * @see #name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the position + * @see #position + */ + public String getPosition() { + return position; + } + + /** + * @param position + * the position to set + * @see #position + */ + public void setPosition(String position) { + this.position = position; + } + } + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Description. + * + * @see Element#notes + */ + private String notes; + + /** + * Type of the alias. + * + * @see Element#getStringType() + */ + private String type; + + /** + * Symbol of the element. + * + * @see Element#symbol + */ + private String symbol; + + /** + * Full name of the element. + * + * @see Element#fullName + */ + private String fullName; + + /** + * Abbreviation of the element. + * + * @see Element#abbreviation + */ + private String abbreviation; + + /** + * Formula describing the element. + * + * @see Element#formula + */ + private String formula; + + /** + * Charge of the element. + * + * @see Species#charge + */ + private Integer charge; + + /** + * Initial amount of species. + * + * @see Species#initialAmount + */ + private Double initialAmount = null; + + private String visibilityLevel = null; + + /** + * Initial concentration of species. + * + * @see Species#initialConcentration + */ + private Double initialConcentration = null; + + /** + * Is only substance units allowed in a species. + * + * @see Species#onlySubstanceUnits + */ + private Boolean onlySubstanceUnits = null; + + /** + * Name of the element. + * + * @see Element#name + */ + private String name = ""; + + /** + * Name of the {@link Element#model}. + */ + private String modelName; + + /** + * Name of the {@link Element#submodel}. + */ + private String submodelName; + + /** + * Id of the {@link Element#submodel}. + */ + private String submodelId; + + /** + * List of synonyms of the element. + * + * @see Element#synonyms + */ + private List<String> synonyms = new ArrayList<>(); + + /** + * List of former symbols used by the entity represented by this element. + * + * @see Element#formerSymbols + */ + private List<String> formerSymbols = new ArrayList<>(); + + /** + * List of references for this element. + * + * @see Element#miriamData + */ + private List<AnnotationView> references = new ArrayList<>(); + + /** + * List of other unstructurized feuters, specific for some subclases of Alias. + * + */ + private Map<String, Object> other = new HashMap<>(); + + /** + * Default constructor. + * + * @param element + * original object from which this element is created + * @param icon + * string with icon that should be used to visualize this alias + */ + protected FullAliasView(Element element, String icon) { + super(element, icon); + setModelName(element.getModel().getName()); + if (element != null) { + setAbbreviation(element.getAbbreviation()); + addFormerSymbols(element.getFormerSymbols()); + setFormula(element.getFormula()); + setFullName(element.getFullName()); + setName(element.getName()); + setNotes(element.getNotes()); + setSymbol(element.getSymbol()); + addSynonyms(element.getSynonyms()); + setType(element.getStringType()); + setVisibilityLevel(element.getVisibilityLevel()); + if (element instanceof Species) { + Species species = (Species) element; + setCharge(species.getCharge()); + setInitialAmount(species.getInitialAmount()); + setInitialConcentration(species.getInitialConcentration()); + setOnlySubstanceUnits(species.getOnlySubstanceUnits()); + if (element.getSubmodel() != null && element.getSubmodel().getSubmodel() != null) { + setSubmodelName(element.getSubmodel().getSubmodel().getName()); + setSubmodelId(element.getSubmodel().getSubmodel().getId() + ""); + } + } + } + } + + /** + * Constructor that should be used only by the deserialization method. + */ + protected FullAliasView() { + } + + /** + * Adds elements to {@link #synonyms} list. + * + * @param synonyms2 + * list of elements to add + */ + private void addSynonyms(List<String> synonyms2) { + synonyms.addAll(synonyms2); + } + + /** + * Adds elements to {@link #formerSymbols} list. + * + * @param formerSymbols2 + * list of elements to add + */ + private void addFormerSymbols(List<String> formerSymbols2) { + formerSymbols.addAll(formerSymbols2); + } + + /** + * @return the notes + * @see #notes + */ + public String getNotes() { + return notes; + } + + /** + * @param notes + * the notes to set + * @see #notes + */ + public void setNotes(String notes) { + this.notes = notes; + } + + /** + * @return the symbol + * @see #symbol + */ + public String getSymbol() { + return symbol; + } + + /** + * @param symbol + * the symbol to set + * @see #symbol + */ + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + /** + * @return the fullName + * @see #fullName + */ + public String getFullName() { + return fullName; + } + + /** + * @param fullName + * the fullName to set + * @see #fullName + */ + public void setFullName(String fullName) { + this.fullName = fullName; + } + + /** + * @return the abbreviation + * @see #abbreviation + */ + public String getAbbreviation() { + return abbreviation; + } + + /** + * @param abbreviation + * the abbreviation to set + * @see #abbreviation + */ + public void setAbbreviation(String abbreviation) { + this.abbreviation = abbreviation; + } + + /** + * @return the formula + * @see #formula + */ + public String getFormula() { + return formula; + } + + /** + * @param formula + * the formula to set + * @see #formula + */ + public void setFormula(String formula) { + this.formula = formula; + } + + /** + * @return the name + * @see #name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + * @see #name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the synonyms + * @see #synonyms + */ + public List<String> getSynonyms() { + return synonyms; + } + + /** + * @param synonyms + * the synonyms to set + * @see #synonyms + */ + public void setSynonyms(List<String> synonyms) { + this.synonyms = synonyms; + } + + /** + * @return the formerSymbols + * @see #formerSymbols + */ + public List<String> getFormerSymbols() { + return formerSymbols; + } + + /** + * @param formerSymbols + * the formerSymbols to set + * @see #formerSymbols + */ + public void setFormerSymbols(List<String> formerSymbols) { + this.formerSymbols = formerSymbols; + } + + /** + * @return the references + * @see #references + */ + public List<AnnotationView> getReferences() { + return references; + } + + /** + * @param references + * the references to set + * @see #references + */ + public void setReferences(List<AnnotationView> references) { + this.references = references; + } + + /** + * @return the other + * @see #other + */ + public Map<String, Object> getOther() { + return other; + } + + /** + * Returns other (additional element) by the name. + * + * @param key + * key identifing the feature. + * @return other (additional element) by the name + */ + public Object getOther(String key) { + return other.get(key); + } + + /** + * @param other + * the other to set + * @see #other + */ + public void setOther(Map<String, Object> other) { + this.other = other; + } + + /** + * @return the type + * @see #type + */ + public String getType() { + return type; + } + + /** + * @param type + * the type to set + * @see #type + */ + public void setType(String type) { + this.type = type; + } + + /** + * Adds elements to {@link #references} list. + * + * @param newReferences + * list of elements to add + */ + public void addReferences(List<AnnotationView> newReferences) { + references.addAll(newReferences); + } + + /** + * Addsother (additional element) by the name. + * + * @param key + * name of the feature + * @param value + * object representing data of the feature + */ + public void addOther(String key, Object value) { + other.put(key, value); + } + + /** + * @return the modelName + * @see #modelName + */ + public String getModelName() { + return modelName; + } + + /** + * @param modelName + * the modelName to set + * @see #modelName + */ + public void setModelName(String modelName) { + this.modelName = modelName; + } + + /** + * @return the charge + * @see #charge + */ + public Integer getCharge() { + return charge; + } + + /** + * @param charge + * the charge to set + * @see #charge + */ + public void setCharge(Integer charge) { + this.charge = charge; + } + + /** + * @return the initialAmount + * @see #initialAmount + */ + public Double getInitialAmount() { + return initialAmount; + } + + /** + * @param initialAmount + * the initialAmount to set + * @see #initialAmount + */ + public void setInitialAmount(Double initialAmount) { + this.initialAmount = initialAmount; + } + + /** + * @return the initialConcentration + * @see #initialConcentration + */ + public Double getInitialConcentration() { + return initialConcentration; + } + + /** + * @param initialConcentration + * the initialConcentration to set + * @see #initialConcentration + */ + public void setInitialConcentration(Double initialConcentration) { + this.initialConcentration = initialConcentration; + } + + /** + * @return the onlySubstanceUnits + * @see #onlySubstanceUnits + */ + public Boolean getOnlySubstanceUnits() { + return onlySubstanceUnits; + } + + /** + * @param onlySubstanceUnits + * the onlySubstanceUnits to set + * @see #onlySubstanceUnits + */ + public void setOnlySubstanceUnits(Boolean onlySubstanceUnits) { + this.onlySubstanceUnits = onlySubstanceUnits; + } + + /** + * @return the submodelName + * @see #submodelName + */ + public String getSubmodelName() { + return submodelName; + } + + /** + * @param submodelName + * the submodelName to set + * @see #submodelName + */ + public void setSubmodelName(String submodelName) { + this.submodelName = submodelName; + } + + /** + * @return the submodelId + * @see #submodelId + */ + public String getSubmodelId() { + return submodelId; + } + + /** + * @param submodelId + * the submodelId to set + * @see #submodelId + */ + public void setSubmodelId(String submodelId) { + this.submodelId = submodelId; + } + + /** + * @return the visibilityLevel + * @see #visibilityLevel + */ + public String getVisibilityLevel() { + return visibilityLevel; + } + + /** + * @param visibilityLevel + * the visibilityLevel to set + * @see #visibilityLevel + */ + public void setVisibilityLevel(String visibilityLevel) { + this.visibilityLevel = visibilityLevel; + } }