use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class DictionaryDbDriver method getCompoundFromCasID.
/**
* Returns the compound referenced by the casID
* @return Compound
* @param con Connection
* @param casID String
*/
public FormalCompound getCompoundFromCasID(Connection con, String casID) throws SQLException {
FormalCompound result = null;
DBFormalSpecies[] dbfsArr = getDatabaseSpecies(con, null, casID, false, FormalSpeciesType.compound, FormalSpeciesType.COMPOUND_CASID, -1, false);
if (dbfsArr != null && dbfsArr.length == 1) {
result = (FormalCompound) dbfsArr[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
return result;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class DictionaryDbDriver method getEnzymeFromECNumber.
/**
* Returns the enzyme referenced by the given ECNumber
* @return Enzyme
* @param con Connection
* @param ecNumber String
*/
public FormalEnzyme getEnzymeFromECNumber(Connection con, String ecNumber) throws SQLException {
FormalEnzyme result = null;
DBFormalSpecies[] dbfsArr = getDatabaseSpecies(con, null, ecNumber, false, FormalSpeciesType.enzyme, FormalSpeciesType.ENZYME_ECNUMBER, -1, false);
if (dbfsArr != null && dbfsArr.length > 0) {
result = (FormalEnzyme) dbfsArr[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
return result;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class DictionaryDbDriver method getProteinFromSwissProtID.
/**
* Returns the protein referenced by the given SwissProt Accession Number
* @return Protein
* @param con Connection
* @param swissProtID String
*/
public FormalProtein getProteinFromSwissProtID(Connection con, String swissProtID) throws SQLException {
FormalProtein result = null;
DBFormalSpecies[] dbfsArr = getDatabaseSpecies(con, null, swissProtID, false, FormalSpeciesType.protein, FormalSpeciesType.PROTEIN_SWISSPROTID, -1, false);
if (dbfsArr != null && dbfsArr.length > 0) {
result = (FormalProtein) dbfsArr[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
return result;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class ReactStepTable method getSQLUserReactionListQuery.
/**
* Insert the method's description here.
* Creation date: (7/12/2003 2:59:27 PM)
* @return java.lang.String
* @param likeString java.lang.String
*/
public String getSQLUserReactionListQuery(ReactionQuerySpec rqs, User user, DatabaseSyntax dbSyntax) {
String reactant_or_flux_likeString = rqs.getReactantLikeString();
String catalyst_likeString = rqs.getCatalystLikeString();
String product_likeString = rqs.getProductLikeString();
DBFormalSpecies reactant_or_flux_dbspecies = rqs.getReactantBoundSpecies();
DBFormalSpecies catalyst_dbspecies = rqs.getCatalystBoundSpecies();
DBFormalSpecies product_dbspecies = rqs.getProductBoundSpecies();
String repWildCard = rqs.getAnyReactionParticipantLikeString();
DBFormalSpecies typeWildCard = rqs.getAnyReactionParticipantBoundSpecies();
// Get list of distinct USER reactions that are visible to user
//
// Create comma-separated lists of dbspeciesid
//
StringBuffer reactant_flux_list = new StringBuffer();
StringBuffer catalyst_list = new StringBuffer();
StringBuffer product_list = new StringBuffer();
if (reactant_or_flux_dbspecies != null) {
reactant_flux_list.append(reactant_or_flux_dbspecies.getDBFormalSpeciesKey().toString());
}
if (catalyst_dbspecies != null) {
catalyst_list.append(catalyst_dbspecies.getDBFormalSpeciesKey().toString());
}
if (product_dbspecies != null) {
product_list.append(product_dbspecies.getDBFormalSpeciesKey().toString());
}
// Creat conditions for flux,reaction,catalyst,product
boolean[] bNeedsDBSpeciesTableArr = new boolean[3];
StringBuffer[] subConditionsArr = new StringBuffer[3];
for (int i = 0; i < 3; i += 1) {
boolean bHasLike = false;
boolean bHasDBspid = false;
StringBuffer subConditions = new StringBuffer();
subConditionsArr[i] = subConditions;
if (i == 0) {
bHasLike = (reactant_or_flux_likeString != null && reactant_or_flux_likeString.length() > 0);
bHasDBspid = (reactant_or_flux_dbspecies != null);
if (!bHasLike && !bHasDBspid) {
continue;
}
subConditions.append("(");
subConditions.append("(vc_reactpart_sub.role = 'reactant' OR vc_reactpart_sub.role = 'flux') AND ");
if (bHasLike) {
subConditions.append("upper(vc_species_sub.commonname) LIKE upper('" + reactant_or_flux_likeString + "')");
if (bHasDBspid) {
subConditions.append(" OR ");
}
}
if (bHasDBspid) {
bNeedsDBSpeciesTableArr[i] = true;
// subConditions.append("vc_species_sub.dbspeciesref IN ("+reactant_flux_list.toString()+")");
subConditions.append("vc_species_sub.dbspeciesref = vc_dbspecies_sub.id AND (");
subConditions.append("vc_dbspecies_sub.compoundref IN (" + reactant_flux_list.toString() + ") OR ");
subConditions.append("vc_dbspecies_sub.enzymeref IN (" + reactant_flux_list.toString() + ") OR ");
subConditions.append("vc_dbspecies_sub.proteinref IN (" + reactant_flux_list.toString() + ")");
subConditions.append(")");
}
subConditions.append(")");
} else if (i == 1) {
bHasLike = (catalyst_likeString != null && catalyst_likeString.length() > 0);
bHasDBspid = (catalyst_dbspecies != null);
if (!bHasLike && !bHasDBspid) {
continue;
}
if (subConditions.length() > 0) {
subConditions.append(" AND ");
}
subConditions.append("(");
subConditions.append("vc_reactpart_sub.role = 'catalyst' AND ");
if (bHasLike) {
subConditions.append("upper(vc_species_sub.commonname) LIKE upper('" + catalyst_likeString + "')");
if (bHasDBspid) {
subConditions.append(" OR ");
}
}
if (bHasDBspid) {
bNeedsDBSpeciesTableArr[i] = true;
// subConditions.append("vc_species_sub.dbspeciesref IN ("+catalyst_list.toString()+")");
subConditions.append("vc_species_sub.dbspeciesref = vc_dbspecies_sub.id AND (");
subConditions.append("vc_dbspecies_sub.compoundref IN (" + catalyst_list.toString() + ") OR ");
subConditions.append("vc_dbspecies_sub.enzymeref IN (" + catalyst_list.toString() + ") OR ");
subConditions.append("vc_dbspecies_sub.proteinref IN (" + catalyst_list.toString() + ")");
subConditions.append(")");
}
subConditions.append(")");
} else if (i == 2) {
bHasLike = (product_likeString != null && product_likeString.length() > 0);
bHasDBspid = (product_dbspecies != null);
if (!bHasLike && !bHasDBspid) {
continue;
}
if (subConditions.length() > 0) {
subConditions.append(" AND ");
}
subConditions.append("(");
subConditions.append("vc_reactpart_sub.role = 'product' AND ");
if (bHasLike) {
subConditions.append("upper(vc_species_sub.commonname) LIKE upper('" + product_likeString + "')");
if (bHasDBspid) {
subConditions.append(" OR ");
}
}
if (bHasDBspid) {
bNeedsDBSpeciesTableArr[i] = true;
// subConditions.append("vc_species_sub.dbspeciesref IN ("+product_list.toString()+")");
subConditions.append("vc_species_sub.dbspeciesref = vc_dbspecies_sub.id AND (");
subConditions.append("vc_dbspecies_sub.compoundref IN (" + product_list.toString() + ") OR ");
subConditions.append("vc_dbspecies_sub.enzymeref IN (" + product_list.toString() + ") OR ");
subConditions.append("vc_dbspecies_sub.proteinref IN (" + product_list.toString() + ")");
subConditions.append(")");
}
subConditions.append(")");
}
}
//
String sql = null;
Field specialBMField = new Field("id bmid", SQLDataType.integer, "");
specialBMField.setTableName(BioModelTable.table.getTableName());
Field[] f = { // 1
ReactStepTable.table.name, // 2
ReactStepTable.table.id, // 3
ReactStepTable.table.reactType, // 4
ReactPartTable.table.role, // 5
ReactPartTable.table.stoich, // 6
SpeciesTable.table.commonName, // 7
specialBMField, // 8
ReactStepTable.table.structRef };
Table[] t = { ReactStepTable.table, BioModelTable.table, ReactPartTable.table, SpeciesContextModelTable.table, SpeciesTable.table };
//
//
// Non-WildCard subcondition
boolean hadPreviousCondiiton = false;
String searchConditions = "";
for (int i = 0; i < 3; i += 1) {
if (subConditionsArr[i].length() > 0) {
//
if (hadPreviousCondiiton) {
searchConditions += " INTERSECT ";
}
hadPreviousCondiiton = true;
//
searchConditions += "(" + " SELECT " + Table.SQL_GLOBAL_HINT + " DISTINCT " + " vc_reactstep_sub.id " + " FROM " + ReactStepTable.table.getTableName() + " vc_reactstep_sub" + "," + ReactPartTable.table.getTableName() + " vc_reactpart_sub" + "," + SpeciesContextModelTable.table.getTableName() + " vc_modelsc_sub" + "," + SpeciesTable.table.getTableName() + " vc_species_sub" + (bNeedsDBSpeciesTableArr[i] ? "," + DBSpeciesTable.table.getTableName() + " vc_dbspecies_sub" : "") + " WHERE " + subConditionsArr[i].toString() + " AND " + " vc_species_sub.id=vc_modelsc_sub.speciesref AND " + " vc_modelsc_sub.modelref = " + BioModelTable.table.modelRef.getQualifiedColName() + " AND " + " vc_modelsc_sub.id=vc_reactpart_sub.scref AND " + " vc_reactpart_sub.reactstepref=vc_reactstep_sub.id " + ")";
}
}
// WildCard subcondtion
if (repWildCard != null || typeWildCard != null) {
searchConditions = "(" + " SELECT " + Table.SQL_GLOBAL_HINT + " DISTINCT " + " vc_reactstep_sub.id " + " FROM " + ReactStepTable.table.getTableName() + " vc_reactstep_sub" + "," + ReactPartTable.table.getTableName() + " vc_reactpart_sub" + "," + SpeciesContextModelTable.table.getTableName() + " vc_modelsc_sub" + "," + SpeciesTable.table.getTableName() + " vc_species_sub" + (typeWildCard != null ? "," + DBSpeciesTable.table.getTableName() + " vc_dbspecies_sub" : "") + " WHERE " + "(" + (repWildCard != null ? "upper(vc_species_sub.commonname) LIKE upper('" + repWildCard + "')" : "") + (repWildCard != null && typeWildCard != null ? " OR " : "") + (typeWildCard != null ? "(" + "vc_species_sub.dbspeciesref IS NOT NULL AND " + "vc_species_sub.dbspeciesref = vc_dbspecies_sub.id AND " + "(" + "vc_dbspecies_sub.compoundref=" + typeWildCard.getDBFormalSpeciesKey() + " OR " + "vc_dbspecies_sub.enzymeref=" + typeWildCard.getDBFormalSpeciesKey() + " OR " + "vc_dbspecies_sub.proteinref=" + typeWildCard.getDBFormalSpeciesKey() + ")" + ")" : "") + ")" + " AND " + " vc_species_sub.id=vc_modelsc_sub.speciesref AND " + " vc_modelsc_sub.modelref = " + BioModelTable.table.modelRef.getQualifiedColName() + " AND " + " vc_modelsc_sub.id=vc_reactpart_sub.scref AND " + " vc_reactpart_sub.reactstepref=vc_reactstep_sub.id " + ")";
}
//
//
//
String condition = "";
if (searchConditions.length() > 0) {
condition += ReactStepTable.table.id.getQualifiedColName() + " IN " + "(" + searchConditions + ")" + " AND ";
}
condition += SpeciesTable.table.id.getQualifiedColName() + " = " + SpeciesContextModelTable.table.speciesRef.getQualifiedColName() + " AND " + SpeciesContextModelTable.table.id.getQualifiedColName() + " = " + ReactPartTable.table.scRef.getQualifiedColName() + " AND " + ReactPartTable.table.reactStepRef.getQualifiedColName() + " = " + ReactStepTable.table.id.getQualifiedColName() + " AND " + ReactStepTable.table.modelRef.getQualifiedColName() + " = " + BioModelTable.table.modelRef.getQualifiedColName();
String special = " ORDER BY " + ReactStepTable.table.id.getQualifiedColName();
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, special, dbSyntax, true);
StringBuffer sb = new StringBuffer(sql);
// LOBs cannot be accessed if the query uses the DISTINCT or UNIQUE keyword
sb.insert(7, Table.SQL_GLOBAL_HINT + " DISTINCT ");
return sb.toString();
}
Aggregations