use of org.jbei.ice.lib.search.blast.BlastException in project ice by JBEI.
the class SearchController method runSearch.
/**
* Executes search using parameters specified in the query.
*
* @param userId unique user identifier making the request. This can be null if the request is via web of
* registries
* @param query wrapper around search query
* @return wrapper around the list of search results
*/
public SearchResults runSearch(String userId, SearchQuery query) {
String queryString = query.getQueryString();
HashMap<String, SearchResult> blastResults = null;
// check if there is a blast result and run first
if (query.hasBlastQuery()) {
if (query.getBlastQuery().getBlastProgram() == null)
query.getBlastQuery().setBlastProgram(BlastProgram.BLAST_N);
try {
blastResults = BlastPlus.runBlast(query.getBlastQuery());
} catch (BlastException e) {
Logger.error("Exception running blast " + e.getMessage());
}
}
// if no other search query or filter and there are blast results (not null) then return the blast results
if (StringUtils.isEmpty(queryString) && blastResults != null && !query.hasFilter()) {
if (blastResults.isEmpty())
return new SearchResults();
int start = query.getParameters().getStart();
int count = query.getParameters().getRetrieveCount();
return HibernateSearch.getInstance().filterBlastResults(userId, start, count, query, blastResults);
}
// text query (may also include blast)
// no filter type indicates a term or phrase query
HibernateSearch hibernateSearch = HibernateSearch.getInstance();
if (!StringUtils.isEmpty(queryString)) {
HashMap<String, QueryType> terms = parseQueryString(queryString);
return hibernateSearch.executeSearch(userId, terms, query, blastResults);
} else {
return hibernateSearch.executeSearchNoTerms(userId, blastResults, query);
}
}
use of org.jbei.ice.lib.search.blast.BlastException in project ice by JBEI.
the class Annotations method generate.
/**
* Using existing and potentially curated annotations on this ICE instance,
* this generates matching features for the passed sequence
*
* @param sequence wrapper around dna sequence
* @return wrapper around passed sequence and now with list if annotations for that sequence
*/
public FeaturedDNASequence generate(FeaturedDNASequence sequence) {
BlastQuery query = new BlastQuery();
query.setSequence(sequence.getSequence());
try {
List<DNAFeature> features = featuresBlastDatabase.runBlast(query);
sequence.getFeatures().addAll(features);
return sequence;
} catch (BlastException e) {
Logger.error(e);
return null;
}
}
use of org.jbei.ice.lib.search.blast.BlastException in project ice by JBEI.
the class SequenceAnalysisController method buildOrRebuildAlignment.
/**
* Calculate sequence alignment between the given {@link TraceSequence} and {@link Sequence}
* using bl2seq, and save the result into the database.
*
* @param traceSequence traceSequence
* @param sequence sequence
*/
public void buildOrRebuildAlignment(TraceSequence traceSequence, Sequence sequence) {
if (traceSequence == null) {
throw new IllegalArgumentException("Failed to rebuild alignment for null trace sequence!");
}
// if sequence is null => delete alignment
if (sequence == null || sequence.getEntry() == null) {
return;
}
// actually build alignment
String traceSequenceString = traceSequence.getSequence();
String entrySequenceString = sequence.getSequence();
int entrySequenceLength = entrySequenceString.length();
boolean isCircular = (sequence.getEntry().getRecordType().equalsIgnoreCase("plasmid")) && ((Plasmid) sequence.getEntry()).getCircular();
if (isCircular) {
entrySequenceString += entrySequenceString;
}
try {
List<Bl2SeqResult> bl2seqAlignmentResults = BlastPlus.runBlast2Seq(entrySequenceString, traceSequenceString);
if (bl2seqAlignmentResults.size() > 0) {
int maxAlignedSequenceLength = -1;
Bl2SeqResult maxBl2SeqResult = null;
for (Bl2SeqResult bl2seqResult : bl2seqAlignmentResults) {
int querySequenceLength = bl2seqResult.getQuerySequence().length();
if (maxAlignedSequenceLength < querySequenceLength) {
maxAlignedSequenceLength = querySequenceLength;
maxBl2SeqResult = bl2seqResult;
}
}
if (maxBl2SeqResult != null) {
int strand = maxBl2SeqResult.getOrientation() == 0 ? 1 : -1;
TraceSequenceAlignment traceSequenceAlignment = traceSequence.getTraceSequenceAlignment();
int queryStart = maxBl2SeqResult.getQueryStart();
int queryEnd = maxBl2SeqResult.getQueryEnd();
int subjectStart = maxBl2SeqResult.getSubjectStart();
int subjectEnd = maxBl2SeqResult.getSubjectEnd();
if (isCircular) {
if (queryStart > entrySequenceLength - 1) {
queryStart = queryStart - entrySequenceLength;
}
if (queryEnd > entrySequenceLength - 1) {
queryEnd = queryEnd - entrySequenceLength;
}
if (subjectEnd > entrySequenceLength - 1) {
subjectEnd = subjectEnd - entrySequenceLength;
}
if (subjectStart > entrySequenceLength - 1) {
subjectStart = subjectStart - entrySequenceLength;
}
}
if (traceSequenceAlignment == null) {
traceSequenceAlignment = new TraceSequenceAlignment(traceSequence, maxBl2SeqResult.getScore(), strand, queryStart, queryEnd, subjectStart, subjectEnd, maxBl2SeqResult.getQuerySequence(), maxBl2SeqResult.getSubjectSequence(), sequence.getFwdHash(), new Date());
traceSequence.setTraceSequenceAlignment(traceSequenceAlignment);
} else {
traceSequenceAlignment.setModificationTime(new Date());
traceSequenceAlignment.setScore(maxBl2SeqResult.getScore());
traceSequenceAlignment.setStrand(strand);
traceSequenceAlignment.setQueryStart(queryStart);
traceSequenceAlignment.setQueryEnd(queryEnd);
traceSequenceAlignment.setSubjectStart(subjectStart);
traceSequenceAlignment.setSubjectEnd(subjectEnd);
traceSequenceAlignment.setQueryAlignment(maxBl2SeqResult.getQuerySequence());
traceSequenceAlignment.setSubjectAlignment(maxBl2SeqResult.getSubjectSequence());
traceSequenceAlignment.setSequenceHash(sequence.getFwdHash());
}
traceDao.save(traceSequence);
}
}
} catch (BlastException e) {
Logger.error(e);
}
}
use of org.jbei.ice.lib.search.blast.BlastException in project ice by JBEI.
the class TraceSequences method buildOrRebuildAlignment.
/**
* Calculate sequence alignment between the given {@link TraceSequence} and {@link Sequence}
* using bl2seq, and save the result into the database.
*
* @param traceSequence traceSequence
* @param sequence sequence
*/
public void buildOrRebuildAlignment(TraceSequence traceSequence, Sequence sequence) {
if (traceSequence == null) {
throw new IllegalArgumentException("Failed to rebuild alignment for null trace sequence!");
}
// if sequence is null => delete alignment
if (sequence == null || sequence.getEntry() == null) {
return;
}
// actually build alignment
String traceSequenceString = traceSequence.getSequence();
String entrySequenceString = sequence.getSequence();
int entrySequenceLength = entrySequenceString.length();
boolean isCircular = (sequence.getEntry() instanceof Plasmid) && ((Plasmid) sequence.getEntry()).getCircular();
if (isCircular) {
entrySequenceString += entrySequenceString;
}
try {
List<Bl2SeqResult> bl2seqAlignmentResults = BlastPlus.runBlast2Seq(entrySequenceString, traceSequenceString);
if (bl2seqAlignmentResults.size() > 0) {
int maxAlignedSequenceLength = -1;
Bl2SeqResult maxBl2SeqResult = null;
for (Bl2SeqResult bl2seqResult : bl2seqAlignmentResults) {
int querySequenceLength = bl2seqResult.getQuerySequence().length();
if (maxAlignedSequenceLength < querySequenceLength) {
maxAlignedSequenceLength = querySequenceLength;
maxBl2SeqResult = bl2seqResult;
}
}
if (maxBl2SeqResult != null) {
int strand = maxBl2SeqResult.getOrientation() == 0 ? 1 : -1;
TraceSequenceAlignment traceSequenceAlignment = traceSequence.getTraceSequenceAlignment();
int queryStart = maxBl2SeqResult.getQueryStart();
int queryEnd = maxBl2SeqResult.getQueryEnd();
int subjectStart = maxBl2SeqResult.getSubjectStart();
int subjectEnd = maxBl2SeqResult.getSubjectEnd();
if (isCircular) {
if (queryStart > entrySequenceLength - 1) {
queryStart = queryStart - entrySequenceLength;
}
if (queryEnd > entrySequenceLength - 1) {
queryEnd = queryEnd - entrySequenceLength;
}
if (subjectEnd > entrySequenceLength - 1) {
subjectEnd = subjectEnd - entrySequenceLength;
}
if (subjectStart > entrySequenceLength - 1) {
subjectStart = subjectStart - entrySequenceLength;
}
}
if (traceSequenceAlignment == null) {
traceSequenceAlignment = new TraceSequenceAlignment(traceSequence, maxBl2SeqResult.getScore(), strand, queryStart, queryEnd, subjectStart, subjectEnd, maxBl2SeqResult.getQuerySequence(), maxBl2SeqResult.getSubjectSequence(), sequence.getFwdHash(), new Date());
traceSequence.setTraceSequenceAlignment(traceSequenceAlignment);
} else {
traceSequenceAlignment.setModificationTime(new Date());
traceSequenceAlignment.setScore(maxBl2SeqResult.getScore());
traceSequenceAlignment.setStrand(strand);
traceSequenceAlignment.setQueryStart(queryStart);
traceSequenceAlignment.setQueryEnd(queryEnd);
traceSequenceAlignment.setSubjectStart(subjectStart);
traceSequenceAlignment.setSubjectEnd(subjectEnd);
traceSequenceAlignment.setQueryAlignment(maxBl2SeqResult.getQuerySequence());
traceSequenceAlignment.setSubjectAlignment(maxBl2SeqResult.getSubjectSequence());
traceSequenceAlignment.setSequenceHash(sequence.getFwdHash());
}
dao.save(traceSequence);
}
}
} catch (BlastException e) {
Logger.error(e);
}
}
use of org.jbei.ice.lib.search.blast.BlastException in project ice by JBEI.
the class TraceSequences method buildOrRebuildAlignment.
/**
* Calculate sequence alignment between the given {@link TraceSequence} and {@link Sequence}
* using bl2seq, and save the result into the database.
*
* @param traceSequence traceSequence
* @param sequence sequence
*/
public void buildOrRebuildAlignment(TraceSequence traceSequence, Sequence sequence) {
if (traceSequence == null) {
throw new IllegalArgumentException("Failed to rebuild alignment for null trace sequence!");
}
// if sequence is null => delete alignment
if (sequence == null || sequence.getEntry() == null) {
return;
}
// actually build alignment
String traceSequenceString = traceSequence.getSequence();
String entrySequenceString = sequence.getSequence();
int entrySequenceLength = entrySequenceString.length();
boolean isCircular = (sequence.getEntry().getRecordType().equalsIgnoreCase("plasmid")) && ((Plasmid) sequence.getEntry()).getCircular();
if (isCircular) {
entrySequenceString += entrySequenceString;
}
try {
List<Bl2SeqResult> bl2seqAlignmentResults = new BlastPlus().runBlast2Seq(entrySequenceString, traceSequenceString);
if (bl2seqAlignmentResults.size() > 0) {
int maxAlignedSequenceLength = -1;
Bl2SeqResult maxBl2SeqResult = null;
for (Bl2SeqResult bl2seqResult : bl2seqAlignmentResults) {
int querySequenceLength = bl2seqResult.getQuerySequence().length();
if (maxAlignedSequenceLength < querySequenceLength) {
maxAlignedSequenceLength = querySequenceLength;
maxBl2SeqResult = bl2seqResult;
}
}
int strand = maxBl2SeqResult.getOrientation() == 0 ? 1 : -1;
TraceSequenceAlignment traceSequenceAlignment = traceSequence.getTraceSequenceAlignment();
int queryStart = maxBl2SeqResult.getQueryStart();
int queryEnd = maxBl2SeqResult.getQueryEnd();
int subjectStart = maxBl2SeqResult.getSubjectStart();
int subjectEnd = maxBl2SeqResult.getSubjectEnd();
if (isCircular) {
if (queryStart > entrySequenceLength - 1) {
queryStart = queryStart - entrySequenceLength;
}
if (queryEnd > entrySequenceLength - 1) {
queryEnd = queryEnd - entrySequenceLength;
}
if (subjectEnd > entrySequenceLength - 1) {
subjectEnd = subjectEnd - entrySequenceLength;
}
if (subjectStart > entrySequenceLength - 1) {
subjectStart = subjectStart - entrySequenceLength;
}
}
if (traceSequenceAlignment == null) {
traceSequenceAlignment = new TraceSequenceAlignment(traceSequence, maxBl2SeqResult.getScore(), strand, queryStart, queryEnd, subjectStart, subjectEnd, maxBl2SeqResult.getQuerySequence(), maxBl2SeqResult.getSubjectSequence(), sequence.getFwdHash(), new Date());
traceSequence.setTraceSequenceAlignment(traceSequenceAlignment);
} else {
traceSequenceAlignment.setModificationTime(new Date());
traceSequenceAlignment.setScore(maxBl2SeqResult.getScore());
traceSequenceAlignment.setStrand(strand);
traceSequenceAlignment.setQueryStart(queryStart);
traceSequenceAlignment.setQueryEnd(queryEnd);
traceSequenceAlignment.setSubjectStart(subjectStart);
traceSequenceAlignment.setSubjectEnd(subjectEnd);
traceSequenceAlignment.setQueryAlignment(maxBl2SeqResult.getQuerySequence());
traceSequenceAlignment.setSubjectAlignment(maxBl2SeqResult.getSubjectSequence());
traceSequenceAlignment.setSequenceHash(sequence.getFwdHash());
}
dao.save(traceSequence);
}
} catch (BlastException e) {
Logger.error(e);
}
}
Aggregations