public void GetAlignmentSet() { var reads = new List <Read>(); reads.Add(CreateRead("chr1", "ACGT", 10, "read1", matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 10, "read2", matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 10, "read1", read2: true, matePosition: 10)); // mate reads.Add(CreateRead("chr1", "ACGT", 10, "read_notmapped", isMapped: false, isProperPair: false, matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 10, "read3", isProperPair: false, read2: true, matePosition: 10)); // mate reads.Add(CreateRead("chr1", "ACGT", 10, "read2", read2: true, matePosition: 10)); var extractor = new MockAlignmentExtractor(reads); var config = new AlignmentSourceConfig { MinimumMapQuality = 10, OnlyUseProperPairs = false }; var source = new AlignmentSource(extractor, null, config); Read read; var numSets = 0; while ((read = source.GetNextRead()) != null) { numSets++; Assert.False(read.Name == "read_notmapped"); } Assert.Equal(numSets, 5); }
private void ExecuteGroupingTest(List <Read> reads, List <int> expectedGroupMemberships, IEnumerable <Tuple <int, string, string> > variants) { var variantSites = new List <VariantSite>(); foreach (var variant in variants) { variantSites.Add(new VariantSite(variant.Item1) { VcfReferenceAllele = variant.Item2, VcfAlternateAllele = variant.Item3 }); } var alignmentExtractor = new MockAlignmentExtractor(reads); var veadSource = new VeadGroupSource(alignmentExtractor, new BamFilterParameters() { MinimumMapQuality = 20 }, false, ""); var vcfNeighborhood = new VcfNeighborhood(new VariantCallingParameters(), "chr1", new VariantSite(120), new VariantSite(121), "T") { VcfVariantSites = variantSites }; vcfNeighborhood.SetRangeOfInterest(); var veadGroups = veadSource.GetVeadGroups(vcfNeighborhood).ToList(); Assert.Equal(expectedGroupMemberships.Count, veadGroups.Count()); for (var i = 0; i < veadGroups.Count(); i++) { Assert.Equal(expectedGroupMemberships[i], veadGroups[i].NumVeads); } }
private void ExecuteTest_ProcessReadsSeparately(bool doMate, bool doStitch) { var read = CreateRead("chr1", "ACGT", 10, "read1", matePosition: 100); var readMate = CreateRead("chr1", "ACGT", 100, "read1", read2: true, matePosition: 10); var extractor = new MockAlignmentExtractor(new List <Read>() { read }); var mateFinder = new Mock <IAlignmentMateFinder>(); mateFinder.Setup(f => f.GetMate(It.IsAny <Read>())).Returns(readMate); var stitcher = new Mock <IAlignmentStitcher>(); var config = new AlignmentSourceConfig { MinimumMapQuality = 10, OnlyUseProperPairs = false }; var source = new AlignmentSource(extractor, doMate ? mateFinder.Object : null, config); var alignmentSet = source.GetNextRead(); // TODO what do we really want to test here now that we're not pairing? }
public void SupplementSupportWithClippedReads() { // In this test we create reads that are either normal or clipped (identified by "clip_" in their name) // This test does not take cigar data into account. var mockClippedReadComparator = new Mock <IMNVClippedReadComparator>(); // Mock read comparator returns true if read name starts with c mockClippedReadComparator.Setup(x => x.DoesClippedReadSupportMNV(It.IsAny <Read>(), It.IsAny <CalledAllele>())) .Returns((Read read, CalledAllele allele) => read.Name[0] == 'c' ? true : false); var reads = new List <Read>(); reads.Add(CreateRead("chr1", "ACGT", 3, "read4")); reads.Add(CreateRead("chr1", "ACGT", 3, "clip_read4", matePosition: 3)); // +1 not in neighborhood, but still gets counted because mocked ClippedReadComparator reads.Add(CreateRead("chr1", "ACGT", 12, "read1", matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 12, "read2", matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 12, "read1", read2: true, matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 12, "read_notmapped", isMapped: false, isProperPair: false, matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 12, "read3", isProperPair: false, read2: true, matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 12, "read2", read2: true, matePosition: 10)); reads.Add(CreateRead("chr1", "ACGT", 12, "clip_read1", matePosition: 10)); // +1 clipped read reads.Add(CreateRead("chr1", "ACGT", 12, "clip_read2", matePosition: 10)); // +1 clipped read reads.Add(CreateRead("chr1", "ACGT", 12, "clip_read1", read2: true, matePosition: 10)); // +1 clipped read reads.Add(CreateRead("chr1", "ACGT", 12, "clip_read_notmapped", isMapped: false, isProperPair: false, matePosition: 10)); // +1 clipped read reads.Add(CreateRead("chr1", "ACGT", 12, "clip_read3", isProperPair: false, read2: true, matePosition: 10)); // +1 clipped read reads.Add(CreateRead("chr1", "ACGT", 12, "clip_read2", read2: true, matePosition: 10)); // +1 clipped read reads.Add(CreateRead("chr1", "ACGT", 30, "read5")); reads.Add(CreateRead("chr1", "ACGT", 30, "clip_read5", matePosition: 30)); // not in neighborhood, not counted var mockAlignmentExtractor = new MockAlignmentExtractor(reads); int qNoiseLevel = 20; int maxQscore = 100; int minMNVsize = 6; MNVSoftClipSupportFinder mnvClippedSupportFinder = new MNVSoftClipSupportFinder(mockAlignmentExtractor, mockClippedReadComparator.Object, qNoiseLevel, maxQscore, minMNVsize); var mnv1 = TestHelper.CreateDummyAllele("chr1", 10, "AAAAAA", "CCC", 2000, 50); var neighbor1 = new VcfNeighborhood(0, "chr", new VariantSite(10000), new VariantSite(200000)) { VcfVariantSites = new List <VariantSite> { new VariantSite(10) { VcfReferenceAllele = "A", VcfAlternateAllele = "C", ReferenceName = "chr" }, new VariantSite(25) { VcfReferenceAllele = "T", VcfAlternateAllele = "G", ReferenceName = "chr" }, }, }; var callableNbhd = new CallableNeighborhood(neighbor1, new VariantCallingParameters(), null); callableNbhd.AddAcceptedPhasedVariant(mnv1); Assert.Equal(50, callableNbhd.CandidateVariants[0].AlleleSupport); mnvClippedSupportFinder.SupplementSupportWithClippedReads(callableNbhd); Assert.Equal(57, callableNbhd.CandidateVariants[0].AlleleSupport); }
public AmpliconTestFactory(string referenceSequence, bool sourceIsStitched = false) { _referenceSequence = referenceSequence; ChrInfo = new ChrReference() { Name = "chr7", Sequence = _referenceSequence }; AlignmentExtractor = new MockAlignmentExtractor(ChrInfo, sourceIsStitched); }
public AmpliconTestFactory(string referenceSequence, bool stitchReads) { _referenceSequence = referenceSequence; ChrInfo = new ChrReference() { Name = "chr7", Sequence = _referenceSequence }; _MAE = new MockAlignmentExtractor(ChrInfo, stitchReads); }
public void GetAlignmentSet() { var reads = new List <Read>(); reads.Add(CreateRead("chr1", "ACGT", 1, "read1")); reads.Add(CreateRead("chr1", "ACGT", 1, "read2")); reads.Add(CreateRead("chr1", "ACGT", 1, "read1_mate")); reads.Add(CreateRead("chr1", "ACGT", 1, "read3_unmapped", isMapped: false, isProperPair: false)); reads.Add(CreateRead("chr1", "ACGT", 1, "read3_mate", isProperPair: false)); reads.Add(CreateRead("chr1", "ACGT", 1, "read2_mate")); var extractor = new MockAlignmentExtractor(reads); var mateFinder = new Mock <IAlignmentMateFinder>(); mateFinder.Setup(f => f.GetMate(It.IsAny <Read>())).Returns( (Read r) => r.Name.EndsWith("_mate") ? reads.FirstOrDefault(o => o.Name == r.Name.Replace("_mate", string.Empty)) : null); var stitcher = new Mock <IAlignmentStitcher>(); stitcher.Setup(s => s.TryStitch(It.IsAny <AlignmentSet>())).Callback((AlignmentSet s) => s.IsStitched = true); var config = new AlignmentSourceConfig { MinimumMapQuality = 10, OnlyUseProperPairs = false }; var source = new AlignmentSource(extractor, mateFinder.Object, stitcher.Object, config); AlignmentSet set; var numSets = 0; while ((set = source.GetNextAlignmentSet()) != null) { numSets++; if (!set.IsFullPair) { Assert.True(set.PartnerRead1.Name.Equals("read3_mate")); Assert.True(set.PartnerRead2 == null); Assert.False(set.IsStitched); } else { Assert.True(set.PartnerRead2.Name.Equals(set.PartnerRead1.Name + "_mate")); Assert.True(set.IsStitched); } } Assert.Equal(numSets, 3); }
private void ExecuteTest_ProcessReadsSeparately(bool doMate, bool doStitch) { var read = CreateRead("chr1", "ACGT", 1, "read1"); var readMate = CreateRead("chr1", "ACGT", 10, "read1mate"); var extractor = new MockAlignmentExtractor(new List <Read>() { read }); var mateFinder = new Mock <IAlignmentMateFinder>(); mateFinder.Setup(f => f.GetMate(It.IsAny <Read>())).Returns(readMate); var stitcher = new Mock <IAlignmentStitcher>(); var config = new AlignmentSourceConfig { MinimumMapQuality = 10, OnlyUseProperPairs = false }; var source = new AlignmentSource(extractor, doMate ? mateFinder.Object : null, doStitch ? stitcher.Object : null, config); var alignmentSet = source.GetNextAlignmentSet(); // verify stitching relies on pairing stitcher.Verify(s => s.TryStitch(It.IsAny <AlignmentSet>()), Times.Never); if (!doMate) { TestHelper.CompareReads(read, alignmentSet.PartnerRead1); Assert.Equal(null, alignmentSet.PartnerRead2); Assert.Equal(1, alignmentSet.ReadsForProcessing.Count); TestHelper.CompareReads(read, alignmentSet.ReadsForProcessing.First()); } else { TestHelper.CompareReads(read, alignmentSet.PartnerRead1); TestHelper.CompareReads(readMate, alignmentSet.PartnerRead2); Assert.Equal(2, alignmentSet.ReadsForProcessing.Count); TestHelper.CompareReads(read, alignmentSet.ReadsForProcessing.First()); TestHelper.CompareReads(readMate, alignmentSet.ReadsForProcessing.Last()); } }
public void GetVeads() { var vcfNeighborhood = new VcfNeighborhood(new VariantCallingParameters(), "chr1", new VariantSite(10000), new VariantSite(200000), "T") { VcfVariantSites = new List <VariantSite> { new VariantSite(100) { VcfReferenceAllele = "A", VcfAlternateAllele = "C" }, new VariantSite(400) { VcfReferenceAllele = "A", VcfAlternateAllele = "C" }, new VariantSite(505) { VcfReferenceAllele = "A", VcfAlternateAllele = "C" }, new VariantSite(703) { VcfReferenceAllele = "A", VcfAlternateAllele = "T" }, new VariantSite(800) { VcfReferenceAllele = "A", VcfAlternateAllele = "C" }, } }; var reads = new List <Read>(); reads.Add(CreateRead("chr1", "ACGT", 10)); // Before neighborhood reads.Add(CreateRead("chr1", "ACGT", 96)); // Ends right before neighborhood's first variant site reads.Add(CreateRead("chr1", "ACGT", 100)); // Match (100) reads.Add(CreateRead("chr1", "ACGT", 300)); // Within neighborhood but no VariantSite reads.Add(CreateRead("chr1", "ACGT", 400, qualityForAll: 19)); // Within neighbhorhood but low quals reads.Add(CreateRead("chr1", "ACGT", 500)); // Within neighborhood but no VariantSite (ends right before 505) reads.Add(CreateRead("chr1", "ACGT", 700)); // Match (703) reads.Add(CreateRead("chr1", "ACGT", 800)); // Match (800) reads.Add(CreateRead("chr1", "ACGT", 805)); // Past neighborhood reads.Add(CreateRead("chr1", "ACGT", 900)); // Past neighborhood reads.Add(CreateRead("chr2", "ACGT", 100)); // Wrong chromosome vcfNeighborhood.SetRangeOfInterest(); var alignmentExtractor = new MockAlignmentExtractor(reads); var veadSource = new VeadGroupSource(alignmentExtractor, new BamFilterParameters() { MinimumMapQuality = 20 }, false, ""); var veadGroups = veadSource.GetVeadGroups(vcfNeighborhood); // Collect all reads that could relate to the neighborhood // - Skip anything that has quality less than MinimumMapQuality // - Skip anything that ends before neighborhood begins // - Stop collecting once we've passed the end of the neighborhood // We should have collected the reads at 100, 700, and 800. Assert.Equal(801, vcfNeighborhood.LastPositionOfInterestWithLookAhead); Assert.Equal(3, veadGroups.Count()); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("100"))); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("700"))); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("800"))); Assert.Equal(0, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("805"))); Assert.Equal(0, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("900"))); foreach (var veadGroup in veadGroups) { Assert.Equal(1, veadGroup.NumVeads); } vcfNeighborhood.VcfVariantSites.Add( new VariantSite(790) { VcfReferenceAllele = "ACAGTGAAAGACTTGTGAC", VcfAlternateAllele = "C" }); vcfNeighborhood.SetRangeOfInterest(); Assert.Equal(809, vcfNeighborhood.LastPositionOfInterestWithLookAhead); alignmentExtractor = new MockAlignmentExtractor(reads); veadSource = new VeadGroupSource(alignmentExtractor, new BamFilterParameters() { MinimumMapQuality = 20 }, false, ""); veadGroups = veadSource.GetVeadGroups(vcfNeighborhood); Assert.Equal(3, veadGroups.Count()); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("100"))); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("700"))); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("800"))); Assert.Equal(0, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("805"))); Assert.Equal(0, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("900"))); // Boundary case - read ends exactly at neighborhood's first variant site reads = new List <Read>(); reads.Add(CreateRead("chr1", "ACGT", 10)); // Before neighborhood reads.Add(CreateRead("chr1", "ACGT", 96)); // Ends right before neighborhood's first variant site reads.Add(CreateRead("chr1", "ACGT", 97)); // Ends exactly at neighborhood's first variant site alignmentExtractor = new MockAlignmentExtractor(reads); veadSource = new VeadGroupSource(alignmentExtractor, new BamFilterParameters() { MinimumMapQuality = 20 }, false, ""); veadGroups = veadSource.GetVeadGroups(vcfNeighborhood); // The veadgroup for 97 should be the only one Assert.Equal(1, veadGroups.Count()); Assert.Equal(1, veadGroups.Count(v => v.RepresentativeVead.Name.EndsWith("97"))); foreach (var veadGroup in veadGroups) { Assert.Equal(1, veadGroup.NumVeads); } }
public static ISomaticVariantCaller CreateMockVariantCaller(VcfFileWriter vcfWriter, ApplicationOptions options, ChrReference chrRef, MockAlignmentExtractor mockAlignmentExtractor, IStrandBiasFileWriter biasFileWriter = null, string intervalFilePath = null) { var config = new AlignmentSourceConfig { MinimumMapQuality = options.MinimumMapQuality, OnlyUseProperPairs = options.OnlyUseProperPairs, }; //var mateFinder = options.StitchReads ? new AlignmentMateFinder() : null; AlignmentMateFinder mateFinder = null; var alignmentSource = new AlignmentSource(mockAlignmentExtractor, mateFinder, config); var variantFinder = new CandidateVariantFinder(options.MinimumBaseCallQuality, options.MaxSizeMNV, options.MaxGapBetweenMNV, options.CallMNVs); var coverageCalculator = new CoverageCalculator(); var alleleCaller = new AlleleCaller(new VariantCallerConfig { IncludeReferenceCalls = options.OutputgVCFFiles, MinVariantQscore = options.MinimumVariantQScore, MaxVariantQscore = options.MaximumVariantQScore, VariantQscoreFilterThreshold = options.FilteredVariantQScore > options.MinimumVariantQScore ? options.FilteredVariantQScore : (int?)null, MinCoverage = options.MinimumDepth, MinFrequency = options.MinimumFrequency, EstimatedBaseCallQuality = options.AppliedNoiseLevel == -1 ? options.MinimumBaseCallQuality : options.AppliedNoiseLevel, StrandBiasModel = options.StrandBiasModel, StrandBiasFilterThreshold = options.StrandBiasAcceptanceCriteria, FilterSingleStrandVariants = options.FilterOutVariantsPresentOnlyOneStrand, ChrReference = chrRef }, coverageCalculator: coverageCalculator, variantCollapser: options.Collapse ? new VariantCollapser(null, coverageCalculator) : null); var stateManager = new RegionStateManager( expectStitchedReads: mockAlignmentExtractor.SourceIsStitched, trackOpenEnded: options.Collapse, trackReadSummaries: options.CoverageMethod == CoverageMethod.Approximate); //statmanager is an allele source Assert.Equal(0, stateManager.GetAlleleCount(1, AlleleType.A, DirectionType.Forward)); return(new SomaticVariantCaller( alignmentSource, variantFinder, alleleCaller, vcfWriter, stateManager, chrRef, null, biasFileWriter)); }
public void Filtering() { //bool isMapped = true, bool isPrimaryAlignment = true, bool isProperPair = true, bool isDuplicate = false var reads = new List <Read>(); reads.Add(CreateRead("chr1", "AAA", 1, "filtered", false, true, true, false, 10)); reads.Add(CreateRead("chr1", "AAA", 1, "filtered", true, false, true, false, 10)); reads.Add(CreateRead("chr1", "AAA", 1, "filtered_properpair", true, true, false, false, 10)); reads.Add(CreateRead("chr1", "AAA", 1, "filtered", true, true, true, true, 10)); reads.Add(CreateRead("chr1", "AAA", 1, "filtered_quality", true, true, true, false, 9)); reads.Add(CreateRead("chr1", "AAA", 1, "Filtered_CigarData", true, true, true, false, 10, false)); reads.Add(CreateRead("chr1", "AAA", 1, "yay", true, true, true, false, 10)); var extractor = new MockAlignmentExtractor(reads); var config = new AlignmentSourceConfig { MinimumMapQuality = 10, OnlyUseProperPairs = true, SkipDuplicates = true }; var source = new AlignmentSource(extractor, null, config); Read read; var fetchedCount = 0; while ((read = source.GetNextRead()) != null) { fetchedCount++; Assert.Equal(read.Name, "yay"); } Assert.Equal(1, fetchedCount); // ------------------------- // turn off proper pairs config.OnlyUseProperPairs = false; fetchedCount = 0; extractor.Reset(); source = new AlignmentSource(extractor, null, config); while ((read = source.GetNextRead()) != null) { fetchedCount++; Assert.Equal(read.Name, fetchedCount == 1 ? "filtered_properpair" : "yay"); } Assert.Equal(fetchedCount, 2); // ------------------------- // change quality cut off config.OnlyUseProperPairs = true; config.MinimumMapQuality = 9; fetchedCount = 0; extractor.Reset(); source = new AlignmentSource(extractor, null, config); while ((read = source.GetNextRead()) != null) { fetchedCount++; Assert.Equal(read.Name, fetchedCount == 1 ? "filtered_quality" : "yay"); } Assert.Equal(fetchedCount, 2); }
private ISomaticVariantCaller CreateMockVariantCaller(VcfFileWriter vcfWriter, ApplicationOptions options, ChrReference chrRef, MockAlignmentExtractor mae, IStrandBiasFileWriter biasFileWriter = null, string intervalFilePath = null) { var config = new AlignmentSourceConfig { MinimumMapQuality = options.MinimumMapQuality, OnlyUseProperPairs = options.OnlyUseProperPairs, }; IAlignmentStitcher stitcher = null; if (options.StitchReads) { if (options.UseXCStitcher) { stitcher = new XCStitcher(options.MinimumBaseCallQuality); } else { stitcher = new BasicStitcher(options.MinimumBaseCallQuality); } } var mateFinder = options.StitchReads ? new AlignmentMateFinder(MAX_FRAGMENT_SIZE) : null; var RegionPadder = new RegionPadder(chrRef, null); var alignmentSource = new AlignmentSource(mae, mateFinder, stitcher, config); var variantFinder = new CandidateVariantFinder(options.MinimumBaseCallQuality, options.MaxSizeMNV, options.MaxGapBetweenMNV, options.CallMNVs); var alleleCaller = new AlleleCaller(new VariantCallerConfig { IncludeReferenceCalls = options.OutputgVCFFiles, MinVariantQscore = options.MinimumVariantQScore, MaxVariantQscore = options.MaximumVariantQScore, VariantQscoreFilterThreshold = options.FilteredVariantQScore > options.MinimumVariantQScore ? options.FilteredVariantQScore : (int?)null, MinCoverage = options.MinimumCoverage, MinFrequency = options.MinimumFrequency, EstimatedBaseCallQuality = options.AppliedNoiseLevel == -1 ? options.MinimumBaseCallQuality : options.AppliedNoiseLevel, StrandBiasModel = options.StrandBiasModel, StrandBiasFilterThreshold = options.StrandBiasAcceptanceCriteria, FilterSingleStrandVariants = options.FilterOutVariantsPresentOnlyOneStrand, GenotypeModel = options.GTModel }); var stateManager = new RegionStateManager(); return(new SomaticVariantCaller( alignmentSource, variantFinder, alleleCaller, vcfWriter, stateManager, chrRef, RegionPadder, biasFileWriter)); }