Search in sources :

Example 11 with Species

use of cbit.vcell.model.Species in project vcell by virtualcell.

the class BioCartoonTool method getNewSpecies.

private static Species getNewSpecies(IdentityHashMap<Species, Species> speciesHash, Species copyFromSpecies, Model pasteToModel, boolean bNew, /* boolean bUseDBSpecies,*/
Structure pasteToStruct, HashMap<Structure, Species> userPreferredToTarget) {
    Species newSpecies = speciesHash.get(copyFromSpecies);
    if (newSpecies != null) {
        return newSpecies;
    }
    Species preferredToSpecies = (userPreferredToTarget != null ? userPreferredToTarget.values().iterator().next() : null);
    try {
        if (bNew || (userPreferredToTarget != null && preferredToSpecies == null)) {
            String newName = copyFromSpecies.getCommonName();
            while (pasteToModel.getSpecies(newName) != null) {
                newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
            }
            newSpecies = new Species(newName, copyFromSpecies.getAnnotation(), copyFromSpecies.getDBSpecies());
            pasteToModel.addSpecies(newSpecies);
            speciesHash.put(copyFromSpecies, newSpecies);
        } else {
            // Find a matching existing species if possible
            if (preferredToSpecies != null) {
                return preferredToSpecies;
            }
            if (!pasteToModel.contains(copyFromSpecies)) {
                // Doesn't have Species (==)
                // see if we have a species with DBSpecies that matches
                // Species[] speciesFromDBSpeciesArr = (copyFromSpecies.getDBSpecies() != null ? pasteToModel.getSpecies(copyFromSpecies.getDBSpecies()) : null);
                // if(/*bUseDBSpecies && */speciesFromDBSpeciesArr != null && speciesFromDBSpeciesArr.length > 0){//DBSpecies match
                // //Choose the species in struct if exists
                // newSpecies = speciesFromDBSpeciesArr[0];
                // for(int i=0;i<speciesFromDBSpeciesArr.length;i+= 1){
                // if(pasteToModel.getSpeciesContext(speciesFromDBSpeciesArr[i], pasteToStruct) != null){
                // newSpecies = speciesFromDBSpeciesArr[i];
                // break;
                // }
                // }
                // }else{// No DBSpecies match
                // See if there is a species with same name
                newSpecies = pasteToModel.getSpecies(copyFromSpecies.getCommonName());
                if (newSpecies == null) {
                    // No name matches
                    String newName = copyFromSpecies.getCommonName();
                    newSpecies = new Species(newName, copyFromSpecies.getAnnotation(), copyFromSpecies.getDBSpecies());
                    pasteToModel.addSpecies(newSpecies);
                    speciesHash.put(copyFromSpecies, newSpecies);
                }
            // }
            } else {
                // Has species (==)
                newSpecies = copyFromSpecies;
            }
        }
    } catch (PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Could not add species to model : " + e.getMessage());
    }
    return newSpecies;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Species(cbit.vcell.model.Species)

Example 12 with Species

use of cbit.vcell.model.Species in project vcell by virtualcell.

the class BioCartoonTool method pasteSpecies.

/**
 * Insert the method's description here.
 * Creation date: (5/10/2003 3:55:25 PM)
 * @param pasteToModel cbit.vcell.model.Model
 * @param pasteToStruct cbit.vcell.model.Structure
 * @param bNew boolean
 */
protected static final SpeciesContext pasteSpecies(Component parent, Species copyFromSpecies, String useThisSpeciesContextRootName, Model pasteToModel, Structure pasteToStruct0, boolean bNew, /*boolean bUseDBSpecies, */
IdentityHashMap<Species, Species> speciesHash, HashMap<Structure, Species> userPreferredToTarget) {
    Structure preferredToStructure = (userPreferredToTarget != null ? userPreferredToTarget.keySet().iterator().next() : pasteToStruct0);
    if (!pasteToModel.contains(preferredToStructure)) {
        throw new IllegalArgumentException("CartoonTool.pasteSpecies model '" + pasteToModel.getName() + "' does not contain structure " + (preferredToStructure == null ? null : "'" + preferredToStructure.getName() + "'"));
    }
    Species newSpecies = null;
    if (copyFromSpecies != null) {
        try {
            newSpecies = getNewSpecies(speciesHash, copyFromSpecies, pasteToModel, bNew, preferredToStructure, userPreferredToTarget);
            // see if we have SpeciesContext
            SpeciesContext speciesContext = pasteToModel.getSpeciesContext(newSpecies, preferredToStructure);
            if (speciesContext == null) {
                // Has Species but not SpeciesContext
                speciesContext = pasteToModel.addSpeciesContext(newSpecies, preferredToStructure);
                String newSpeciesContextName = newSpecies.getCommonName();
                if (useThisSpeciesContextRootName != null) {
                    newSpeciesContextName = useThisSpeciesContextRootName + "_" + speciesContext.getStructure().getName();
                    while (pasteToModel.getSpeciesContext(newSpeciesContextName) != null) {
                        newSpeciesContextName = TokenMangler.getNextEnumeratedToken(newSpeciesContextName);
                    }
                }
                speciesContext.setName(newSpeciesContextName);
            }
        } catch (Exception e) {
            DialogUtils.showErrorDialog(parent, e.getMessage(), e);
        }
    }
    return pasteToModel.getSpeciesContext(newSpecies, preferredToStructure);
}
Also used : SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) UserCancelException(org.vcell.util.UserCancelException)

