Search in sources :

Example 1 with ConversionTableRow

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

the class BioModelEditorConversionTableModel method createTableRow.

private ConversionTableRow createTableRow(BioPaxObject bpObject, String interactionId, String interactionLabel, String participantType, double stoich, HashSet<RelationshipObject> relationshipObjects) {
    String location = "";
    ConversionTableRow conversionTableRow = new ConversionTableRow(bpObject);
    conversionTableRow.setInteractionId(interactionId);
    conversionTableRow.setInteractionLabel(interactionLabel);
    conversionTableRow.setParticipantType(participantType);
    // stoichiometry and location
    if (participantType.equals("Reactant") || participantType.equals("Product")) {
        // stoichiometry
        if (stoich != 0)
            conversionTableRow.setStoich(stoich);
        else
            conversionTableRow.setStoich(1.0);
        // location
        // if(((PhysicalEntity)bpObject).getCellularLocation() != null && ((PhysicalEntity)bpObject).getCellularLocation().getTerm().size()>0)
        // location = ((PhysicalEntity)bpObject).getCellularLocation().getTerm().get(0);
        // else
        location = bioModel.getModel().getStructures()[0].getName();
        conversionTableRow.setLocation(location);
    } else {
        conversionTableRow.setStoich(1.0);
        // else
        if (bpObject instanceof Transport) {
            if (bioModel.getModel().getMembranes().size() > 0)
                location = bioModel.getModel().getMembranes().get(0).getName();
            else
                location = bioModel.getModel().getStructures()[0].getName();
        } else
            location = bioModel.getModel().getStructures()[0].getName();
        conversionTableRow.setLocation(location);
    }
    // id
    if (relationshipObjects == null) {
        if (bpObject instanceof Entity) {
            String id = (BioPAXUtil.getName((Entity) bpObject) + "_" + location).trim();
            if (isValid(id))
                conversionTableRow.setId(id);
            else
                conversionTableRow.setId(changeID(id));
        }
    } else {
        String id = null;
        for (RelationshipObject relationshipObject : relationshipObjects) {
            if (relationshipObject.getBioModelEntityObject() instanceof MolecularType) {
                id = relationshipObject.getBioModelEntityObject().getName();
                location = "";
            } else if (relationshipObject.getBioModelEntityObject().getStructure().getName().equalsIgnoreCase(location)) {
                id = relationshipObject.getBioModelEntityObject().getName();
            }
        }
        if (id != null) {
            // the linked bmObject with the same location will be used
            conversionTableRow.setId(id);
        } else {
            // a new bmObject will be created if no linked bmObject in the same location
            if (bpObject instanceof Entity) {
                id = (BioPAXUtil.getName((Entity) bpObject) + "_" + location).trim();
                if (isValid(id))
                    conversionTableRow.setId(id);
                else
                    conversionTableRow.setId(changeID(id));
            }
        }
    }
    return conversionTableRow;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Entity(org.vcell.pathway.Entity) PhysicalEntity(org.vcell.pathway.PhysicalEntity) ConversionTableRow(org.vcell.relationship.ConversionTableRow) Transport(org.vcell.pathway.Transport) RelationshipObject(org.vcell.relationship.RelationshipObject)

Example 2 with ConversionTableRow

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

the class BioModelEditorConversionTableModel method createTableRowForTransportParticipant.

private ConversionTableRow createTableRowForTransportParticipant(BioPaxObject bpObject, String interactionId, String interactionLabel, String participantType, double stoich, HashSet<RelationshipObject> relationshipObjects) {
    String location = "";
    ConversionTableRow conversionTableRow = new ConversionTableRow(bpObject);
    conversionTableRow.setInteractionId(interactionId);
    conversionTableRow.setInteractionLabel(interactionLabel);
    conversionTableRow.setParticipantType(participantType);
    // stoichiometry and location
    Model model = bioModel.getModel();
    StructureTopology structTopology = model.getStructureTopology();
    if (participantType.equals("Reactant")) {
        // stoichiometry
        if (stoich != 0)
            conversionTableRow.setStoich(stoich);
        else
            conversionTableRow.setStoich(1.0);
        // else{
        if (model.getMembranes().size() > 0)
            location = structTopology.getOutsideFeature(model.getMembranes().get(0)).getName();
        else
            location = model.getStructures()[0].getName();
        // }
        conversionTableRow.setLocation(location);
    } else if (participantType.equals("Product")) {
        // stoichiometry
        if (stoich != 0)
            conversionTableRow.setStoich(stoich);
        else
            conversionTableRow.setStoich(1.0);
        // else{
        if (model.getMembranes().size() > 0)
            location = structTopology.getInsideFeature(model.getMembranes().get(0)).getName();
        else
            location = model.getStructures()[0].getName();
        // }
        conversionTableRow.setLocation(location);
    } else {
        conversionTableRow.setStoich(1.0);
        // else
        if (bpObject instanceof Transport) {
            if (model.getMembranes().size() > 0)
                location = model.getMembranes().get(0).getName();
            else
                location = model.getStructures()[0].getName();
        } else
            location = model.getStructures()[0].getName();
        conversionTableRow.setLocation(location);
    }
    // id
    if (relationshipObjects == null) {
        if (bpObject instanceof Entity) {
            String id = (BioPAXUtil.getName((Entity) bpObject) + "_" + location).trim();
            if (isValid(id))
                conversionTableRow.setId(id);
            else
                conversionTableRow.setId(changeID(id));
        }
    } else {
        String id = null;
        for (RelationshipObject relationshipObject : relationshipObjects) {
            if (relationshipObject.getBioModelEntityObject().getStructure().getName().equalsIgnoreCase(location)) {
                id = relationshipObject.getBioModelEntityObject().getName();
            }
        }
        if (id != null) {
            // the linked bmObject with the same location will be used
            conversionTableRow.setId(id);
        } else {
            // a new bmObject will be created if no linked bmObject in the same location
            if (bpObject instanceof Entity) {
                id = (BioPAXUtil.getName((Entity) bpObject) + "_" + location).trim();
                if (isValid(id))
                    conversionTableRow.setId(id);
                else
                    conversionTableRow.setId(changeID(id));
            }
        }
    }
    return conversionTableRow;
}
Also used : Entity(org.vcell.pathway.Entity) PhysicalEntity(org.vcell.pathway.PhysicalEntity) StructureTopology(cbit.vcell.model.Model.StructureTopology) ConversionTableRow(org.vcell.relationship.ConversionTableRow) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) BioModel(cbit.vcell.biomodel.BioModel) AutoCompleteTableModel(org.vcell.util.gui.AutoCompleteTableModel) Model(cbit.vcell.model.Model) Transport(org.vcell.pathway.Transport) RelationshipObject(org.vcell.relationship.RelationshipObject)

