public void TryReStitch_RealCases() { var read1 = TestHelpers.CreateRead("chr1", "AGCAGCAGCAGCTCCAGCACCAGCAGTCCCAGCACCAGCAGGCCCCGAAGAAGCATACCCAGCAGCAGAAGACACCTCAGCAGCTGCACCAGGTGATCGG", 14106298, new CigarAlignment("41M59S")); var read2 = TestHelpers.CreateRead("chr1", "GCGATCTATCAGTATTAGCTCCAGCATCAGCAGCCCGAGCATCTGCAGTTCTAGCAGCAGCAGTCCCAGCAGCAGCAGTCCCAGCAGCAGCTGCCCCAGT", 14106328, new CigarAlignment("52S48M")); var stitcher = new BasicStitcher(20, false, true, debug: false, nifyUnstitchablePairs: true, ignoreProbeSoftclips: true, maxReadLength: 1024, ignoreReadsAboveMaxLength: false, thresholdNumDisagreeingBases: 1000); var stitchedPairHandler = new PairHandler(new Dictionary <int, string>() { { 1, "chr1" } }, stitcher, tryStitch: true); var restitcher = new PostRealignmentStitcher(stitchedPairHandler, new Mock <IStatusHandler>().Object); var pair = new ReadPair(read1.BamAlignment); pair.AddAlignment(read2.BamAlignment); var mockNmCalculator = new Mock <INmCalculator>(); var reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 1, 1, false, mockNmCalculator.Object, false); Assert.Equal(1.0, reads.Count); Assert.Equal("22S78M22S", reads.First().CigarData.ToString()); }
public void Restitch() { var stitchedPairHandler = new PairHandler(new Dictionary <int, string>() { { 1, "chr1" } }, new BasicStitcher(5), tryStitch: true); var restitcher = new PostRealignmentStitcher(stitchedPairHandler, new Mock <IStatusHandler>().Object); var mockNmCalculator = new Mock <INmCalculator>(); var pair = TestHelpers.GetPair("3M1I4M", "3M1I4M"); var reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 0, true, mockNmCalculator.Object, false); Assert.Equal(1.0, reads.Count); Assert.Equal("3M1I4M", reads.First().CigarData.ToString()); pair = TestHelpers.GetPair("3M1I4M", "3M5S"); reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 0, true, mockNmCalculator.Object, false); Assert.Equal(1.0, reads.Count); Assert.Equal("3M1I4M", reads.First().CigarData.ToString()); pair = TestHelpers.GetPair("3M2I4M", "3M1I"); reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 0, true, mockNmCalculator.Object, false); Assert.Equal(1, reads.Count); Assert.Equal("3M2I4M", reads.First().CigarData.ToString()); // Second read insertion is longer, can't stitch pair = TestHelpers.GetPair("3M2I4M", "3M3I"); reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 0, true, mockNmCalculator.Object, false); Assert.Equal(2, reads.Count); Assert.Equal("3M2I4M", reads[0].CigarData.ToString()); Assert.Equal("3M3I", reads[1].CigarData.ToString()); // Same insertion introduced. One read had NM=4 before (included insertion), other did not. Stitched NM is 4 (3 from the insertion, 1 from the mismatch in the original read) pair = TestHelpers.GetPair("3M3I4M", "3M3I6M"); mockNmCalculator.Setup(x => x.GetNm(It.IsAny <BamAlignment>())).Returns(4); reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 4, true, mockNmCalculator.Object, true); Assert.Equal(1, reads.Count); Assert.Equal("3M3I6M", reads[0].CigarData.ToString()); // Same insertion introduced. One read had NM=4 before (included insertion), other did not (was perfect). // Stitched NM is 5 (3 from the insertion, 1 from the mismatch in the original read, and, say, 1 from a mismatch introduced by realignment in the first read) pair = TestHelpers.GetPair("3M3I4M", "3M3I6M"); mockNmCalculator.Setup(x => x.GetNm(It.IsAny <BamAlignment>())).Returns(5); reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 4, true, mockNmCalculator.Object, true); Assert.Equal(2, reads.Count); // Partial insertion, from right pair = TestHelpers.GetPair("3M2I4M", "1I4M", read2Offset: 3); reads = restitcher.GetRestitchedReads(pair, pair.Read1, pair.Read2, 0, 0, true, mockNmCalculator.Object, false); Assert.Equal(1, reads.Count); Assert.Equal("3M2I4M", reads.First().CigarData.ToString()); }
private static List <BamAlignment> ExtractReadsFromRealignerAndCombiner(PairResult pair, string refSeq, int refSeqOffset, List <PreIndel> preIndels, bool hasExistingIndels = false) { var stitchedPairHandler = new PairHandler(new Dictionary <int, string>() { { 1, "chr1" } }, new BasicStitcher(0), tryStitch: true); var snippetSource = new Mock <IGenomeSnippetSource>(); var genomeSnippet = new GenomeSnippet() { Chromosome = "chr1", Sequence = new string('A', refSeqOffset) + refSeq + new string('T', 1000), StartPosition = 0 }; snippetSource.Setup(x => x.GetGenomeSnippet(It.IsAny <int>())).Returns(genomeSnippet); var mockStatusHandler = new Mock <IStatusHandler>(); var comparer = new GemBasicAlignmentComparer(false, false); var readRealigner = new GeminiReadRealigner(comparer, remaskSoftclips: false, keepProbeSoftclips: false, keepBothSideSoftclips: false, trackActualMismatches: false, checkSoftclipsForMismatches: true, debug: false, maskNsOnly: false, maskPartialInsertion: false, minimumUnanchoredInsertionLength: 1, minInsertionSizeToAllowMismatchingBases: 4, maxProportionInsertSequenceMismatch: 0.2); // TODO fix // TODO figure out what I was saying to fix here... var filterer = new Mock <IRegionFilterer>(); filterer.Setup(x => x.AnyIndelsNearby(It.IsAny <int>())).Returns(true); var indels = preIndels.Select(x => HashableIndelSource.GetHashableIndel(genomeSnippet, x, 0, false)).ToList(); var indelSource = new ChromosomeIndelSource(indels, snippetSource.Object); var realignmentEvaluator = new RealignmentEvaluator(indelSource, mockStatusHandler.Object, readRealigner, new RealignmentJudger(comparer), "chr1", false, true, true, true, filterer.Object, false); var combiner = new ReadPairRealignerAndCombiner(new NonSnowballEvidenceCollector(), new PostRealignmentStitcher(stitchedPairHandler, new DebugStatusHandler(new ReadStatusCounter())), realignmentEvaluator, new PairSpecificIndelFinder(), "chr1", false, hasExistingIndels: hasExistingIndels); var nmCalc = new NmCalculator(snippetSource.Object); var result = combiner.ExtractReads(pair, nmCalc); return(result); }
public void RankPlayers(List <PlayerHand> players) { StraightFlushHandler straightFlushHandler = new StraightFlushHandler(); ThreeofKindHandler threeofKindHandler = new ThreeofKindHandler(); StraightFlushHandler straightFlushHandler1 = new StraightFlushHandler(); FlushHandler flushHandler = new FlushHandler(); PairHandler pairHandler = new PairHandler(); straightFlushHandler.SetNextHandler(threeofKindHandler); threeofKindHandler.SetNextHandler(straightFlushHandler); straightFlushHandler.SetNextHandler(flushHandler); flushHandler.SetNextHandler(pairHandler); foreach (var player in players) { straightFlushHandler.Process(player); } }
public ReadPairRealignerAndCombiner GetRealignPairHandler(bool tryRestitch, bool alreadyStitched, bool pairAwareRealign, Dictionary <int, string> refIdMapping, ReadStatusCounter statusCounter, bool isSnowball, IChromosomeIndelSource indelSource, string chromosome, Dictionary <string, IndelEvidence> masterLookup, bool hasIndels, Dictionary <HashableIndel, int[]> outcomesLookup, bool skipRestitchIfNothingChanged) { var stitcher = GetStitcher(); var stitchedPairHandler = new PairHandler(refIdMapping, stitcher, tryStitch: tryRestitch); var judger = new RealignmentJudger(GetAlignmentComparer()); var readRealigner = new GeminiReadRealigner(GetAlignmentComparer(), remaskSoftclips: _geminiOptions.RemaskMessySoftclips, keepProbeSoftclips: _geminiOptions.KeepProbeSoftclip, keepBothSideSoftclips: _geminiOptions.KeepBothSideSoftclips || (_geminiOptions.KeepProbeSoftclip && alreadyStitched), trackActualMismatches: _realignmentAssessmentOptions.TrackActualMismatches, checkSoftclipsForMismatches: _realignmentAssessmentOptions.CheckSoftclipsForMismatches, debug: _geminiOptions.Debug, maskNsOnly: !(_geminiOptions.RemaskMessySoftclips || _geminiOptions.KeepProbeSoftclip || _geminiOptions.KeepBothSideSoftclips), maskPartialInsertion: _realignmentOptions.MaskPartialInsertion, minimumUnanchoredInsertionLength: _realignmentOptions.MinimumUnanchoredInsertionLength, minInsertionSizeToAllowMismatchingBases: 4, maxProportionInsertSequenceMismatch: 0.2); // TODO fix // TODO figure out what I was saying to fix here... IStatusHandler statusHandler = new DebugSummaryStatusHandler(statusCounter); if (_geminiOptions.Debug) { statusHandler = new DebugStatusHandler(statusCounter); } // Only softclip unknowns if it is not stitched to begin with (we believe in these more, plus it makes our lives simpler for dealing with stitched directions) var softclipUnknownIndels = _geminiOptions.SoftclipUnknownIndels && !alreadyStitched; //var regionFilterer = new RegionFilterer(chromosome, indelSource.Indels); var regionFilterer = new DummyRegionFilterer(); var collector = GetCollector(isSnowball); var realignmentEvaluator = new RealignmentEvaluator(indelSource.DeepCopy(), statusHandler, readRealigner, judger, chromosome, _realignmentAssessmentOptions.TrackActualMismatches, _realignmentAssessmentOptions.CheckSoftclipsForMismatches, _geminiOptions.AllowRescoringOrigZero, softclipUnknownIndels, regionFilterer, _geminiOptions.LightDebug); return(new ReadPairRealignerAndCombiner( collector, GetRestitcher(stitchedPairHandler, statusHandler), realignmentEvaluator, GetIndelFinder(pairAwareRealign, chromosome, indelSource), chromosome, alreadyStitched, pairAwareRealign, masterLookup: masterLookup, hasExistingIndels: hasIndels, masterOutcomesLookup: outcomesLookup, skipRestitchIfNothingChanged: skipRestitchIfNothingChanged, allowedToStitch: !_geminiOptions.SkipStitching)); }
private IReadRestitcher GetRestitcher(PairHandler pairHandler, IStatusHandler statusHandler) { // TODO also allow not restitch return(new PostRealignmentStitcher(pairHandler, statusHandler, _stitcherOptions.StringTagsToKeepFromR1)); }
private void ExtractReads(bool addUmiTags) { var refIdMapping = new Dictionary <int, string>() { { 1, "chr1" } }; var stitcher = StitcherTestHelpers.GetStitcher(10, false); var readStatusCounter = new ReadStatusCounter(); var pairHandler = new PairHandler(refIdMapping, stitcher, readStatusCounter, filterUnstitchablePairs: true); var alignment1 = new BamAlignment() { AlignmentFlag = 0, Bases = "ABCF", Bin = 4, CigarData = new CigarAlignment("2S2M"), FragmentLength = 42, MapQuality = 30, MatePosition = 2, MateRefID = 43, Name = "Read1", Position = 1, Qualities = new byte[4], RefID = 1, TagData = new byte[0] }; var tagUtils = new TagUtils(); tagUtils.AddStringTag("BC", "14"); tagUtils.AddIntTag("SM", 40); if (addUmiTags) { tagUtils.AddIntTag("XV", 1); tagUtils.AddIntTag("XW", 2); tagUtils.AddStringTag("XU", "ABBA-ZABBA"); } alignment1.AppendTagData(tagUtils.ToBytes()); var alignment2 = new BamAlignment() { AlignmentFlag = 0, Bases = "ABCF", Bin = 4, CigarData = new CigarAlignment("2S2M"), FragmentLength = 42, MapQuality = 30, MatePosition = 2, MateRefID = 43, Name = "Read1", Position = 1, Qualities = new byte[4], RefID = 1, TagData = new byte[0] }; var tagUtils2 = new TagUtils(); tagUtils2.AddIntTag("NM", 5); tagUtils2.AddStringTag("BC", "14"); tagUtils2.AddIntTag("SM", 20); if (addUmiTags) { tagUtils2.AddIntTag("XV", 1); tagUtils2.AddIntTag("XW", 2); tagUtils2.AddStringTag("XU", "ABBA-ZABBA"); } alignment2.AppendTagData(tagUtils2.ToBytes()); var readPair = new ReadPair(alignment1); readPair.AddAlignment(alignment2); var alignmentResults = pairHandler.ExtractReads(readPair); Assert.Equal(1, alignmentResults.Count); var alignment = alignmentResults[0]; Assert.NotNull(alignment.GetStringTag("XD")); Assert.Null(alignment.GetIntTag("NM")); Assert.Null(alignment.GetStringTag("BC")); Assert.Null(alignment.GetIntTag("SM")); if (addUmiTags) { Assert.Equal("ABBA-ZABBA", alignment.GetStringTag("XU")); Assert.Equal(1, alignment.GetIntTag("XV")); Assert.Equal(2, alignment.GetIntTag("XW")); } }
private void ExtractReadsStrand(bool r1Reverse, bool r2Reverse, string expectedXRTag) { var refIdMapping = new Dictionary <int, string>() { { 1, "chr1" } }; var stitcher = StitcherTestHelpers.GetStitcher(10, false); var readStatusCounter = new ReadStatusCounter(); var pairHandler = new PairHandler(refIdMapping, stitcher, readStatusCounter, filterUnstitchablePairs: true); var alignment1 = new BamAlignment() { AlignmentFlag = 0, Bases = "ABCF", Bin = 4, CigarData = new CigarAlignment("2S2M"), FragmentLength = 42, MapQuality = 30, MatePosition = 2, MateRefID = 43, Name = "Read1", Position = 1, Qualities = new byte[4], RefID = 1, TagData = new byte[0] }; alignment1.SetIsFirstMate(true); alignment1.SetIsReverseStrand(r1Reverse); var alignment2 = new BamAlignment() { AlignmentFlag = 0, Bases = "ABCF", Bin = 4, CigarData = new CigarAlignment("2S2M"), FragmentLength = 42, MapQuality = 30, MatePosition = 2, MateRefID = 43, Name = "Read1", Position = 1, Qualities = new byte[4], RefID = 1, TagData = new byte[0] }; alignment2.SetIsSecondMate(true); alignment2.SetIsReverseStrand(r2Reverse); var readPair = new ReadPair(alignment1); readPair.AddAlignment(alignment2); var alignmentResults = pairHandler.ExtractReads(readPair); Assert.Equal(1, alignmentResults.Count); var alignment = alignmentResults[0]; var XD = alignment.GetStringTag("XR"); Assert.Equal(expectedXRTag, alignment.GetStringTag("XR")); }
private void ExtractReadsStrandXRValidation() { var refIdMapping = new Dictionary <int, string>() { { 1, "chr1" } }; var stitcher = StitcherTestHelpers.GetStitcher(10, false); var readStatusCounter = new ReadStatusCounter(); var pairHandler = new PairHandler(refIdMapping, stitcher, readStatusCounter, filterUnstitchablePairs: true); var alignment1 = new BamAlignment() { AlignmentFlag = 99, Bases = "ABCF", Bin = 4, CigarData = new CigarAlignment("2S2M"), FragmentLength = 42, MapQuality = 30, MatePosition = 2, MateRefID = 43, Name = "Read1", Position = 1, Qualities = new byte[4], RefID = 1, TagData = new byte[0] }; var tagUtils = new TagUtils(); tagUtils.AddStringTag("XR", "BLABLA"); //start with random XR tag and confirm whether it is overwritten by read direction alignment1.AppendTagData(tagUtils.ToBytes()); var alignment2 = new BamAlignment() { AlignmentFlag = 144, Bases = "ABCF", Bin = 4, CigarData = new CigarAlignment("2S2M"), FragmentLength = 42, MapQuality = 30, MatePosition = 2, MateRefID = 43, Name = "Read1", Position = 1, Qualities = new byte[4], RefID = 1, TagData = new byte[0] }; var tagUtils2 = new TagUtils(); tagUtils.AddStringTag("XR", "BLABLA"); //start with random XR tag and confirm whether it is overwritten by read direction alignment2.AppendTagData(tagUtils.ToBytes()); var readPair = new ReadPair(alignment1); readPair.AddAlignment(alignment2); var alignmentResults = pairHandler.ExtractReads(readPair); Assert.Equal(1, alignmentResults.Count); var alignment = alignmentResults[0]; Assert.Equal("FR", alignment.GetStringTag("XR")); }