Search in sources :

Example 1 with BlastPlus

use of org.jbei.ice.lib.search.blast.BlastPlus 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);
    }
}
Also used : BlastPlus(org.jbei.ice.lib.search.blast.BlastPlus) Bl2SeqResult(org.jbei.ice.lib.parsers.bl2seq.Bl2SeqResult) Date(java.util.Date) BlastException(org.jbei.ice.lib.search.blast.BlastException)

Example 2 with BlastPlus

use of org.jbei.ice.lib.search.blast.BlastPlus in project ice by JBEI.

the class PartTraceSequences 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 = 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;
                }
            }
            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);
    }
}
Also used : BlastPlus(org.jbei.ice.lib.search.blast.BlastPlus) Bl2SeqResult(org.jbei.ice.lib.parsers.bl2seq.Bl2SeqResult) Date(java.util.Date) BlastException(org.jbei.ice.lib.search.blast.BlastException)

Aggregations

Date (java.util.Date)2 Bl2SeqResult (org.jbei.ice.lib.parsers.bl2seq.Bl2SeqResult)2 BlastException (org.jbei.ice.lib.search.blast.BlastException)2 BlastPlus (org.jbei.ice.lib.search.blast.BlastPlus)2