use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class DictionaryDbDriver method getCompoundFromKeggID.
/**
* Returns the compound referenced by the keggID
* @return Compound
* @param con Connection
* @param dbLink DBLink
*/
public FormalCompound getCompoundFromKeggID(Connection con, String keggID) throws SQLException {
FormalCompound result = null;
DBFormalSpecies[] dbfsArr = getDatabaseSpecies(con, null, keggID, false, FormalSpeciesType.compound, FormalSpeciesType.COMPOUND_KEGGID, -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 getBoundSpecies.
/**
* Insert the method's description here.
* Creation date: (2/26/2003 1:38:19 PM)
* @return cbit.vcell.dictionary.DBSpecies
* @param dbfs cbit.vcell.dictionary.DBFormalSpecies
*/
public DBSpecies getBoundSpecies(Connection con, DBFormalSpecies dbfs) throws SQLException {
// Check if this is already a DBSpecies
if (dbfs instanceof DBSpecies) {
return (DBSpecies) dbfs;
}
int restrictsearch = 0;
if (dbfs.getFormalSpeciesType().equals(FormalSpeciesType.compound)) {
restrictsearch = FormalSpeciesType.COMPOUND_KEGGID;
} else if (dbfs.getFormalSpeciesType().equals(FormalSpeciesType.enzyme)) {
restrictsearch = FormalSpeciesType.ENZYME_ECNUMBER;
} else if (dbfs.getFormalSpeciesType().equals(FormalSpeciesType.protein)) {
restrictsearch = FormalSpeciesType.PROTEIN_SWISSPROTID;
} else {
throw new IllegalArgumentException("DictionaryDbDriver.getBoundSpecies: Unsupported FormalSpeciesType");
}
// Check if binding already exists in database
DBFormalSpecies[] dbfsBound = getDatabaseSpecies(con, null, dbfs.getFormalSpeciesInfo().getFormalID(), true, dbfs.getFormalSpeciesType(), restrictsearch, -1, false);
if (dbfsBound != null) {
if (dbfsBound.length == 1) {
return (DBSpecies) dbfsBound[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
}
// Create new binding
// Add entry to binding table
KeyValue newKey = keyFactory.getNewKey(con);
String sql = "INSERT INTO " + DBSpeciesTable.table.getTableName() + " VALUES " + DBSpeciesTable.table.getSQLValueList(newKey, dbfs);
DbDriver.updateCleanSQL(con, sql);
// Get new DBSpecies
dbfsBound = getDatabaseSpecies(con, null, dbfs.getFormalSpeciesInfo().getFormalID(), true, dbfs.getFormalSpeciesType(), restrictsearch, -1, false);
if (dbfsBound != null) {
if (dbfsBound.length == 1) {
return (DBSpecies) dbfsBound[0];
} else {
throw new RuntimeException("Expecting only 1 result");
}
}
throw new RuntimeException("Couldn't Get New DBSpecies");
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class CompoundTable method getCompounds.
/**
* returns a Compound object from the ResultSet
* @return cbit.vcell.dictionary.Compound
* @param rset java.sql.ResultSet
*/
public DBFormalSpecies[] getCompounds(java.sql.ResultSet rset, boolean createBound) throws java.sql.SQLException {
Vector compounds = new Vector();
Vector aliasNames = new Vector();
String currentAliasName = null;
String currentCASID = null;
String currentFormula = null;
String currentKeggID = null;
String currentPreferred = null;
org.vcell.util.document.KeyValue currentCompoundID = null;
org.vcell.util.document.KeyValue currentDBSpeciesID = null;
while (rset.next() || rset.isAfterLast()) {
KeyValue compoundID = null;
if (!rset.isAfterLast()) {
compoundID = new KeyValue(rset.getBigDecimal(CompoundTable.table.id.toString()));
}
if (!rset.isFirst() && (!currentCompoundID.equals(compoundID))) {
if (currentCompoundID != null) {
if (aliasNames.size() > 0) {
String[] aliasNamesArr = new String[aliasNames.size()];
aliasNames.copyInto(aliasNamesArr);
CompoundInfo compoundInfo = new CompoundInfo(currentKeggID, aliasNamesArr, currentFormula, currentCASID, null);
FormalCompound formalCompound = new FormalCompound(currentCompoundID, compoundInfo);
Object compound = formalCompound;
if (createBound) {
BoundCompound boundCompound = new BoundCompound(currentDBSpeciesID, formalCompound);
compound = boundCompound;
}
compounds.add(compound);
}
}
aliasNames.clear();
if (rset.isAfterLast()) {
break;
}
}
if (aliasNames.size() == 0) {
currentCompoundID = compoundID;
currentKeggID = rset.getString(CompoundTable.table.keggID.toString());
currentCASID = rset.getString(CompoundTable.table.casID.toString());
currentFormula = rset.getString(CompoundTable.table.formula.toString());
currentFormula = (currentFormula != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentFormula) : null);
if (createBound) {
currentDBSpeciesID = new KeyValue(rset.getBigDecimal("dbspecies_id"));
}
}
currentPreferred = rset.getString(CompoundAliasTable.table.preferred.toString());
currentAliasName = org.vcell.util.TokenMangler.getSQLRestoredString(rset.getString(CompoundAliasTable.table.name.toString()));
if (currentPreferred.compareToIgnoreCase("T") == 0) {
aliasNames.add(0, currentAliasName);
} else {
aliasNames.add(currentAliasName);
}
}
DBFormalSpecies[] compoundsArr = null;
if (compounds.size() > 0) {
if (createBound) {
BoundCompound[] boundCompoundsArr = null;
boundCompoundsArr = new BoundCompound[compounds.size()];
compounds.copyInto(boundCompoundsArr);
compoundsArr = boundCompoundsArr;
} else {
FormalCompound[] formalCompoundsArr = null;
formalCompoundsArr = new FormalCompound[compounds.size()];
compounds.copyInto(formalCompoundsArr);
compoundsArr = formalCompoundsArr;
}
}
return compoundsArr;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class ProteinTable method getProteins.
/**
* returns a protein object from the ResultSet
* @return cbit.vcell.dictionary.protein
* @param rset java.sql.ResultSet
*/
public DBFormalSpecies[] getProteins(java.sql.ResultSet rset, boolean createBound) throws java.sql.SQLException {
Vector proteins = new Vector();
Vector aliasNames = new Vector();
String currentAliasName = null;
String currentKeywords = null;
String currentSwissProtId = null;
String currentAccession = null;
String currentOrganism = null;
String currentPreferred = null;
String currentDescription = null;
double currentMolWeight = ProteinInfo.UNKNOWN_MW;
org.vcell.util.document.KeyValue currentProteinID = null;
org.vcell.util.document.KeyValue currentDBSpeciesID = null;
while (rset.next() || rset.isAfterLast()) {
KeyValue proteinID = null;
if (!rset.isAfterLast()) {
proteinID = new KeyValue(rset.getBigDecimal(ProteinTable.table.id.toString()));
}
if (!rset.isFirst() && (!currentProteinID.equals(proteinID))) {
if (currentProteinID != null) {
if (aliasNames.size() > 0) {
String[] aliasNamesArr = new String[aliasNames.size()];
aliasNames.copyInto(aliasNamesArr);
String[] keywordsArr = null;
ProteinInfo proteinInfo = new ProteinInfo(currentSwissProtId, aliasNamesArr, currentOrganism, currentAccession, currentKeywords, currentDescription, currentMolWeight);
FormalProtein formalProtein = new FormalProtein(currentProteinID, proteinInfo);
Object protein = formalProtein;
if (createBound) {
BoundProtein boundProtein = new BoundProtein(currentDBSpeciesID, formalProtein);
protein = boundProtein;
}
proteins.add(protein);
}
}
aliasNames.clear();
if (rset.isAfterLast()) {
break;
}
}
if (aliasNames.size() == 0) {
currentProteinID = proteinID;
currentSwissProtId = rset.getString(ProteinTable.table.swissProtEntryName.toString());
currentAccession = rset.getString(ProteinTable.table.accessionNumber.toString());
currentOrganism = rset.getString(ProteinTable.table.organism.toString());
currentOrganism = (currentOrganism != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentOrganism) : null);
currentKeywords = rset.getString(ProteinTable.table.keywords.toString());
currentKeywords = (currentKeywords != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentKeywords) : null);
currentDescription = rset.getString(ProteinTable.table.description.toString());
currentDescription = (currentDescription != null ? org.vcell.util.TokenMangler.getSQLRestoredString(currentDescription) : null);
currentMolWeight = rset.getDouble(ProteinTable.table.molWeight.toString());
if (rset.wasNull()) {
currentMolWeight = ProteinInfo.UNKNOWN_MW;
}
if (createBound) {
currentDBSpeciesID = new KeyValue(rset.getBigDecimal("dbspecies_id"));
}
}
currentAliasName = org.vcell.util.TokenMangler.getSQLRestoredString(rset.getString(ProteinAliasTable.table.name.toString()));
if (!aliasNames.contains(currentAliasName)) {
currentPreferred = rset.getString(ProteinAliasTable.table.preferred.toString());
if (currentPreferred.compareToIgnoreCase("true") == 0) {
aliasNames.add(0, currentAliasName);
} else {
aliasNames.add(currentAliasName);
}
}
}
DBFormalSpecies[] proteinsArr = null;
if (proteins.size() > 0) {
if (createBound) {
BoundProtein[] boundProteinsArr = null;
boundProteinsArr = new BoundProtein[proteins.size()];
proteins.copyInto(boundProteinsArr);
proteinsArr = boundProteinsArr;
} else {
FormalProtein[] formalProteinsArr = null;
formalProteinsArr = new FormalProtein[proteins.size()];
proteins.copyInto(formalProteinsArr);
proteinsArr = formalProteinsArr;
}
}
return proteinsArr;
}
use of cbit.vcell.model.DBFormalSpecies in project vcell by virtualcell.
the class XmlReader method getDBFormalSpecies.
/**
* This method returns a DBFormalSpecies from a XML representation.
* Creation date: (6/3/2003 8:46:44 PM)
* @return cbit.vcell.dictionary.DBFormalSpecies
* @param formalSpeciesElement org.jdom.Element
*/
private DBFormalSpecies getDBFormalSpecies(Element formalSpeciesElement) throws XmlParseException {
// read key
String keystring = formalSpeciesElement.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = new KeyValue(keystring);
// read type
String typestring = formalSpeciesElement.getAttributeValue(XMLTags.TypeAttrTag);
// read the FormalSpeciesInfo
Element speciesInfoElement = formalSpeciesElement.getChild(XMLTags.FormalSpeciesInfoTag, vcNamespace);
// create the DBFormalSpecies upon the type
DBFormalSpecies formalSpecies = null;
if (typestring.equalsIgnoreCase(XMLTags.CompoundTypeTag)) {
formalSpecies = new FormalCompound(key, (CompoundInfo) getFormalSpeciesInfo(speciesInfoElement));
} else if (typestring.equalsIgnoreCase(XMLTags.EnzymeTypeTag)) {
formalSpecies = new FormalEnzyme(key, (EnzymeInfo) getFormalSpeciesInfo(speciesInfoElement));
} else if (typestring.equalsIgnoreCase(XMLTags.ProteinTypeTag)) {
formalSpecies = new FormalProtein(key, (ProteinInfo) getFormalSpeciesInfo(speciesInfoElement));
} else {
throw new XmlParseException("DBFormalSpecies type:" + typestring + ", not supported yet!");
}
return formalSpecies;
}
Aggregations