added AlignmentUtils.getNumAlignmentBlocks(read) - a faster alternative to read.getAlignmentBlocks().size(); IntervalCleaner updated accordingly.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@923 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
asivache 2009-06-06 19:35:21 +00:00
parent 92b054b71b
commit 0bb4565798
2 changed files with 23 additions and 2 deletions

View File

@ -185,7 +185,7 @@ public class IntervalCleanerWalker extends LocusWindowWalker<Integer, Integer>
// decide which reads potentially need to be cleaned
for ( SAMRecord read : reads ) {
// first, move existing indels (for 1 indel reads only) to leftmost position within identical sequence
if ( read.getAlignmentBlocks().size() == 2 )
if ( AlignmentUtils.getNumAlignmentBlocks(read) == 2 )
read.setCigar(indelRealignment(read.getCigar(), reference, read.getReadString(), read.getAlignmentStart()-(int)leftmostIndex));
AlignedRead aRead = new AlignedRead(read);

View File

@ -1,5 +1,6 @@
package org.broadinstitute.sting.playground.indels;
import net.sf.samtools.CigarOperator;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.Cigar;
import net.sf.samtools.CigarElement;
@ -139,6 +140,26 @@ public class AlignmentUtils {
return mismatches;
}
/** Returns number of alignment blocks (continuous stretches of aligned bases) in the specified alignment.
* This method follows closely the SAMRecord::getAlignmentBlocks() implemented in samtools library, but
* it only counts blocks without actually allocating and filling the list of blocks themselves. Hence, this method is
* a much more efficient alternative to r.getAlignmentBlocks.size() in the situations when this number is all that is needed.
* Formally, this method simply returns the number of M elements in the cigar.
* @param r alignment
* @return number of continuous alignment blocks (i.e. 'M' elements of the cigar; all indel and clipping elements are ignored).
*/
public static int getNumAlignmentBlocks(final SAMRecord r) {
int n = 0;
final Cigar cigar = r.getCigar();
if (cigar == null) return 0;
for (final CigarElement e : cigar.getCigarElements()) {
if (e.getOperator() == CigarOperator.M ) n++;
}
return n;
}
/** Reads through the alignment cigar and returns all indels found in the alignment as a collection
* of Indel objects.
@ -243,8 +264,8 @@ public class AlignmentUtils {
case D : c = 'D'; break;
case I : c = 'I'; break;
}
b.append(c);
b.append(cig.getCigarElement(i).getLength());
b.append(c);
}
return b.toString();
}