Example 3 with ConversionTableRow

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

the class BioModelEditorConversionTableModel method refreshData.

private void refreshData() {
    if (bioModel == null || bioModel.getPathwayModel() == null || bioPaxObjects == null) {
        setData(null);
        return;
    }
    // function I :: get selected objects only
    // create ConversionTableRow objects
    allPathwayObjectList = new ArrayList<ConversionTableRow>();
    convertedBPObjects = new HashSet<BioPaxObject>();
    printObjects(bioPaxObjects);
    BioModel.printBpModelObjects(bioModel.getPathwayModel().getBiopaxObjects());
    // BioModel.printBpRelationshipObjects(bioModel.getRelationshipModel().getBioPaxObjects());	// derived; the bpObjects that are part of a relationship
    BioModel.printRelationships(bioModel.getRelationshipModel().getRelationshipObjects());
    System.out.println("----------------------------------------------------------------------");
    for (BioPaxObject bpo : bioPaxObjects) {
        if (bpo instanceof Conversion) {
            if (bioModel.getRelationshipModel().getRelationshipObjects(bpo).size() == 0) {
                Conversion conversion = (Conversion) bpo;
                ArrayList<String> nameList = conversion.getName();
                String interactionId = conversion.getID();
                String interactionLabel = nameList.isEmpty() ? conversion.getIDShort() : nameList.get(0);
                ConversionTableRow newConversionTableRow = createTableRow(conversion, interactionId, interactionLabel, "Conversion", 1.0, null);
                allPathwayObjectList.add(newConversionTableRow);
                convertedBPObjects.add(bpo);
                ArrayList<Stoichiometry> stoichiometryList = conversion.getParticipantStoichiometry();
                // stoichiometryMap problem:
                // how to deal with the case that the same object occurs on both left and right sides
                HashMap<PhysicalEntity, Double> stoichiometryMap = createStoichiometryMap(stoichiometryList);
                // reactant
                for (BioPaxObject bpObject1 : conversion.getLeft()) {
                    Double stoich = 1.0;
                    if (stoichiometryMap.get((PhysicalEntity) bpObject1) != null) {
                        stoich = stoichiometryMap.get((PhysicalEntity) bpObject1);
                    }
                    ConversionTableRow conversionTableRow;
                    if (bioModel.getRelationshipModel().getRelationshipObjects(bpObject1).isEmpty()) {
                        if (conversion instanceof Transport)
                            conversionTableRow = createTableRowForTransportParticipant(bpObject1, interactionId, interactionLabel, "Reactant", stoich, null);
                        else
                            conversionTableRow = createTableRow(bpObject1, interactionId, interactionLabel, "Reactant", stoich, null);
                    } else {
                        if (conversion instanceof Transport)
                            conversionTableRow = createTableRowForTransportParticipant(bpObject1, interactionId, interactionLabel, "Reactant", stoich, bioModel.getRelationshipModel().getRelationshipObjects(bpObject1));
                        else
                            conversionTableRow = createTableRow(bpObject1, interactionId, interactionLabel, "Reactant", stoich, bioModel.getRelationshipModel().getRelationshipObjects(bpObject1));
                    }
                    allPathwayObjectList.add(conversionTableRow);
                    convertedBPObjects.add(bpObject1);
                }
                // product
                for (BioPaxObject bpObject1 : conversion.getRight()) {
                    Double stoich = 1.0;
                    if (stoichiometryMap.get((PhysicalEntity) bpObject1) != null) {
                        stoich = stoichiometryMap.get((PhysicalEntity) bpObject1);
                    }
                    ConversionTableRow conversionTableRow;
                    if (bioModel.getRelationshipModel().getRelationshipObjects(bpObject1).isEmpty()) {
                        if (conversion instanceof Transport)
                            conversionTableRow = createTableRowForTransportParticipant(bpObject1, interactionId, interactionLabel, "Product", stoich, null);
                        else
                            conversionTableRow = createTableRow(bpObject1, interactionId, interactionLabel, "Product", stoich, null);
                    } else {
                        if (conversion instanceof Transport)
                            conversionTableRow = createTableRowForTransportParticipant(bpObject1, interactionId, interactionLabel, "Product", stoich, bioModel.getRelationshipModel().getRelationshipObjects(bpObject1));
                        else
                            conversionTableRow = createTableRow(bpObject1, interactionId, interactionLabel, "Product", stoich, bioModel.getRelationshipModel().getRelationshipObjects(bpObject1));
                    }
                    allPathwayObjectList.add(conversionTableRow);
                    convertedBPObjects.add(bpObject1);
                }
                // control
                for (BioPaxObject bpObject : bioModel.getPathwayModel().getBiopaxObjects()) {
                    if (bpObject instanceof Control) {
                        Control control = (Control) bpObject;
                        if (control instanceof Catalysis) {
                            // catalysis
                            if (BioPAXUtil.getControlledNonControlInteraction(control) == conversion) {
                                for (PhysicalEntity pe : ((Catalysis) control).getPhysicalControllers()) {
                                    ConversionTableRow conversionTableRow;
                                    if (bioModel.getRelationshipModel().getRelationshipObjects(pe).isEmpty()) {
                                        conversionTableRow = createTableRow(pe, interactionId, interactionLabel, "Catalyst", 1.0, null);
                                    } else {
                                        conversionTableRow = createTableRow(pe, interactionId, interactionLabel, "Catalyst", 1.0, bioModel.getRelationshipModel().getRelationshipObjects(pe));
                                    }
                                    allPathwayObjectList.add(conversionTableRow);
                                    convertedBPObjects.add(pe);
                                }
                            }
                        } else {
                            // other control types
                            if (BioPAXUtil.getControlledNonControlInteraction(control) == conversion) {
                                for (PhysicalEntity pe : control.getPhysicalControllers()) {
                                    ConversionTableRow conversionTableRow;
                                    if (bioModel.getRelationshipModel().getRelationshipObjects(pe).isEmpty()) {
                                        conversionTableRow = createTableRow(pe, interactionId, interactionLabel, "Control", 1.0, null);
                                    } else {
                                        conversionTableRow = createTableRow(pe, interactionId, interactionLabel, "Control", 1.0, bioModel.getRelationshipModel().getRelationshipObjects(pe));
                                    }
                                    allPathwayObjectList.add(conversionTableRow);
                                    convertedBPObjects.add(pe);
                                }
                            }
                        }
                    }
                }
            }
        } else if (bpo instanceof Catalysis) {
            for (PhysicalEntity pe : ((Catalysis) bpo).getPhysicalControllers()) {
                if (!convertedBPObjects.contains(pe)) {
                    ConversionTableRow conversionTableRow;
                    if (bioModel.getRelationshipModel().getRelationshipObjects(bpo).isEmpty()) {
                        conversionTableRow = createTableRow(pe, "", "", "Catalyst", 1.0, null);
                    } else {
                        conversionTableRow = createTableRow(pe, "", "", "Catalyst", 1.0, bioModel.getRelationshipModel().getRelationshipObjects(bpo));
                    }
                    allPathwayObjectList.add(conversionTableRow);
                    convertedBPObjects.add(pe);
                }
            }
            for (Pathway pathway : ((Catalysis) bpo).getPathwayControllers()) {
            // TODO
            }
        } else if (bpo instanceof Control) {
            for (PhysicalEntity pe : ((Catalysis) bpo).getPhysicalControllers()) {
                if (!convertedBPObjects.contains(pe)) {
                    ConversionTableRow conversionTableRow;
                    if (bioModel.getRelationshipModel().getRelationshipObjects(bpo).isEmpty()) {
                        conversionTableRow = createTableRow(pe, "", "", "Control", 1.0, null);
                    } else {
                        conversionTableRow = createTableRow(pe, "", "", "Control", 1.0, bioModel.getRelationshipModel().getRelationshipObjects(bpo));
                    }
                    allPathwayObjectList.add(conversionTableRow);
                    convertedBPObjects.add(pe);
                }
            }
            for (Pathway pathway : ((Catalysis) bpo).getPathwayControllers()) {
            // TODO
            }
        }
    }
    // 2nd pass - entities selected as themselves
    for (BioPaxObject bpo : bioPaxObjects) {
        if (bpo instanceof PhysicalEntity) {
            if (bioModel.getRelationshipModel().getRelationshipObjects(bpo).size() == 0) {
                PhysicalEntity physicalEntityObject = (PhysicalEntity) bpo;
                // we add standalone selected entities, only if they were not already added as part of any reaction
                if (!convertedBPObjects.contains(physicalEntityObject)) {
                    ConversionTableRow conversionTableRow = createTableRow(physicalEntityObject, "", "", "", 1.0, null);
                    allPathwayObjectList.add(conversionTableRow);
                    convertedBPObjects.add(physicalEntityObject);
                }
            }
        }
    }
    // apply text search function for particular columns
    ArrayList<ConversionTableRow> pathwayObjectList = new ArrayList<ConversionTableRow>();
    if (searchText == null || searchText.length() == 0) {
        pathwayObjectList.addAll(allPathwayObjectList);
    } else {
        String lowerCaseSearchText = searchText.toLowerCase();
        for (ConversionTableRow rs : allPathwayObjectList) {
            BioPaxObject bpObject = rs.getBioPaxObject();
            if (rs.interactionLabel().toLowerCase().contains(lowerCaseSearchText) || rs.participantType().toLowerCase().contains(lowerCaseSearchText) || getLabel(bpObject).toLowerCase().contains(lowerCaseSearchText) || getType(bpObject).toLowerCase().contains(lowerCaseSearchText)) {
                pathwayObjectList.add(rs);
            }
        }
    }
    setData(pathwayObjectList);
    GuiUtils.flexResizeTableColumns(ownerTable);
}
Also used : Stoichiometry(org.vcell.pathway.Stoichiometry) BioPaxObject(org.vcell.pathway.BioPaxObject) Pathway(org.vcell.pathway.Pathway) ArrayList(java.util.ArrayList) Conversion(org.vcell.pathway.Conversion) Control(org.vcell.pathway.Control) PhysicalEntity(org.vcell.pathway.PhysicalEntity) ConversionTableRow(org.vcell.relationship.ConversionTableRow) Catalysis(org.vcell.pathway.Catalysis) Transport(org.vcell.pathway.Transport)

