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 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?
        }
Пример #3
0
        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));
        }
Пример #4
0
        protected virtual IAlignmentSource CreateAlignmentSource(ChrReference chrReference, string bamFilePath)
        {
            var alignmentExtractor = new BamFileAlignmentExtractor(bamFilePath, _options.StitchReads, chrReference.Name);
            var mateFinder         = _options.StitchReads ? new AlignmentMateFinder(Constants.MaxFragmentSize) : null; // jg todo - do we want to expose this to command line?
            var stitcher           = _options.StitchReads ? CreateStitcher() : null;
            var config             = new AlignmentSourceConfig
            {
                MinimumMapQuality  = _options.MinimumMapQuality,
                OnlyUseProperPairs = _options.OnlyUseProperPairs,
            };

            return(new AlignmentSource(alignmentExtractor, mateFinder, stitcher, config));
        }
Пример #5
0
        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);
        }
Пример #6
0
        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));
        }
Пример #7
0
        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());
            }
        }
Пример #8
0
        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));
        }
Пример #9
0
        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));
        }
        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);
        }