Example 13 with Species

use of cbit.vcell.model.Species in project vcell by virtualcell.

the class ModelDbDriver method getSpeciesContext.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.SpeciesContext
 * @param rset java.sql.ResultSet
 */
private SpeciesContext getSpeciesContext(QueryHashtable dbc, Connection con, ResultSet rset) throws SQLException, DataAccessException {
    // 
    // if in object cache, no need to create it
    // 
    KeyValue scKey = new KeyValue(rset.getBigDecimal(SpeciesContextModelTable.table.id.toString()));
    SpeciesContext speciesContext = (SpeciesContext) dbc.get(scKey);
    if (speciesContext != null) {
        return speciesContext;
    }
    // 
    // get foreign keys
    // 
    KeyValue structKey = new KeyValue(rset.getBigDecimal(SpeciesContextModelTable.table.structRef.toString()));
    KeyValue speciesKey = new KeyValue(rset.getBigDecimal(SpeciesContextModelTable.table.speciesRef.toString()));
    // 
    // get object (ignoring foreign keys)
    // 
    speciesContext = speciesContextModelTable.getSpeciesContext(rset, scKey);
    String speciesPatternString = speciesContext.getSpeciesPatternString();
    // 
    // add objects corresponding to foreign keys
    // 
    Structure structure = reactStepDB.getStructure(dbc, con, structKey);
    Species species = reactStepDB.getSpecies(dbc, con, speciesKey);
    speciesContext = new SpeciesContext(scKey, speciesContext.getName(), species, structure);
    speciesContext.setSpeciesPatternString(speciesPatternString);
    // 
    // put SpeciesContext into object cache
    // 
    dbc.put(scKey, speciesContext);
    return speciesContext;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species)

Example 14 with Species

use of cbit.vcell.model.Species in project vcell by virtualcell.

the class ModelDbDriver method getModel.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.Model
 * @param rset java.sql.ResultSet
 */
