Search in sources :

Example 6 with PathwayModel

use of org.vcell.pathway.PathwayModel 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("http://sabiork.h-its.org/sabioRestWebServices/searchKineticLaws/biopax?q=" + 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 7 with PathwayModel

use of org.vcell.pathway.PathwayModel 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(defaultBaseURL + "?" + 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 8 with PathwayModel

use of org.vcell.pathway.PathwayModel 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);
    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)

Example 9 with PathwayModel

use of org.vcell.pathway.PathwayModel in project vcell by virtualcell.

the class PathwayTableModel method setPathwayModel.

public void setPathwayModel(PathwayModel newValue) {
    if (this.pathwayModel == newValue) {
        return;
    }
    PathwayModel oldValue = pathwayModel;
    if (oldValue != null) {
        oldValue.removePathwayListener(this);
    }
    if (newValue != null) {
        newValue.addPathwayListener(this);
    }
    this.pathwayModel = newValue;
    refreshData();
}
Also used : PathwayModel(org.vcell.pathway.PathwayModel)

Example 10 with PathwayModel

use of org.vcell.pathway.PathwayModel in project vcell by virtualcell.

the class PathwayReader method main.

public static void main(String[] args) {
    try {
        Document document = XmlUtil.readXML(new File("C:\\Developer\\eclipse\\workspace\\VCell_Standard\\temp.xml"));
        PathwayReader pathwayReader = new PathwayReader(new RDFXMLContext());
        System.out.println("starting parsing");
        PathwayModel pathwayModel = pathwayReader.parse(document.getRootElement(), null);
        System.out.println("ending parsing");
        pathwayModel.reconcileReferences(null);
        System.out.println(pathwayModel.show(true));
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : Document(org.jdom.Document) PathwayModel(org.vcell.pathway.PathwayModel) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

PathwayModel (org.vcell.pathway.PathwayModel)11 Document (org.jdom.Document)5 Element (org.jdom.Element)4 RDFXMLContext (org.vcell.pathway.persistence.RDFXMLContext)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 File (java.io.File)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 ZoomRangeException (cbit.gui.graph.GraphResizeManager.ZoomRangeException)1 BioModel (cbit.vcell.biomodel.BioModel)1 ActiveView (cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView)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 XmlParseException (cbit.vcell.xml.XmlParseException)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1