Search in sources :

Example 1 with PathwaySelectionExpander

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

the class BioModelEditorPathwayPanel method importPathway.

public void importPathway(boolean addComplexes, boolean addComponents, boolean addInteractions) {
    ArrayList<BioPaxObject> selectedBioPaxObjects = new ArrayList<BioPaxObject>();
    int[] rows = table.getSelectedRows();
    if (rows == null || rows.length == 0) {
        return;
    }
    for (int row : rows) {
        BioPaxObject bioPaxObject = tableModel.getValueAt(row);
        selectedBioPaxObjects.add(bioPaxObject);
    }
    PathwaySelectionExpander selectionExpander = new PathwaySelectionExpander();
    PathwayModel rawPathwayModel = pathwayData.getPathwayModel();
    if (addComplexes) {
        selectionExpander.forPhysicalEntitiesAddComplexes(rawPathwayModel, selectedBioPaxObjects);
    }
    if (addComponents) {
        selectionExpander.forComplexesAddComponents(rawPathwayModel, selectedBioPaxObjects);
    }
    if (addInteractions) {
        selectionExpander.forPhysicalEntitiesAddInteractions(rawPathwayModel, selectedBioPaxObjects);
    }
    selectionExpander.forInteractionsAddControls(rawPathwayModel, selectedBioPaxObjects);
    selectionExpander.forInteractionsAddParticipants(rawPathwayModel, selectedBioPaxObjects);
    PathwayModel selectedPathwayModel = new PathwayModel();
    HashSet<BioPaxObject> objectsToDelete = new HashSet<BioPaxObject>();
    for (BioPaxObject candidateObject : selectedBioPaxObjects) {
        // is the object in the current pathwayModel already?
        BioPaxObject keeperObject = bioModel.getPathwayModel().find(candidateObject);
        if (keeperObject == null) {
            // not found in the current pathwayModel, add it
            selectedPathwayModel.add(candidateObject);
        } else {
            // make a list with the objects we don't bring in because of duplication
            objectsToDelete.add(candidateObject);
        }
    }
    // we replace references to those objects within selectedPathwayModel with the real thing
    for (BioPaxObject bpObject : selectedPathwayModel.getBiopaxObjects()) {
        if (bpObject == null) {
            System.out.println("PathwayModel: null BioPaxObject.");
            continue;
        }
        for (BioPaxObject objectToDelete : objectsToDelete) {
            BioPaxObject keeperObject = bioModel.getPathwayModel().find(objectToDelete);
            // for now we only implemented this for InteractionParticipant entities of Conversions
            bpObject.replace(keeperObject);
        }
    }
    // we bring proteins, small molecules, etc that are components of a Complex
    ArrayList<PhysicalEntity> addList = new ArrayList<>();
    for (BioPaxObject bpo : selectedPathwayModel.getBiopaxObjects()) {
        if (bpo instanceof Complex) {
            Complex complex = (Complex) bpo;
            addComplexComponents(complex, addList, 0);
        }
    }
    for (PhysicalEntity pe : addList) {
        if (selectedPathwayModel.find(pe) == null) {
            selectedPathwayModel.add(pe);
        }
    }
    bioModel.getPathwayModel().merge(selectedPathwayModel);
    // jump the view to pathway diagram panel
    if (selectionManager != null) {
        selectionManager.followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.PATHWAY_DIAGRAM_NODE, ActiveViewID.pathway_diagram), selectedPathwayModel.getBiopaxObjects().toArray());
    }
}
Also used : BioPaxObject(org.vcell.pathway.BioPaxObject) ArrayList(java.util.ArrayList) PathwayModel(org.vcell.pathway.PathwayModel) ActiveView(cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView) Complex(org.vcell.pathway.Complex) PhysicalEntity(org.vcell.pathway.PhysicalEntity) PathwaySelectionExpander(org.vcell.pathway.PathwaySelectionExpander) HashSet(java.util.HashSet)

Aggregations

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 Complex (org.vcell.pathway.Complex)1 PathwayModel (org.vcell.pathway.PathwayModel)1 PathwaySelectionExpander (org.vcell.pathway.PathwaySelectionExpander)1 PhysicalEntity (org.vcell.pathway.PhysicalEntity)1