public void GetMate() { var finder = new AlignmentMateFinder(1001); var read1 = CreateAlignment(100, 500, "1"); var read1Mate = CreateAlignment(500, 100, "1"); var read2 = CreateAlignment(200, 500, "2"); var read2Mate = CreateAlignment(500, 200, "2"); var read3 = CreateAlignment(201, 600, "3"); var read3Mate = CreateAlignment(600, 201, "3"); var read4 = CreateAlignment(1000, 2001, "4"); var read4Mate = CreateAlignment(2001, 1000, "4"); var read5 = CreateAlignment(2500, 3502, "5"); var read5Mate = CreateAlignment(3502, 2500, "5"); Assert.Equal(finder.GetMate(read1), null); Assert.Equal(finder.GetMate(read2), null); Assert.Equal(finder.GetMate(read3), null); TestHelper.CompareReads(finder.GetMate(read2Mate), read2); TestHelper.CompareReads(finder.GetMate(read1Mate), read1); TestHelper.CompareReads(finder.GetMate(read3Mate), read3); Assert.Equal(finder.GetMate(read4), null); TestHelper.CompareReads(finder.GetMate(read4Mate), read4); Assert.Equal(finder.GetMate(read5), null); // jg - turned this behavior off for now because it's really inefficient // Assert.Throws<Exception>(() => finder.GetMate(read5Mate)); // out of window Assert.Throws <ArgumentException>(() => finder.GetMate(CreateAlignment(2500, 2500, null))); // null name Assert.Throws <ArgumentException>(() => finder.GetMate(CreateAlignment(2500, 2500, ""))); // empty name Assert.Throws <ArgumentException>(() => finder.GetMate(CreateAlignment(2500, -1, null))); // invalid mate position }
public void GetMate() { var finder = new AlignmentMateFinder(); var read1 = CreateAlignment(100, 500, "1"); var read1Mate = CreateAlignment(500, 100, "1"); var read2 = CreateAlignment(200, 400, "2"); var read2Mate = CreateAlignment(400, 200, "2"); var read3 = CreateAlignment(201, 600, "3"); var read3Mate = CreateAlignment(600, 201, "3"); var read4 = CreateAlignment(1000, 2000, "4"); var read4Mate = CreateAlignment(2000, 1000, "4"); var read5 = CreateAlignment(2500, 3501, "5"); var read5Mate = CreateAlignment(3501, 2500, "5"); Assert.Equal(finder.LastClearedPosition, null); Assert.Equal(finder.NextMatePosition, null); Assert.Equal(finder.GetMate(read1), null); Assert.Equal(finder.LastClearedPosition, 99); Assert.Equal(finder.NextMatePosition, 500); Assert.Equal(finder.GetMate(read2), null); Assert.Equal(finder.LastClearedPosition, 99); Assert.Equal(finder.NextMatePosition, 400); Assert.Equal(finder.GetMate(read3), null); Assert.Equal(finder.LastClearedPosition, 99); ReadTests.CompareReads(finder.GetMate(read2Mate), read2); Assert.Equal(finder.LastClearedPosition, 99); Assert.Equal(finder.NextMatePosition, 500); ReadTests.CompareReads(finder.GetMate(read1Mate), read1); Assert.Equal(finder.LastClearedPosition, 200); Assert.Equal(finder.NextMatePosition, 600); ReadTests.CompareReads(finder.GetMate(read3Mate), read3); Assert.Equal(finder.LastClearedPosition, null); Assert.Equal(finder.GetMate(read4), null); Assert.Equal(finder.LastClearedPosition, 999); ReadTests.CompareReads(finder.GetMate(read4Mate), read4); Assert.Equal(finder.LastClearedPosition, null); Assert.Equal(finder.GetMate(read5), null); Assert.Equal(finder.LastClearedPosition, 2499); Assert.Equal(finder.GetMate(read5Mate), null); // out of window gets tossed Assert.Equal(finder.LastClearedPosition, null); Assert.Equal(finder.NextMatePosition, null); Assert.Equal(2, finder.ReadsUnpairable); Assert.Throws<ArgumentException>(() => finder.GetMate(CreateAlignment(2500, 2500, null))); // null name Assert.Throws<ArgumentException>(() => finder.GetMate(CreateAlignment(2500, 2500, ""))); // empty name Assert.Throws<ArgumentException>(() => finder.GetMate(CreateAlignment(2500, -1, null))); // invalid mate position }
public void GetUnpaired() { var finder = new AlignmentMateFinder(); var read1 = CreateAlignment(100, 500, "1"); Assert.Null(finder.GetMate(read1)); Assert.Equal(new[] {read1.Name}, finder.GetUnpairedReads().Select(x => x.Name).ToArray()); }
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 ReadPurgedEventTriggered() { var finder = new AlignmentMateFinder(maxWindow:500); Read purgedRead = null; finder.ReadPurged += read => purgedRead = read; // reads whose mates will never be encountered because they are before the current position var read1 = CreateAlignment(5000, 100, "1"); Assert.Equal(finder.GetMate(read1), null); Assert.Equal(read1.Name, purgedRead.Name); // reads whose mates are more than the max distance before a read being added (and thus will not be encountered) var read2 = CreateAlignment(5000, 5100, "2"); Assert.Equal(finder.GetMate(read2), null); Assert.Equal(finder.GetMate(CreateAlignment(6000, 6100, "3")), null); Assert.Equal(read2.Name, purgedRead.Name); }
public void BadPairs() { var finder = new AlignmentMateFinder(); // mismatch on mate positions var read6 = CreateAlignment(2500, 2600, "6"); var read6Mate = CreateAlignment(2600, 2501, "6"); var read7 = CreateAlignment(2500, 2601, "7"); var read7Mate = CreateAlignment(2602, 2500, "7"); Assert.Equal(finder.GetMate(read6), null); Assert.Equal(finder.LastClearedPosition, 2499); Assert.Equal(finder.GetMate(read6Mate), null); Assert.Equal(finder.LastClearedPosition, null); // both cleared out Assert.Equal(finder.GetMate(read7), null); Assert.Equal(finder.LastClearedPosition, 2499); Assert.Equal(finder.GetMate(read7Mate), null); Assert.Equal(finder.LastClearedPosition, null); // both cleared out }
protected virtual IAlignmentSource CreateAlignmentSource(ChrReference chrReference, string bamFilePath, List <string> chrsToProcess = null) { AlignmentMateFinder mateFinder = null; var alignmentExtractor = new BamFileAlignmentExtractor(bamFilePath, chrReference.Name, _bamIntervalLookup.ContainsKey(bamFilePath) && _options.SkipNonIntervalAlignments ? _bamIntervalLookup[bamFilePath] : null); //Warn if the bam has sequences ordered differently to the reference genome. //That would confuse us because we will not know how the user wants to order the output gvcf. if (alignmentExtractor.SequenceOrderingIsNotConsistent(chrsToProcess)) { Logger.WriteToLog("Warning: Reference sequences in the bam do not match the order of the reference sequences in the genome. Check bam " + bamFilePath); Logger.WriteToLog("Variants will be ordered according to the reference genome"); } var config = new AlignmentSourceConfig { MinimumMapQuality = _options.MinimumMapQuality, OnlyUseProperPairs = _options.OnlyUseProperPairs, }; return(new AlignmentSource(alignmentExtractor, mateFinder, config)); }
protected virtual IAlignmentSource CreateAlignmentSource(ChrReference chrReference, string bamFilePath, bool commandLineSaysStitched, List <string> chrsToProcess = null) { AlignmentMateFinder mateFinder = null; var alignmentExtractor = new BamFileAlignmentExtractor(bamFilePath, commandLineSaysStitched, chrReference.Name); //Warn if the bam has sequences ordered differently to the reference genome. //That would confuse us because we will not know how the user wants to order the output gvcf. if (alignmentExtractor.SequenceOrderingIsNotConsistent(chrsToProcess)) { Logger.WriteToLog("Warning: Reference sequences in the bam do not match the order of the reference sequences in the genome. Check bam " + bamFilePath); Logger.WriteToLog("Variants will be ordered according to the reference genome"); } var config = new AlignmentSourceConfig { MinimumMapQuality = _options.BamFilterParameters.MinimumMapQuality, OnlyUseProperPairs = _options.BamFilterParameters.OnlyUseProperPairs, SkipDuplicates = _options.BamFilterParameters.RemoveDuplicates }; return(new AlignmentSource(alignmentExtractor, mateFinder, config)); }