Search in sources :

Example 1 with PathwayMapping

use of org.vcell.relationship.PathwayMapping in project vcell by virtualcell.

the class BioModelEditorPathwayDiagramPanel method importIntoModel.

public void importIntoModel() {
    if (bioModel == null) {
        return;
    }
    String warningMessage = "";
    String warningMessage2 = "";
    int warningCount = 0;
    int warningCount2 = 0;
    String infoMessage = "";
    ArrayList<BioPaxObject> importedBPObjects = new ArrayList<BioPaxObject>();
    warningMessage = "The following pathway object(s) have been associated with object(s) in the physiology model:\n";
    warningMessage2 = "The following transport reaction(s) will NOT be converted to the physiology model:\n";
    warningCount = 0;
    warningCount2 = 0;
    infoMessage = "The following pathway object(s) have been coverted in the physiology model:\n\n";
    boolean hasMembrane = false;
    if (bioModel.getModel().getMembranes().size() > 0)
        hasMembrane = true;
    HashSet<BioPaxObject> selected = new HashSet<BioPaxObject>();
    // convert group Object to regular biopaxObjects
    for (BioPaxObject bpo : getSelectedBioPaxObjects()) {
        if (bpo instanceof GroupObject) {
            selected.addAll(((GroupObject) bpo).computeGroupedBioPaxObjects());
        } else {
            selected.add(bpo);
        }
    }
    for (BioPaxObject bpo : selected) {
        if (bpo instanceof Conversion) {
            if (bpo instanceof Transport && !hasMembrane) {
                warningCount2++;
                if (((Conversion) bpo).getName().size() > 0)
                    warningMessage2 += "\nTransport: \'" + ((Conversion) bpo).getName().get(0) + "\'\n";
                else
                    warningMessage2 += "\nTransport: \'" + ((Conversion) bpo).getIDShort() + "\'\n";
            } else if (bioModel.getRelationshipModel().getRelationshipObjects(bpo).size() == 0) {
                importedBPObjects.add(bpo);
            } else {
                warningCount++;
                if (((Conversion) bpo).getName().size() > 0)
                    warningMessage += "\nReaction: \'" + ((Conversion) bpo).getName().get(0) + "\' =>\n";
                else
                    warningMessage += "\nReaction: \'" + ((Conversion) bpo).getIDShort() + "\' =>\n";
                for (RelationshipObject r : bioModel.getRelationshipModel().getRelationshipObjects(bpo)) {
                    warningMessage += "\t=> \'" + r.getBioModelEntityObject().getName() + "\'\n";
                }
            }
        } else if (bpo instanceof PhysicalEntity) {
            if (bioModel.getRelationshipModel().getRelationshipObjects(bpo).size() == 0) {
                importedBPObjects.add(bpo);
            } else {
                warningCount++;
                if (((PhysicalEntity) bpo).getName().size() > 0)
                    warningMessage += "\nSpecies: \'" + ((PhysicalEntity) bpo).getName().get(0) + "\' =>\n";
                else
                    warningMessage += "\nSpecies: \'" + ((PhysicalEntity) bpo).getIDShort() + "\' =>\n";
                for (RelationshipObject r : bioModel.getRelationshipModel().getRelationshipObjects(bpo)) {
                    warningMessage += "\t=> \'" + r.getBioModelEntityObject().getName() + "\'\n";
                }
            }
        }
    }
    // create import panel
    conversionPanel = new ConversionPanel();
    conversionPanel.setBioModel(bioModel);
    conversionPanel.setSelectionManager(getSelectionManager());
    // show warning message
    warningMessage2 += "\nNO membrane structures available in the physiology model.\n";
    if (warningCount2 > 0) {
        DialogUtils.showWarningDialog(conversionPanel, warningMessage2);
    }
    warningMessage += "\nThey will NOT be converted to the physiology model.\n";
    if (warningCount > 0) {
        DialogUtils.showWarningDialog(conversionPanel, warningMessage);
    }
    if (importedBPObjects.size() == 0) {
        return;
    }
    // set the selected objects to be the validly imported biopaxObject set
    conversionPanel.setBioPaxObjects(importedBPObjects);
    int returnCode = DialogUtils.showComponentOKCancelDialog(this, conversionPanel, "Import into Physiology");
    if (returnCode == JOptionPane.OK_OPTION) {
        PathwayMapping pathwayMapping = new PathwayMapping();
        try {
            // function I:
            // pass the table rows that contains user edited values to create Vcell object
            pathwayMapping.createBioModelEntitiesFromBioPaxObjects(bioModel, conversionPanel.getTableRows(), conversionPanel.isAddSubunits());
            for (BioPaxObject bpo : importedBPObjects) {
                if (bpo instanceof Conversion) {
                    infoMessage += "Reaction: \t\'";
                    for (RelationshipObject r : bioModel.getRelationshipModel().getRelationshipObjects(bpo)) {
                        infoMessage += r.getBioModelEntityObject().getName() + "\'\n";
                    }
                    infoMessage += "\n";
                } else if (bpo instanceof PhysicalEntity) {
                    infoMessage += "Species: \t\'";
                    for (RelationshipObject r : bioModel.getRelationshipModel().getRelationshipObjects(bpo)) {
                        infoMessage += r.getBioModelEntityObject().getName() + "\'\n";
                    }
                    infoMessage += "\n";
                }
            }
            DialogUtils.showInfoDialog(this, infoMessage);
            // jump the view to reaction diagram panel
            if (selectionManager != null) {
                selectionManager.setActiveView(new ActiveView(null, DocumentEditorTreeFolderClass.REACTION_DIAGRAM_NODE, ActiveViewID.reaction_diagram));
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
            DialogUtils.showErrorDialog(this, "Errors occur when converting pathway objects to VCell bioModel objects.\n" + e.getMessage());
        }
    }
}
Also used : PathwayMapping(org.vcell.relationship.PathwayMapping) BioPaxObject(org.vcell.pathway.BioPaxObject) ArrayList(java.util.ArrayList) GroupObject(org.vcell.pathway.GroupObject) ActiveView(cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView) Conversion(org.vcell.pathway.Conversion) RelationshipObject(org.vcell.relationship.RelationshipObject) ZoomRangeException(cbit.gui.graph.GraphResizeManager.ZoomRangeException) UtilCancelException(org.vcell.util.UtilCancelException) PhysicalEntity(org.vcell.pathway.PhysicalEntity) Transport(org.vcell.pathway.Transport) HashSet(java.util.HashSet)

Aggregations

ZoomRangeException (cbit.gui.graph.GraphResizeManager.ZoomRangeException)1 ActiveView (cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BioPaxObject (org.vcell.pathway.BioPaxObject)1 Conversion (org.vcell.pathway.Conversion)1 GroupObject (org.vcell.pathway.GroupObject)1 PhysicalEntity (org.vcell.pathway.PhysicalEntity)1 Transport (org.vcell.pathway.Transport)1 PathwayMapping (org.vcell.relationship.PathwayMapping)1 RelationshipObject (org.vcell.relationship.RelationshipObject)1 UtilCancelException (org.vcell.util.UtilCancelException)1