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:
parent
92b054b71b
commit
0bb4565798
|
|
@ -185,7 +185,7 @@ public class IntervalCleanerWalker extends LocusWindowWalker<Integer, Integer>
|
||||||
// decide which reads potentially need to be cleaned
|
// decide which reads potentially need to be cleaned
|
||||||
for ( SAMRecord read : reads ) {
|
for ( SAMRecord read : reads ) {
|
||||||
// first, move existing indels (for 1 indel reads only) to leftmost position within identical sequence
|
// 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));
|
read.setCigar(indelRealignment(read.getCigar(), reference, read.getReadString(), read.getAlignmentStart()-(int)leftmostIndex));
|
||||||
|
|
||||||
AlignedRead aRead = new AlignedRead(read);
|
AlignedRead aRead = new AlignedRead(read);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.broadinstitute.sting.playground.indels;
|
package org.broadinstitute.sting.playground.indels;
|
||||||
|
|
||||||
|
import net.sf.samtools.CigarOperator;
|
||||||
import net.sf.samtools.SAMRecord;
|
import net.sf.samtools.SAMRecord;
|
||||||
import net.sf.samtools.Cigar;
|
import net.sf.samtools.Cigar;
|
||||||
import net.sf.samtools.CigarElement;
|
import net.sf.samtools.CigarElement;
|
||||||
|
|
@ -139,6 +140,26 @@ public class AlignmentUtils {
|
||||||
return mismatches;
|
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
|
/** Reads through the alignment cigar and returns all indels found in the alignment as a collection
|
||||||
* of Indel objects.
|
* of Indel objects.
|
||||||
|
|
@ -243,8 +264,8 @@ public class AlignmentUtils {
|
||||||
case D : c = 'D'; break;
|
case D : c = 'D'; break;
|
||||||
case I : c = 'I'; break;
|
case I : c = 'I'; break;
|
||||||
}
|
}
|
||||||
b.append(c);
|
|
||||||
b.append(cig.getCigarElement(i).getLength());
|
b.append(cig.getCigarElement(i).getLength());
|
||||||
|
b.append(c);
|
||||||
}
|
}
|
||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue