Search in sources :

Example 1 with RelationshipReader

use of org.vcell.relationship.persistence.RelationshipReader in project vcell by virtualcell.

the class XmlReader method getBioModel.

/**
 * This method returns a Biomodel object from a XML Element.
 * Creation date: (3/13/2001 12:35:00 PM)
 * @return cbit.vcell.biomodel.BioModel
 * @param param org.jdom.Element
 */
public BioModel getBioModel(Element param, VCellSoftwareVersion docVcellSoftwareVersion) throws XmlParseException {
    this.docVCellSoftwareVersion = docVcellSoftwareVersion;
    // long l1 = System.currentTimeMillis();
    // Get metadata information Version (if available)
    Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
    // Create new biomodel
    BioModel biomodel = new BioModel(version);
    // Set name
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    try {
        biomodel.setName(name);
        // String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
        // if (annotation!=null) {
        // biomodel.setDescription(unMangle(annotation));
        // }
        // get annotation
        String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
        if (annotationText != null && annotationText.length() > 0) {
            biomodel.setDescription(unMangle(annotationText));
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException(e);
    }
    // long l2 = System.currentTimeMillis();
    // System.out.println("biomodel-------- "+((double)(l2-l1))/1000);
    // ***Add biomodel to the dictionnary***
    // dictionnary.put(simcontext.getClass().getName()+":"+simcontext.getName(), simcontext);
    // Set model
    Model newmodel = getModel(param.getChild(XMLTags.ModelTag, vcNamespace));
    biomodel.setModel(newmodel);
    // Set simulation contexts
    java.util.List<Element> children = param.getChildren(XMLTags.SimulationSpecTag, vcNamespace);
    java.util.Iterator<Element> iterator = children.iterator();
    // System.out.println("model-------- "+((double)(l3-l2))/1000);
    if (biomodel.getVersion() != null && biomodel.getVersion().getVersionKey() != null) {
        Long lpcBMKey = Long.valueOf(biomodel.getVersion().getVersionKey().toString());
        MathDescription.originalHasLowPrecisionConstants.remove(lpcBMKey);
    }
    while (iterator.hasNext()) {
        // long l4 = System.currentTimeMillis();
        Element tempElement = iterator.next();
        SimulationContext simContext = getSimulationContext(tempElement, biomodel);
        try {
            biomodel.addSimulationContext(simContext);
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace();
            throw new XmlParseException("An error occurred while trying to add the SimContext " + simContext.getName() + " to the BioModel Object!", e);
        }
        // process the simulations within this Simspec
        Iterator<Element> simIterator = tempElement.getChildren(XMLTags.SimulationTag, vcNamespace).iterator();
        // System.out.println("simcontext-------- "+((double)(l5-l4))/1000);
        while (simIterator.hasNext()) {
            try {
                biomodel.addSimulation(getSimulation((Element) simIterator.next(), simContext.getMathDescription()));
            } catch (java.beans.PropertyVetoException e) {
                e.printStackTrace();
                throw new XmlParseException("A PropertyVetoException occurred when adding a Simulation entity to the BioModel " + name, e);
            }
        }
    // long l6 = System.currentTimeMillis();
    // System.out.println("sims-------- "+((double)(l6-l5))/1000);
    }
    // biomodel.getVCMetaData().setAnnotation(biomodel, param);
    // biomodel.getVCMetaData().setNotes(biomodel, param);
    boolean bMetaDataPopulated = false;
    List<Element> elementsMetaData = param.getChildren(XMLMetaData.VCMETADATA_TAG, VCMetaData.nsVCML);
    if (elementsMetaData != null && elementsMetaData.size() > 0) {
        for (Element elementMetaData : elementsMetaData) {
            XMLMetaDataReader.readFromElement(biomodel.getVCMetaData(), biomodel, elementMetaData);
        }
        bMetaDataPopulated = true;
    } else {
        // no metadata was found, populate vcMetaData from biomodel (mainly free text annotation for identifiables)
        if (!bMetaDataPopulated) {
            biomodel.populateVCMetadata(bMetaDataPopulated);
        }
    }
    Element pathwayElement = param.getChild(XMLTags.PathwayModelTag, vcNamespace);
    if (pathwayElement != null) {
        Element rdfElement = pathwayElement.getChild(XMLRDF.tagRDF, XMLRDF.nsRDF);
        if (rdfElement != null) {
            PathwayReaderBiopax3 pathwayReader = new PathwayReaderBiopax3(new RDFXMLContext());
            PathwayModel pathwayModel = pathwayReader.parse(rdfElement, false);
            // ??? is this needed ???
            pathwayModel.reconcileReferences(null);
            // we keep as lvl 1 only the objects which we want to show in the diagram
            pathwayModel.filterDiagramObjects();
            biomodel.getPathwayModel().merge(pathwayModel);
        } else {
            throw new XmlParseException("expecting RDF element as child of pathwayModel within VCML document");
        }
    }
    Element relationshipElement = param.getChild(XMLTags.RelationshipModelTag, vcNamespace);
    if (relationshipElement != null) {
        Element rmnsElement = relationshipElement.getChild("RMNS", vcNamespace);
        if (rmnsElement != null) {
            RelationshipReader relationshipReader = new RelationshipReader();
            RelationshipModel relationshipModel = relationshipReader.parse(rmnsElement, biomodel);
            biomodel.getRelationshipModel().merge(relationshipModel);
        } else {
        // throw new XmlParseException("expecting RMNS element as child of pathwayModel within VCML document");
        }
    }
    return biomodel;
}
Also used : RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) RelationshipReader(org.vcell.relationship.persistence.RelationshipReader) Element(org.jdom.Element) RelationshipModel(org.vcell.relationship.RelationshipModel) SimulationContext(cbit.vcell.mapping.SimulationContext) PathwayModel(org.vcell.pathway.PathwayModel) PathwayReaderBiopax3(org.vcell.pathway.persistence.PathwayReaderBiopax3) PropertyVetoException(java.beans.PropertyVetoException) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) BioModel(cbit.vcell.biomodel.BioModel) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) PathwayModel(org.vcell.pathway.PathwayModel) RelationshipModel(org.vcell.relationship.RelationshipModel) BioModel(cbit.vcell.biomodel.BioModel)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathModel (cbit.vcell.mathmodel.MathModel)1 Model (cbit.vcell.model.Model)1 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)1 PropertyVetoException (java.beans.PropertyVetoException)1 Element (org.jdom.Element)1 PathwayModel (org.vcell.pathway.PathwayModel)1 PathwayReaderBiopax3 (org.vcell.pathway.persistence.PathwayReaderBiopax3)1 RDFXMLContext (org.vcell.pathway.persistence.RDFXMLContext)1 RelationshipModel (org.vcell.relationship.RelationshipModel)1 RelationshipReader (org.vcell.relationship.persistence.RelationshipReader)1 SimulationVersion (org.vcell.util.document.SimulationVersion)1 VCellSoftwareVersion (org.vcell.util.document.VCellSoftwareVersion)1 Version (org.vcell.util.document.Version)1