Search in sources :

Example 16 with Species

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;
    }
}
Also used : Vector(java.util.Vector) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies)

Example 17 with Species

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;
}
Also used : Statement(java.sql.Statement) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResultSet(java.sql.ResultSet) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies)

Example 18 with 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()) {
    // 
    // }
    // }
    }
}
Also used : ReactionSpeciesCopy(cbit.vcell.model.ReactionSpeciesCopy) IdentityHashMap(java.util.IdentityHashMap) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) Species(cbit.vcell.model.Species) Vector(java.util.Vector) Point(java.awt.Point)

Example 19 with Species

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();
    }
}
Also used : ModelException(cbit.vcell.model.ModelException) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) List(java.util.List) ParseException(org.vcell.model.bngl.ParseException) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Example 20 with Species

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();
}
Also used : ModelException(cbit.vcell.model.ModelException) SpeciesContext(cbit.vcell.model.SpeciesContext) Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.vcell.model.bngl.ParseException) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Aggregations

Species (cbit.vcell.model.Species)39 SpeciesContext (cbit.vcell.model.SpeciesContext)28 Structure (cbit.vcell.model.Structure)21 Model (cbit.vcell.model.Model)16 PropertyVetoException (java.beans.PropertyVetoException)13 KeyValue (org.vcell.util.document.KeyValue)12 Feature (cbit.vcell.model.Feature)11 ReactionStep (cbit.vcell.model.ReactionStep)11 Expression (cbit.vcell.parser.Expression)11 DBSpecies (cbit.vcell.model.DBSpecies)10 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 Membrane (cbit.vcell.model.Membrane)9 SimpleReaction (cbit.vcell.model.SimpleReaction)9 BioModel (cbit.vcell.biomodel.BioModel)8 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)8 ModelException (cbit.vcell.model.ModelException)8 ArrayList (java.util.ArrayList)8 FeatureMapping (cbit.vcell.mapping.FeatureMapping)7 DBFormalSpecies (cbit.vcell.model.DBFormalSpecies)7 ImageException (cbit.image.ImageException)6