private static void MappedReadTest(bool r1UnMapped, bool r1MateUnMapped, bool r2UnMapped, bool r2MateUnMapped) { var dupIdentifier = new Mock <IDuplicateIdentifier>(); var filter = new StitcherPairFilter(false, false, dupIdentifier.Object, new ReadStatusCounter(), filterPairUnmapped: true); var unmappedRead = CreateAlignment("case1", true, 0, "3M", r1UnMapped, r1MateUnMapped); var mappedRead = CreateAlignment("case1", true, 0, "3M", r2UnMapped, r2MateUnMapped); var pair = filter.TryPair(mappedRead); Assert.Null(pair); pair = filter.TryPair(unmappedRead); Assert.Null(pair); Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); }
public IDataSource <ReadPair> CreateReadPairSource(IBamReader bamReader, ReadStatusCounter statusCounter) { //var pairSourceLevelFilterProperPairs = _stitcherOptions.FilterForProperPairs; var pairSourceLevelFilterProperPairs = false; // This gets taken care of at the Gemini level now. var filter = new StitcherPairFilter(_stitcherOptions.FilterDuplicates, pairSourceLevelFilterProperPairs, new AlignmentFlagDuplicateIdentifier(), statusCounter, minMapQuality: 0, treatImproperAsIncomplete: false); var readLength = 150; return(new PairFilterReadPairSource(bamReader, statusCounter, _skipAndRemoveDuplicates, filter, refId: _refId, expectedFragmentLength: readLength, filterForProperPairs: pairSourceLevelFilterProperPairs)); }
public void TryPair() { var dupIdentifier = new Mock <IDuplicateIdentifier>(); var filter = new StitcherPairFilter(false, false, dupIdentifier.Object, new ReadStatusCounter()); // First alignment the filter sees: not paired yet, hold on to it var firstInPair = CreateAlignment("abc"); var pair = filter.TryPair(firstInPair); Assert.Null(pair); // Found the original alignment's pair -> return the pair var secondInPair = CreateAlignment("abc"); pair = filter.TryPair(secondInPair); Assert.NotNull(pair); // There should be nothing unpaired Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); // Add another one and don't give it a pair (i.e. a singleton), there should be a single unpaired pair = filter.TryPair(CreateAlignment("singleton")); Assert.Null(pair); Assert.Equal(1, filter.GetFlushableUnpairedReads().Count()); // Improper pairs should be treated as incomplete (like a singleton) Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); var improperPairRead1 = CreateAlignment("improper", false); var improperPairRead2 = CreateAlignment("improper", false); pair = filter.TryPair(improperPairRead1); Assert.Null(pair); pair = filter.TryPair(improperPairRead2); Assert.Null(pair); // Should be able to get both of these reads back with unpaired Assert.Equal(2, filter.GetFlushableUnpairedReads().Count()); // Non-overlapping pairs should be treated as incomplete (like a singleton) Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); var nonOverlappingRead1 = CreateAlignment("noOverlap", true, 1, "3M2I"); var nonOverlappingRead2 = CreateAlignment("noOverlap", true, 4, "2I4M"); pair = filter.TryPair(nonOverlappingRead1); Assert.Null(pair); pair = filter.TryPair(nonOverlappingRead2); Assert.Null(pair); // Should be able to get both of these reads back with unpaired Assert.Equal(2, filter.GetFlushableUnpairedReads().Count()); }
private static void LowMapQualityTest(uint r1MapQ, uint r2MapQ, bool filterPair, int expectedFragmentCount, uint MinMapQuality, bool shouldStitch) { var dupIdentifier = new Mock <IDuplicateIdentifier>(); var filter = new StitcherPairFilter(false, false, dupIdentifier.Object, new ReadStatusCounter(), filterPairLowMapQ: filterPair, minMapQuality: MinMapQuality); var r1 = CreateAlignment("LowMap", true, 0, "3M", false, mapQ: r1MapQ); var r2 = CreateAlignment("LowMap", true, 0, "3M", false, mapQ: r2MapQ); var pair = filter.TryPair(r1); Assert.Null(pair); pair = filter.TryPair(r2); if (shouldStitch) { Assert.NotNull(pair); } else { Assert.Null(pair); } Assert.Equal(expectedFragmentCount, filter.GetFlushableUnpairedReads().Count()); }
public void GetNextEntryUntilNull_NonMocked() { var readEarly = TestHelpers.CreateBamAlignment(new string('A', 100), 3, 500, 30, false, name: "FarApart", isFirstMate: true); readEarly.FragmentLength = 600; readEarly.SetIsPaired(true); var readLate = TestHelpers.CreateBamAlignment(new string('A', 100), 500, 3, 30, false, name: "FarApart", isFirstMate: true); readLate.FragmentLength = -600; readLate.SetIsPaired(true); var bamAlignments = new List <BamAlignment>() { readEarly, readLate }; var refIdLookup = new Dictionary <string, int>() { { "chr1", 1 } }; var bamReader = new MockBamReader(bamAlignments, refIdLookup); var filter = new StitcherPairFilter(false, false, new AlignmentFlagDuplicateIdentifier(), new ReadStatusCounter(), minMapQuality: 0, treatImproperAsIncomplete: false); var source = new PairFilterReadPairSource(bamReader, new ReadStatusCounter(), false, filter, refId: 1, expectedFragmentLength: 150); // Return far apart reads individually so we don't bog down memory with things that don't act as pairs (stitch, cover same indels) anyway. var nextEntry = source.GetNextEntryUntilNull(); Assert.Equal(2, nextEntry.MinPosition); Assert.Equal(1, nextEntry.NumPrimaryReads); Assert.Equal(PairStatus.LongFragment, nextEntry.PairStatus); nextEntry = source.GetNextEntryUntilNull(); Assert.Equal(499, nextEntry.MinPosition); Assert.Equal(1, nextEntry.NumPrimaryReads); Assert.Equal(PairStatus.LongFragment, nextEntry.PairStatus); }
public void TryPair() { var dupIdentifier = new Mock <IDuplicateIdentifier>(); var filter = new StitcherPairFilter(false, false, dupIdentifier.Object, new ReadStatusCounter()); // First alignment the filter sees: not paired yet, hold on to it var firstInPair = CreateAlignment("abc"); var tagUtils = new TagUtils(); tagUtils.AddStringTag("SA", "chr1,100,+,3M,50,1"); firstInPair.TagData = tagUtils.ToBytes(); var pair = filter.TryPair(firstInPair); Assert.Null(pair); // Found the original alignment's pair -> return the pair, even though it has a supplementary which has not yet been encountered var secondInPair = CreateAlignment("abc"); pair = filter.TryPair(secondInPair); Assert.NotNull(pair); // There should be nothing unpaired Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); // Add another one and don't give it a pair (i.e. a singleton), there should be a single unpaired pair = filter.TryPair(CreateAlignment("singleton")); Assert.Null(pair); Assert.Equal(1, filter.GetFlushableUnpairedReads().Count()); // Improper pairs should be treated as incomplete (like a singleton) Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); var improperPairRead1 = CreateAlignment("improper", false); var improperPairRead2 = CreateAlignment("improper", false); pair = filter.TryPair(improperPairRead1); Assert.Null(pair); pair = filter.TryPair(improperPairRead2); Assert.Null(pair); // Should be able to get both of these reads back with unpaired Assert.Equal(2, filter.GetFlushableUnpairedReads().Count()); /// /// LowMapQ filter tests both the filterPairLowMapQ and the minmapquality setting /// If filterPairLowMapQ == true, and one or both reads below mapQ both read pairs should be filtered and have 0 FlushableUnpairedReads /// If filterPairLowMapQ == false, and one read below mapQ, only one read should be filtered and have 1 FlushableUnpairedReads /// // HappyCase, both reads mapQ = 30, filterPair on, Stitched so 0 flushable reads, minMapQ = 20 LowMapQualityTest(30, 30, true, 0, 20, true); // r1MapQ = 10, r2MapQ = 30, filterPair on, expected to throw out both reads, minMapQ = 20) LowMapQualityTest(10, 30, true, 0, 20, false); // r1MapQ = 30, r2MapQ = 10, filterPair on, expected to throw out both reads, minMapQ = 20) LowMapQualityTest(10, 30, true, 0, 20, false); // r1MapQ = 30, r2MapQ = 10, filterPair off, expected to throw out 1 read, minMapQ = 20) LowMapQualityTest(10, 30, false, 1, 20, false); // r1MapQ = 10, r2MapQ = 30, filterPair off, expected to throw out 1 read, minMapQ = 20) LowMapQualityTest(10, 30, false, 1, 20, false); // r1MapQ = 3, r2MapQ = 20, filterPair on, expected to throw out both reads, minMapQ = 5) LowMapQualityTest(3, 20, true, 0, 5, false); // r1MapQ = 10, r2MapQ = 10, filterPair on, expected to throw out both reads, minMapQ = 20) LowMapQualityTest(10, 10, true, 0, 20, false); // r1MapQ = 10, r2MapQ = 10, filterPair off, expected to throw out both reads, minMapQ = 20) LowMapQualityTest(10, 10, false, 0, 20, false); // r1MapQ = 19, r2MapQ = 20, filterPair on, expected to throw out both reads, minMapQ = 20) LowMapQualityTest(19, 20, true, 0, 20, false); // r1MapQ = 19, r2MapQ = 20, filterPair off, expected to throw out 1 reads, minMapQ = 20) LowMapQualityTest(19, 20, false, 1, 20, false); // Non-overlapping pairs should be treated as incomplete (like a singleton) Assert.Equal(0, filter.GetFlushableUnpairedReads().Count()); var nonOverlappingRead1 = CreateAlignment("noOverlap", true, 1, "3M2I"); var nonOverlappingRead2 = CreateAlignment("noOverlap", true, 4, "2I4M"); pair = filter.TryPair(nonOverlappingRead1); Assert.Null(pair); pair = filter.TryPair(nonOverlappingRead2); Assert.Null(pair); // Should be able to get both of these reads back with unpaired Assert.Equal(2, filter.GetFlushableUnpairedReads().Count()); }