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); } }
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); } }