Search in sources :

Example 1 with RDFXMLContext

use of org.vcell.pathway.persistence.RDFXMLContext in project vcell by virtualcell.

the class BioModelEditorSabioPanel method treeSelectionChanged.

public void treeSelectionChanged() {
    System.out.println("treeSelectionChanged");
    final SBEntity kineticLaw = computeSelectedKineticLaw();
    if (kineticLaw == null) {
        return;
    }
    String kineticLawID = kineticLaw.getID();
    final String kls = new String("kineticLaw");
    if (!kineticLawID.contains(kls)) {
        return;
    }
    kineticLawID = kineticLawID.substring(kineticLawID.lastIndexOf(kls) + kls.length());
    command = "EntryID:" + kineticLawID;
    AsynchClientTask task1 = new AsynchClientTask("Importing Kinetic Laws", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(final Hashtable<String, Object> hashTable) throws Exception {
            final URL url = new URL(BeanUtils.getDynamicClientProperties().getProperty(PropertyLoader.SABIO_SRCH_KINETIC_URL) + command);
            // final URL url = new URL("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=EntryID:33107");
            System.out.println(url.toString());
            String ERROR_CODE_TAG = "error_code";
            Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
            Element rootElement = jdomDocument.getRootElement();
            String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
            if (errorCode != null) {
                throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
            }
            PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
            PathwayData pathwayData = new PathwayData("Sabio Kinetic Laws", pathwayModel);
            hashTable.put("pathwayData", pathwayData);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
            if (pathwayData != null) {
                setSelectedObjects(new Object[] { pathwayData });
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Hashtable(java.util.Hashtable) Element(org.jdom.Element) PathwayData(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData) Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) SBEntity(org.vcell.pathway.sbpax.SBEntity) URL(java.net.URL) PathwayStringObject(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject)

Example 2 with RDFXMLContext

use of org.vcell.pathway.persistence.RDFXMLContext in project vcell by virtualcell.

the class BioModelEditorSabioPanel method populateKineticLawsTree.

public void populateKineticLawsTree() {
    // String category1 = (String)categoryList1.getSelectedItem();
    String category1 = "AnyRole";
    String category2 = (String) categoryList2.getSelectedItem();
    String entity1 = entityName1.getText();
    String entity2 = entityName2.getText();
    // http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=%28Pathway:JAK-STAT%20AND%20CellularLocation:cytosol%29
    command = "";
    if (entity1.isEmpty() && entity2.isEmpty()) {
        DialogUtils.showWarningDialog(this, "No search criteria specified.");
        return;
    }
    if (!entity1.isEmpty() && entity2.isEmpty()) {
        command += category1 + ":" + entity1;
    } else if (entity1.isEmpty() && !entity2.isEmpty()) {
        command += category2 + ":" + entity2;
    } else {
        // both entities present
        command += "%28" + category1 + ":" + entity1 + "%20AND%20" + category2 + ":" + entity2 + "%29";
    }
    AsynchClientTask task1 = new AsynchClientTask("Importing Kinetic Laws", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(final Hashtable<String, Object> hashTable) throws Exception {
            final URL url = new URL(BeanUtils.getDynamicClientProperties().getProperty(PropertyLoader.SABIO_SRCH_KINETIC_URL) + command);
            System.out.println(url.toString());
            String ERROR_CODE_TAG = "error_code";
            Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
            Element rootElement = jdomDocument.getRootElement();
            String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
            if (errorCode != null) {
                throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
            }
            PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
            PathwayData pathwayData = new PathwayData("Sabio Kinetic Laws", pathwayModel);
            hashTable.put("pathwayData", pathwayData);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
            if (pathwayData != null) {
                responseTreeModel.addSearchResponse("text", pathwayData);
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Hashtable(java.util.Hashtable) Element(org.jdom.Element) PathwayData(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData) PathwayStringObject(cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject) Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) URL(java.net.URL)

Example 3 with RDFXMLContext

use of org.vcell.pathway.persistence.RDFXMLContext in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation for a Biomodel object.
 * Creation date: (2/14/2001 3:41:13 PM)
 * @return Element
 * @param param cbit.vcell.biomodel.BioModel
 */
@SuppressWarnings("deprecation")
public Element getXML(BioModel param) throws XmlParseException, ExpressionException {
    // Creation of BioModel Node
    Element biomodelnode = new Element(XMLTags.BioModelTag);
    String name = param.getName();
    // Add attributes
    biomodelnode.setAttribute(XMLTags.NameAttrTag, name);
    // Add annotation
    if (param.getDescription() != null && param.getDescription().length() > 0) {
        Element annotationElem = new Element(XMLTags.AnnotationTag);
        annotationElem.setText(mangle(param.getDescription()));
        biomodelnode.addContent(annotationElem);
    }
    // Get Model
    try {
        biomodelnode.addContent(getXML(param.getModel()));
    } catch (XmlParseException e) {
        e.printStackTrace();
        throw new XmlParseException("An error occurred while processing the BioModel " + name, e);
    }
    // Get SimulationContexts
    if (param.getSimulationContexts() != null) {
        for (int index = 0; index < param.getSimulationContexts().length; index++) {
            biomodelnode.addContent(getXML(param.getSimulationContext(index), param));
        }
    }
    // Add Database Metadata (Version) information
    if (param.getVersion() != null) {
        biomodelnode.addContent(getXML(param.getVersion(), param.getName(), param.getDescription()));
    }
    // Add bioPAX and relationship information
    if (param.getPathwayModel() != null) {
        biomodelnode.addContent(getXML(param.getPathwayModel(), new RDFXMLContext()));
    }
    RelationshipModel rm = param.getRelationshipModel();
    if (rm != null) {
        biomodelnode.addContent(getXML(rm, param));
    }
    biomodelnode.addContent(XMLMetaDataWriter.getElement(param.getVCMetaData(), param));
    return biomodelnode;
}
Also used : RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Element(org.jdom.Element) RelationshipModel(org.vcell.relationship.RelationshipModel)

Example 4 with RDFXMLContext

use of org.vcell.pathway.persistence.RDFXMLContext in project vcell by virtualcell.

the class BioModelEditorPathwayCommonsPanel method showPathway.

public void showPathway() {
    final Pathway pathway = computeSelectedPathway();
    if (pathway == null) {
        return;
    }
    AsynchClientTask task1 = new AsynchClientTask("Importing pathway '" + pathway.name() + "'", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(final Hashtable<String, Object> hashTable) throws Exception {
            final URL url = new URL(BeanUtils.getDynamicClientProperties().getProperty(PropertyLoader.PATHWAY_WEB_DO_URL) + "?" + PathwayCommonsKeyword.cmd + "=" + PathwayCommonsKeyword.get_record_by_cpath_id + "&" + PathwayCommonsKeyword.version + "=" + PathwayCommonsVersion.v2.name + "&" + PathwayCommonsKeyword.q + "=" + pathway.primaryId() + "&" + PathwayCommonsKeyword.output + "=" + PathwayCommonsKeyword.biopax);
            System.out.println(url.toString());
            String ERROR_CODE_TAG = "error_code";
            // String ERROR_MSG_TAG = "error_msg";
            org.jdom.Document jdomDocument = XmlUtil.getJDOMDocument(url, getClientTaskStatusSupport());
            org.jdom.Element rootElement = jdomDocument.getRootElement();
            String errorCode = rootElement.getChildText(ERROR_CODE_TAG);
            if (errorCode != null) {
                throw new RuntimeException("Failed to access " + url + " \n\nPlease try again.");
            }
            // String xmlText = StringUtil.textFromInputStream(connection.getInputStream());
            // PathwayReader pathwayReader = new PathwayReader();
            // org.jdom.Document jdomDocument = XmlUtil.stringToXML(xmlText, null);
            // String xmlText = StringUtil.textFromInputStream(connection.getInputStream(), "UTF-8");
            // PathwayReader pathwayReader = new PathwayReader();
            // org.jdom.Document jdomDocument = XmlUtil.stringToXML(xmlText, "UTF-8");
            PathwayModel pathwayModel = PathwayIOUtil.extractPathwayFromJDOM(jdomDocument, new RDFXMLContext(), getClientTaskStatusSupport());
            PathwayData pathwayData = new PathwayData(pathway.name(), pathwayModel);
            hashTable.put("pathwayData", pathwayData);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("showing", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            PathwayData pathwayData = (PathwayData) hashTable.get("pathwayData");
            if (pathwayData != null) {
                // setActiveView(new ActiveView(null, DocumentEditorTreeFolderClass.PATHWAY_NODE, null));
                setSelectedObjects(new Object[] { pathwayData });
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, true, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) Pathway(org.vcell.sybil.util.http.pathwaycommons.search.Pathway) Hashtable(java.util.Hashtable) PathwayModel(org.vcell.pathway.PathwayModel) URL(java.net.URL)

Example 5 with RDFXMLContext

use of org.vcell.pathway.persistence.RDFXMLContext 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

RDFXMLContext (org.vcell.pathway.persistence.RDFXMLContext)5 Element (org.jdom.Element)4 PathwayModel (org.vcell.pathway.PathwayModel)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 URL (java.net.URL)3 Hashtable (java.util.Hashtable)3 PathwayData (cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayData)2 PathwayStringObject (cbit.vcell.client.desktop.biomodel.BioModelEditorPathwayCommonsPanel.PathwayStringObject)2 Document (org.jdom.Document)2 RelationshipModel (org.vcell.relationship.RelationshipModel)2 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 PathwayReaderBiopax3 (org.vcell.pathway.persistence.PathwayReaderBiopax3)1 SBEntity (org.vcell.pathway.sbpax.SBEntity)1 RelationshipReader (org.vcell.relationship.persistence.RelationshipReader)1 Pathway (org.vcell.sybil.util.http.pathwaycommons.search.Pathway)1