use of cbit.vcell.model.Species in project vcell by virtualcell.
the class ReactStepDbDriver method getSpecies.
/**
* getModel method comment.
*/
public Species[] getSpecies(QueryHashtable dbc, Connection con, User user) throws SQLException, DataAccessException {
// log.print("ReactStepDbDriver.getSpecies()");
String sql;
sql = " SELECT " + speciesTable.getTableName() + ".* " + " FROM " + speciesTable.getTableName() + "," + ModelTable.table.getTableName() + "," + SpeciesContextModelTable.table.getTableName() + " WHERE " + ModelTable.table.ownerRef.getQualifiedColName() + " = " + user.getID() + " AND " + SpeciesContextModelTable.table.modelRef.getQualifiedColName() + " = " + ModelTable.table.id.getQualifiedColName() + " AND " + SpeciesContextModelTable.table.speciesRef.getQualifiedColName() + " = " + speciesTable.id.getQualifiedColName() + " ORDER BY " + speciesTable.commonName.getQualifiedColName();
// System.out.println(sql);
Statement stmt = con.createStatement();
java.util.Vector speciesList = new java.util.Vector();
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
Species s = getSpecies(dbc, rset, con);
speciesList.addElement(s);
}
} finally {
// Release resources include resultset
stmt.close();
}
//
if (speciesList.size() == 0) {
return null;
} else {
Species[] speciesArray = new Species[speciesList.size()];
speciesList.copyInto(speciesArray);
return speciesArray;
}
}
use of cbit.vcell.model.Species in project vcell by virtualcell.
the class ReactStepDbDriver method getSpecies.
/**
* getModel method comment.
*/
public Species getSpecies(QueryHashtable dbc, Connection con, KeyValue speciesID) throws SQLException, DataAccessException, ObjectNotFoundException {
//
// try to get Species from the object cache
//
Species species = (Species) dbc.get(speciesID);
if (species != null) {
return species;
}
if (speciesID == null) {
throw new IllegalArgumentException("Improper parameters for getSpecies");
}
// log.print("ReactStepDbDriver.getSpecies(speciesID=" + speciesID + ")");
String sql;
sql = " SELECT * " + " FROM " + speciesTable.getTableName() + " WHERE " + speciesTable.id + " = " + speciesID;
// System.out.println(sql);
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
species = getSpecies(dbc, rset, con);
} else {
throw new org.vcell.util.ObjectNotFoundException("Species id=" + speciesID + " not found");
}
} finally {
// Release resources include resultset
stmt.close();
}
// MIRIAMTable.table.setMIRIAMAnnotation(con, species, speciesID);
return species;
}
use of cbit.vcell.model.Species in project vcell by virtualcell.
the class ReactionCartoonTool method pasteReactionsAndSpecies.
private void pasteReactionsAndSpecies(Structure structure) {
final String RXSPECIES_PASTERX = "Reactions";
final String RXSPECIES_SPECIES = "Species";
ReactionSpeciesCopy reactionSpeciesCopy = (ReactionSpeciesCopy) SimpleTransferable.getFromClipboard(VCellTransferable.REACTION_SPECIES_ARRAY_FLAVOR);
if (reactionSpeciesCopy != null) {
// TODO: here we may want to warn the user about compartment number / type / name mismatch
// between the source and the destination
String response = null;
if ((reactionSpeciesCopy.getReactStepArr() != null || reactionSpeciesCopy.getReactionRuleArr() != null) && reactionSpeciesCopy.getSpeciesContextArr() != null) {
String msg = "There are ";
msg += reactionSpeciesCopy.getSpeciesContextArr().length + " Species and ";
int rlen = 0;
if (reactionSpeciesCopy.getReactStepArr() != null)
rlen += reactionSpeciesCopy.getReactStepArr().length;
if (reactionSpeciesCopy.getReactionRuleArr() != null)
rlen += reactionSpeciesCopy.getReactionRuleArr().length;
msg += rlen + " Reactions / Rules on the clipboard, choose which set to paste.";
response = DialogUtils.showWarningDialog(getGraphPane(), "Choose Species or Reactions to paste", msg, new String[] { RXSPECIES_SPECIES, RXSPECIES_PASTERX, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
if (response == null || response.equals(RXSPECIES_CANCEL)) {
return;
}
}
if (reactionSpeciesCopy.getSpeciesContextArr() != null && (response == null || response.equals(RXSPECIES_SPECIES))) {
IdentityHashMap<Species, Species> speciesHash = new IdentityHashMap<Species, Species>();
Vector<BioModelEntityObject> pastedSpeciesContextV = new Vector<BioModelEntityObject>();
for (int i = 0; i < reactionSpeciesCopy.getSpeciesContextArr().length; i++) {
String rootSC = speciesContextRootFinder(reactionSpeciesCopy.getSpeciesContextArr()[i]);
pastedSpeciesContextV.add(pasteSpecies(getGraphPane(), reactionSpeciesCopy.getSpeciesContextArr()[i].getSpecies(), rootSC, getModel(), structure, true, speciesHash, null));
copyRelativePosition(getGraphModel(), reactionSpeciesCopy.getSpeciesContextArr()[i], pastedSpeciesContextV.lastElement());
}
ReactionCartoonTool.selectAndSaveDiagram(ReactionCartoonTool.this, pastedSpeciesContextV);
}
if (reactionSpeciesCopy.getReactStepArr() != null && reactionSpeciesCopy.getReactionRuleArr() == null && (response == null || response.equals(RXSPECIES_PASTERX))) {
pasteReactionSteps(getGraphPane(), reactionSpeciesCopy.getReactStepArr(), getModel(), structure, true, null, ReactionCartoonTool.this);
} else if (reactionSpeciesCopy.getReactionRuleArr() != null && (response == null || response.equals(RXSPECIES_PASTERX))) {
pasteReactionsAndRules(getGraphPane(), reactionSpeciesCopy, getModel(), structure, ReactionCartoonTool.this);
}
// try {
// for(MolecularType mtOurs : mtNewList) {
// rbmmcOurs.addMolecularType(mtOurs, false);
// }
// } catch (ModelException | PropertyVetoException e) {
// e.printStackTrace();
// }
//
// // ReactionRules
// if(reactionSpeciesCopy.getReactionRuleArr() != null) {
// for(ReactionRule rrTheirs : reactionSpeciesCopy.getReactionRuleArr()) {
//
// }
// }
}
}
use of cbit.vcell.model.Species in project vcell by virtualcell.
the class GeneratedSpeciesTableRow method deriveSpecies.
private void deriveSpecies(String inputString, Model tempModel) {
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
System.out.println("something is wrong, we just do nothing rather than crash");
return;
}
try {
String strStructure = null;
if (inputString.contains(RbmUtils.SiteStruct)) {
// we are in the mode where we emulate compartments by adding the compartment name as a fake site
Pair<List<String>, String> p = RbmUtils.extractCompartment(inputString);
strStructure = p.one.get(0);
inputString = p.two;
} else {
// should be the normal @comp:expression format - if it's not it will return null
strStructure = RbmUtils.parseCompartment(inputString, tempModel);
}
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
structure = tempModel.getStructure(0);
}
SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
sp.resolveBonds();
// System.out.println(sp.toString());
species = new SpeciesContext(new Species("a", ""), structure, sp);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
}
}
use of cbit.vcell.model.Species in project vcell by virtualcell.
the class ViewGeneratedSpeciesPanel method updateShape.
public void updateShape(int selectedRow) {
GeneratedSpeciesTableRow speciesTableRow = tableModel.getValueAt(selectedRow);
String inputString = speciesTableRow.getExpression();
// System.out.println(selectedRows[0] + ": " + inputString);
Model tempModel = null;
try {
tempModel = new Model("MyTempModel");
tempModel.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
System.out.println("something is wrong, we just do nothing rather than crash");
return;
}
try {
String strStructure = null;
if (inputString.contains(RbmUtils.SiteStruct)) {
// we are in the mode where we emulate compartments by adding the compartment name as a fake site
Pair<List<String>, String> p = RbmUtils.extractCompartment(inputString);
// we'll just assume there's only one, may want to throw exception if more
strStructure = p.one.get(0);
inputString = p.two;
} else {
// should be the normal @comp:expression format - if it's not it will return null
strStructure = RbmUtils.parseCompartment(inputString, tempModel);
}
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
if (owner.getSimulationContext().getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
tempModel.addMembrane(strStructure);
} else {
tempModel.addFeature(strStructure);
}
}
structure = tempModel.getStructure(strStructure);
} else {
structure = tempModel.getStructure(0);
}
SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
sp.resolveBonds();
SpeciesContext sc = new SpeciesContext(new Species("a", ""), structure, sp);
spls = new SpeciesPatternLargeShape(20, 20, -1, sp, shapePanel, sc, issueManager);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
// error (red circle)
spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanel, true, issueManager);
shapePanel.repaint();
}
int xOffset = spls.getRightEnd() + 45;
Dimension preferredSize = new Dimension(xOffset + 90, 50);
shapePanel.setPreferredSize(preferredSize);
shapePanel.repaint();
}
Aggregations