use of org.vcell.pathway.PhysicalEntity 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());
}
}
}
use of org.vcell.pathway.PhysicalEntity in project vcell by virtualcell.
the class BioModelEditorPathwayDiagramPanel method collapse2Complex.
private GroupObject collapse2Complex(BioPaxObject bpObject) {
PathwayGrouping pathwayGrouping = new PathwayGrouping();
GroupObject groupObject = null;
HashSet<BioPaxObject> hiddenobjects = new HashSet<BioPaxObject>();
if (bpObject instanceof Complex) {
// collapse components
Complex complex = (Complex) bpObject;
Set<BioPaxObject> bioPaxObjects = new HashSet<BioPaxObject>(bioModel.getPathwayModel().getBiopaxObjects());
for (PhysicalEntity pe : complex.getComponents()) {
if (bioPaxObjects.contains(pe)) {
hiddenobjects.add(pe);
}
}
if (hiddenobjects.size() > 0) {
hiddenobjects.add(bpObject);
String id = pathwayGrouping.groupIdGenerator(bioModel.getPathwayModel());
groupObject = pathwayGrouping.createGroupObject(bioModel.getPathwayModel(), ((Entity) bpObject).getName(), id, hiddenobjects, GroupObject.Type.GROUPEDCOMPLEX);
} else {
// error message
DialogUtils.showErrorDialog(this, "No Collapse action happened because the components of the complex, " + getEntityName(complex) + ", haven't been imported to pathway model.");
}
} else if (bpObject instanceof Protein || bpObject instanceof SmallMolecule) {
Set<BioPaxObject> bioPaxObjects = new HashSet<BioPaxObject>(bioModel.getPathwayModel().getBiopaxObjects());
ArrayList<String> name = new ArrayList<String>();
List<BioPaxObject> parents = bioModel.getPathwayModel().getParents(bpObject);
if (parents.isEmpty()) {
DialogUtils.showErrorDialog(this, "No Collapse action happened because protein, " + getEntityName((Entity) bpObject) + ", doesn't involve in any complexes in the pathway data.");
return null;
}
for (BioPaxObject bpo : bioModel.getPathwayModel().getParents(bpObject)) {
if (bpo instanceof Complex && bioPaxObjects.contains(bpo)) {
hiddenobjects.add(bpo);
name.addAll(((Complex) bpo).getName());
for (PhysicalEntity pe : ((Complex) bpo).getComponents()) {
if (bioPaxObjects.contains(pe)) {
hiddenobjects.add(pe);
}
}
}
}
if (hiddenobjects.size() > 0) {
hiddenobjects.add(bpObject);
String id = pathwayGrouping.groupIdGenerator(bioModel.getPathwayModel());
if (name.size() == 0) {
name.add(id);
}
groupObject = pathwayGrouping.createGroupObject(bioModel.getPathwayModel(), name, id, hiddenobjects, GroupObject.Type.GROUPEDCOMPLEX);
} else {
// error message
DialogUtils.showErrorDialog(this, "No Collapse action happened because complexes that relate to protein, " + getEntityName((Entity) bpObject) + ", haven't been imported to pathway model.");
}
}
return groupObject;
}
use of org.vcell.pathway.PhysicalEntity 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;
}
use of org.vcell.pathway.PhysicalEntity 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());
}
}
use of org.vcell.pathway.PhysicalEntity in project vcell by virtualcell.
the class BioPaxRelationshipTableModel method refreshData.
private void refreshData() {
ArrayList<BioPaxRelationshipTableRow> entityRows = new ArrayList<BioPaxRelationshipTableRow>();
if (bioModel != null) {
HashSet<RelationshipObject> relationshipObjects = null;
if (bioPaxObject != null) {
relationshipObjects = bioModel.getRelationshipModel().getRelationshipObjects(bioPaxObject);
}
List<BioPaxRelationshipTableRow> allEntityRows = new ArrayList<BioPaxRelationshipTableRow>();
if (bioPaxObject instanceof Conversion) {
for (ReactionStep rs : bioModel.getModel().getReactionSteps()) {
BioPaxRelationshipTableRow entityRow = new BioPaxRelationshipTableRow(rs);
if (relationshipObjects != null) {
for (RelationshipObject ro : relationshipObjects) {
if (ro.getBioModelEntityObject() == rs) {
entityRow.setSelected(true);
break;
}
}
}
if (!bShowLinkOnly || entityRow.selected) {
allEntityRows.add(entityRow);
}
}
for (ReactionRule rr : bioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
BioPaxRelationshipTableRow entityRow = new BioPaxRelationshipTableRow(rr);
if (relationshipObjects != null) {
for (RelationshipObject ro : relationshipObjects) {
if (ro.getBioModelEntityObject() == rr) {
entityRow.setSelected(true);
break;
}
}
}
if (!bShowLinkOnly || entityRow.selected) {
allEntityRows.add(entityRow);
}
}
} else if (bioPaxObject instanceof PhysicalEntity) {
for (SpeciesContext rs : bioModel.getModel().getSpeciesContexts()) {
BioPaxRelationshipTableRow entityRow = new BioPaxRelationshipTableRow(rs);
if (relationshipObjects != null) {
for (RelationshipObject ro : relationshipObjects) {
if (ro.getBioModelEntityObject() == rs) {
entityRow.setSelected(true);
break;
}
}
}
if (!bShowLinkOnly || entityRow.selected) {
allEntityRows.add(entityRow);
}
}
for (MolecularType mt : bioModel.getModel().getRbmModelContainer().getMolecularTypeList()) {
BioPaxRelationshipTableRow entityRow = new BioPaxRelationshipTableRow(mt);
if (relationshipObjects != null) {
for (RelationshipObject ro : relationshipObjects) {
if (ro.getBioModelEntityObject() == mt) {
entityRow.setSelected(true);
break;
}
}
}
if (!bShowLinkOnly || entityRow.selected) {
allEntityRows.add(entityRow);
}
}
}
if (searchText == null || searchText.length() == 0) {
entityRows.addAll(allEntityRows);
} else {
for (BioPaxRelationshipTableRow rs : allEntityRows) {
BioModelEntityObject object = rs.getBioModelEntityObject();
String lowerCaseSearchText = searchText.toLowerCase();
if (object.getName().toLowerCase().contains(lowerCaseSearchText) || object.getTypeLabel().toLowerCase().contains(lowerCaseSearchText)) {
entityRows.add(rs);
}
}
}
}
setData(entityRows);
GuiUtils.flexResizeTableColumns(ownerTable);
}
Aggregations