use of org.jbei.ice.lib.utils.UtilityException in project ice by JBEI.
the class SequenceDAO method getFeatureBySequence.
/**
* Retrieve the {@link Feature} object with the given DNA sequence string.
*
* @param featureDnaSequence dna sequence of feature
* @return Feature object.
* @throws DAOException
*/
private Feature getFeatureBySequence(String featureDnaSequence) {
featureDnaSequence = featureDnaSequence.toLowerCase();
try {
String hash = SequenceUtils.calculateSequenceHash(featureDnaSequence);
CriteriaQuery<Feature> query = getBuilder().createQuery(Feature.class);
Root<Feature> from = query.from(Feature.class);
query.where(getBuilder().equal(from.get("hash"), hash));
Optional<Feature> result = currentSession().createQuery(query).uniqueResultOptional();
if (result.isPresent())
return result.get();
String reverseComplement = SequenceUtils.reverseComplement(featureDnaSequence);
String sequenceHash = SequenceUtils.calculateSequenceHash(reverseComplement);
query.getRestriction().getExpressions().clear();
query.where(getBuilder().equal(from.get("hash"), sequenceHash));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException | UtilityException e) {
Logger.error(e);
throw new DAOException("Failed to get Feature by sequence!", e);
}
}
Aggregations