Example 4 with ConversionTableRow

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

the class BioModelEditorConversionTableModel method isCellEditable.

public boolean isCellEditable(int iRow, int iCol) {
    ConversionTableRow conversonTableRow = getValueAt(iRow);
    boolean editable = true;
    if (conversonTableRow.participantType().equals("Conversion") || conversonTableRow.participantType().equals("")) {
        editable = false;
    }
    // only allow users to edit the stoich and location
    return ((iCol == iColStoich && editable) || iCol == iColLocation || iCol == iColID);
}
Also used : ConversionTableRow(org.vcell.relationship.ConversionTableRow)

Example 5 with ConversionTableRow

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

the class BioModelEditorConversionTableModel method getValueAt.

public Object getValueAt(int iRow, int iCol) {
    ConversionTableRow conversionTableRow = getValueAt(iRow);
    BioPaxObject bpObject = conversionTableRow.getBioPaxObject();
    switch(iCol) {
        case iColInteraction:
            {
                return conversionTableRow.interactionLabel();
            }
        case iColParticipant:
            {
                return conversionTableRow.participantType();
            }
        case iColEntity:
            {
                return getLabel(bpObject);
            }
        case iColType:
            {
                return getType(bpObject);
            }
        case iColStoich:
            {
                return conversionTableRow.stoich();
            }
        case iColID:
            {
                return conversionTableRow.id();
            }
        case iColLocation:
            {
                return conversionTableRow.location();
            }
        default:
            {
                return null;
            }
    }
}
Also used : ConversionTableRow(org.vcell.relationship.ConversionTableRow) BioPaxObject(org.vcell.pathway.BioPaxObject)

Aggregations

ConversionTableRow (org.vcell.relationship.ConversionTableRow)5 PhysicalEntity (org.vcell.pathway.PhysicalEntity)3 Transport (org.vcell.pathway.Transport)3 BioPaxObject (org.vcell.pathway.BioPaxObject)2 Entity (org.vcell.pathway.Entity)2 RelationshipObject (org.vcell.relationship.RelationshipObject)2 BioModel (cbit.vcell.biomodel.BioModel)1 Model (cbit.vcell.model.Model)1 StructureTopology (cbit.vcell.model.Model.StructureTopology)1 ArrayList (java.util.ArrayList)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 MolecularType (org.vcell.model.rbm.MolecularType)1 Catalysis (org.vcell.pathway.Catalysis)1 Control (org.vcell.pathway.Control)1 Conversion (org.vcell.pathway.Conversion)1 Pathway (org.vcell.pathway.Pathway)1 Stoichiometry (org.vcell.pathway.Stoichiometry)1 AutoCompleteTableModel (org.vcell.util.gui.AutoCompleteTableModel)1