private Model getModel(QueryHashtable dbc, ResultSet rset, Connection con, User user) throws SQLException, DataAccessException {
    // User owner = new User(ownerName, ownerRef);
    try {
        Model model = modelTable.getModel(rset, con);
        // model.setOwner(owner);
        KeyValue modelKey = model.getVersion().getVersionKey();
        // 
        // set structures for this model
        // 
        StructureTopology structureTopology = model.getStructureTopology();
        Structure[] structures = reactStepDB.getStructuresFromModel(dbc, con, modelKey);
        if (structures != null && structures.length > 0) {
            model.setStructures(structures);
        }
        HashMap<KeyValue, StructureKeys> structureKeysMap = reactStepDB.getStructureParentMapByModel(dbc, con, modelKey);
        ReactStepDbDriver.populateStructureAndElectricalTopology(model, structureKeysMap);
        // 
        // set species for this model
        // 
        SpeciesContext[] speciesContexts = getSpeciesContextFromModel(dbc, con, user, modelKey, structureTopology);
        if (speciesContexts != null) {
            Vector<Species> speciesList = new Vector<Species>();
            for (int i = 0; i < speciesContexts.length; i++) {
                if (!speciesList.contains(speciesContexts[i].getSpecies())) {
                    speciesList.addElement(speciesContexts[i].getSpecies());
                }
            }
            Species[] speciesArray = new Species[speciesList.size()];
            speciesList.copyInto(speciesArray);
            model.setSpecies(speciesArray);
        }
        // 
        if (speciesContexts != null) {
            model.setSpeciesContexts(speciesContexts);
        }
        // 
        // Add global parameters to the model
        // 
        GlobalModelParameterTable.table.setModelParameters(con, model);
        // 
        // add reactionSteps for this model
        // 
        ReactionStep[] reactSteps = reactStepDB.getReactionStepsFromModel(dbc, con, model, modelKey);
        if (reactSteps != null) {
            model.setReactionSteps(reactSteps);
            for (int i = 0; i < reactSteps.length; i++) {
                try {
                    // 
                    // fix any improperly defined reactionSteps (which have parameters that should be catalysts)
                    // name space of kinetic parameters should be unique with respect to SpeciesContexts (so if they overlap, should be a catalyst).
                    // 
                    Kinetics.KineticsParameter[] params = reactSteps[i].getKinetics().getKineticsParameters();
                    for (int j = 0; j < params.length; j++) {
                        SpeciesContext speciesContext = model.getSpeciesContext(params[j].getName());
                        if (speciesContext != null) {
                            reactSteps[i].addCatalyst(speciesContext);
                            if (lg.isWarnEnabled())
                                lg.warn("ModelDbDriver.getModel(), Parameter '" + params[j].getName() + "' in Reaction " + reactSteps[i].getName() + " in Model(" + model.getKey() + ") conflicts with SpeciesContext, added as a catalyst");
                        }
                    }
                } catch (Throwable e) {
                    lg.error(e.getMessage(), e);
                }
                try {
                    reactSteps[i].rebindAllToModel(model);
                } catch (cbit.vcell.parser.ExpressionBindingException e) {
                    throw new DataAccessException("bindingException: " + e.getMessage());
                } catch (cbit.vcell.parser.ExpressionException e) {
                    throw new DataAccessException(e.getMessage());
                } catch (PropertyVetoException e) {
                    throw new DataAccessException("PropertyVetoException: " + e.getMessage());
                } catch (cbit.vcell.model.ModelException e) {
                    throw new DataAccessException(e.getMessage());
                }
            }
        }
        // 
        // add diagrams for this model
        // 
        Diagram[] diagrams = getDiagramsFromModel(dbc, con, modelKey, structureTopology, dbSyntax);
        model.setDiagrams(diagrams);
        // 
        // add rbm
        // 
        ModelTable.readRbmElement(con, model, dbSyntax);
        if (!model.getRbmModelContainer().isEmpty()) {
            for (SpeciesContext sc : model.getSpeciesContexts()) {
                sc.parseSpeciesPatternString(model);
            }
        }
        return model;
    } catch (PropertyVetoException e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException) StructureTopology(cbit.vcell.model.Model.StructureTopology) Diagram(cbit.vcell.model.Diagram) PropertyVetoException(java.beans.PropertyVetoException) StructureKeys(cbit.vcell.modeldb.ReactStepDbDriver.StructureKeys) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model)

Example 15 with Species

use of cbit.vcell.model.Species in project vcell by virtualcell.

the class ReactStepDbDriver method getSpecies.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.Species
 * @param rset java.sql.ResultSet
 * @exception java.sql.SQLException The exception description.
 */
private Species getSpecies(QueryHashtable dbc, ResultSet rset, Connection con) throws SQLException, DataAccessException {
    // 
    // look in object cache (don't instantiate a new one if possible)
    // 
    KeyValue speciesKey = new KeyValue(rset.getBigDecimal(speciesTable.id.toString()));
    Species species = (Species) dbc.get(speciesKey);
    if (species != null) {
        return species;
    } else {
        DBSpecies dbSpeciesRef = null;
        KeyValue dbSpeciesKey = null;
        java.math.BigDecimal dbSpeciesKeyS = rset.getBigDecimal(speciesTable.dbSpeciesRef.toString());
        if (dbSpeciesKeyS != null) {
            dbSpeciesKey = new KeyValue(dbSpeciesKeyS);
        }
        if (dbSpeciesKey != null) {
            dbSpeciesRef = (DBSpecies) dbc.get(dbSpeciesKey);
            if (dbSpeciesRef == null) {
                dbSpeciesRef = dictDB.getDBSpeciesFromKeyValue(dbc, con, dbSpeciesKey);
            }
        }
        species = speciesTable.getSpecies(rset, dbSpeciesRef);
        // 
        // stick new one in cache
        // 
        dbc.put(speciesKey, species);
        return species;
    }
}
Also used : DBSpecies(cbit.vcell.model.DBSpecies) KeyValue(org.vcell.util.document.KeyValue) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies)

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