Merge pull request #299 from broadinstitute/eb_mate_fixer_confused_by_nonprimary_alignment
Another fix for the Indel Realigner that arises because of secondary alignments.
This commit is contained in:
commit
d8ca4d3e6d
|
|
@ -130,7 +130,7 @@ public class ConstrainedMateFixingManager {
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
/** How often do we check whether we want to emit reads? */
|
/** How often do we check whether we want to emit reads? */
|
||||||
private final static int EMIT_FREQUENCY = 1000;
|
protected final static int EMIT_FREQUENCY = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much could a single read move in position from its original position?
|
* How much could a single read move in position from its original position?
|
||||||
|
|
@ -324,6 +324,7 @@ public class ConstrainedMateFixingManager {
|
||||||
|| noReadCanMoveBefore(read.getMateAlignmentStart(), newRead ) ) ) { // we're already past where the mate started
|
|| noReadCanMoveBefore(read.getMateAlignmentStart(), newRead ) ) ) { // we're already past where the mate started
|
||||||
|
|
||||||
// remove reads from the map that we have emitted -- useful for case where the mate never showed up
|
// remove reads from the map that we have emitted -- useful for case where the mate never showed up
|
||||||
|
if ( !read.getNotPrimaryAlignmentFlag() )
|
||||||
forMateMatching.remove(read.getReadName());
|
forMateMatching.remove(read.getReadName());
|
||||||
|
|
||||||
if ( DEBUG )
|
if ( DEBUG )
|
||||||
|
|
@ -346,6 +347,7 @@ public class ConstrainedMateFixingManager {
|
||||||
|
|
||||||
private void writeRead(SAMRecord read) {
|
private void writeRead(SAMRecord read) {
|
||||||
try {
|
try {
|
||||||
|
if ( writer != null )
|
||||||
writer.addAlignment(read);
|
writer.addAlignment(read);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new UserException("If the maximum allowable reads in memory is too small, it may cause reads to be written out of order when trying to write the BAM; please see the --maxReadsInMemory argument for details. " + e.getMessage(), e);
|
throw new UserException("If the maximum allowable reads in memory is too small, it may cause reads to be written out of order when trying to write the BAM; please see the --maxReadsInMemory argument for details. " + e.getMessage(), e);
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,10 @@ public class ConstrainedMateFixingManagerUnitTest extends BaseTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public void beforeClass() {
|
public void beforeClass() {
|
||||||
header = ArtificialSAMUtils.createArtificialSamHeader(3, 1, 100);
|
header = ArtificialSAMUtils.createArtificialSamHeader(3, 1, 10000);
|
||||||
genomeLocParser = new GenomeLocParser(header.getSequenceDictionary());
|
genomeLocParser = new GenomeLocParser(header.getSequenceDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSecondaryAlignmentsDoNotInterfere() {
|
public void testSecondaryAlignmentsDoNotInterfere() {
|
||||||
final List<GATKSAMRecord> properReads = ArtificialSAMUtils.createPair(header, "foo", 1, 10, 30, true, false);
|
final List<GATKSAMRecord> properReads = ArtificialSAMUtils.createPair(header, "foo", 1, 10, 30, true, false);
|
||||||
|
|
@ -105,4 +106,29 @@ public class ConstrainedMateFixingManagerUnitTest extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSecondaryAlignmentsDoNotCauseAccidentalRemovalOfMate() {
|
||||||
|
final List<GATKSAMRecord> properReads = ArtificialSAMUtils.createPair(header, "foo", 1, 530, 1594, true, false);
|
||||||
|
final GATKSAMRecord read1 = properReads.get(0);
|
||||||
|
read1.setFlags(99); // first in proper pair, mate negative strand
|
||||||
|
|
||||||
|
final GATKSAMRecord read2Primary = properReads.get(1);
|
||||||
|
read2Primary.setFlags(147); // second in pair, mate unmapped, not primary alignment
|
||||||
|
read2Primary.setAlignmentStart(1596); // move the read
|
||||||
|
|
||||||
|
final GATKSAMRecord read2NonPrimary = new GATKSAMRecord(read2Primary);
|
||||||
|
read2NonPrimary.setReadName("foo");
|
||||||
|
read2NonPrimary.setFlags(393); // second in proper pair, on reverse strand
|
||||||
|
read2NonPrimary.setAlignmentStart(451);
|
||||||
|
read2NonPrimary.setMateAlignmentStart(451);
|
||||||
|
|
||||||
|
final ConstrainedMateFixingManager manager = new ConstrainedMateFixingManager(null, genomeLocParser, 10000, 200, 10000);
|
||||||
|
manager.addRead(read2NonPrimary, false, false);
|
||||||
|
manager.addRead(read1, false, false);
|
||||||
|
|
||||||
|
for ( int i = 0; i < ConstrainedMateFixingManager.EMIT_FREQUENCY; i++ )
|
||||||
|
manager.addRead(ArtificialSAMUtils.createArtificialRead(header, "foo" + i, 0, 1500, 10), false, false);
|
||||||
|
|
||||||
|
Assert.assertTrue(manager.forMateMatching.containsKey("foo"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue