use of org.jbei.ice.storage.model.Feature in project ice by JBEI.
the class BlastPlus method writeBigFastaFileForFeatures.
/**
* Writes the fasta file (part of the blast database) that contains all the features that exists on this system.
* This routine is expected to be called as part of the blast sequence feature database rebuild
*
* @param writer writer for fasta file
* @throws BlastException
*/
private static void writeBigFastaFileForFeatures(BufferedWriter writer) throws BlastException {
FeatureDAO featureDAO = DAOFactory.getFeatureDAO();
SequenceFeatureDAO sequenceFeatureDAO = DAOFactory.getSequenceFeatureDAO();
long count = featureDAO.getFeatureCount(null);
if (count <= 0)
return;
int offset = 0;
while (offset < count) {
List<Feature> features = featureDAO.getFeatures(offset++, 1, null);
Feature feature = features.get(0);
String featureName = feature.getName();
if (featureName == null || featureName.trim().isEmpty())
continue;
if (feature.getCuration() != null && feature.getCuration().isExclude())
continue;
boolean hasNegativeStrand = false;
boolean hasPositiveStrand = false;
List<SequenceFeature> sequenceFeatures = sequenceFeatureDAO.getByFeature(feature);
if (sequenceFeatures == null || sequenceFeatures.isEmpty()) {
hasPositiveStrand = true;
} else {
for (SequenceFeature sequenceFeature : sequenceFeatures) {
if (sequenceFeature.getStrand() == 1) {
hasPositiveStrand = true;
} else if (sequenceFeature.getStrand() == -1) {
hasNegativeStrand = true;
}
}
}
try {
String sequenceString = feature.getSequence().trim();
if (StringUtils.isEmpty(sequenceString))
continue;
if (hasNegativeStrand) {
try {
SymbolList symbolList = DNATools.createDNA(sequenceString);
symbolList = DNATools.reverseComplement(symbolList);
writeSequenceString(feature, writer, symbolList.seqString(), -1);
} catch (IllegalSymbolException | IllegalAlphabetException e) {
Logger.warn(e.getMessage());
continue;
}
}
if (hasPositiveStrand) {
writeSequenceString(feature, writer, sequenceString, 1);
}
} catch (IOException e) {
throw new BlastException(e);
}
}
}
use of org.jbei.ice.storage.model.Feature in project ice by JBEI.
the class FeatureDAO method getByFeatureSequence.
/**
* Retrieve the {@link Feature} object with the given DNA sequence string.
*
* @param featureDnaSequence dna sequence of feature
* @return Optional Feature object.
* @throws DAOException on Hibernate or UtilityException
*/
public Optional<Feature> getByFeatureSequence(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));
return currentSession().createQuery(query).uniqueResultOptional();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to get Feature by sequence!", e);
}
}
Aggregations