Exemplo n.º 1
0
 public static StitcherOptions DeepCopy(this StitcherOptions options)
 {
     return(new StitcherOptions()
     {
         Debug = options.Debug,
         DebugSummary = options.DebugSummary,
         DontStitchHomopolymerBridge = options.DontStitchHomopolymerBridge,
         FilterDuplicates = options.FilterDuplicates,
         FilterForProperPairs = options.FilterForProperPairs,
         FilterMinMapQuality = options.FilterMinMapQuality,
         FilterPairLowMapQ = options.FilterPairLowMapQ,
         FilterPairUnmapped = options.FilterPairUnmapped,
         FilterUnstitchablePairs = options.FilterUnstitchablePairs,
         IdentifyDuplicates = options.IdentifyDuplicates,
         MinBaseCallQuality = options.MinBaseCallQuality,
         NumThreads = options.NumThreads,
         SortMemoryGB = options.SortMemoryGB,
         MaxReadLength = options.MaxReadLength,
         IgnoreReadsAboveMaxLength = options.IgnoreReadsAboveMaxLength,
         MaxNumDisagreeingBases = options.MaxNumDisagreeingBases,
         NifyDisagreements = options.NifyDisagreements,
         NifyUnstitchablePairs = options.NifyUnstitchablePairs,
         ThreadByChromosome = options.ThreadByChromosome,
         StitchGappedPairs = options.StitchGappedPairs,
         StitchProbeSoftclips = options.StitchProbeSoftclips,
         UseSoftClippedBases = options.UseSoftClippedBases,
         KeepUnpairedReads = options.KeepUnpairedReads,
     });
 }
Exemplo n.º 2
0
 public ClassifierTransformerBlockFactory(Dictionary <int, string> refIdMapping, StitcherOptions stitcherOptions, GeminiOptions geminiOptions)
 {
     _refIdMapping           = refIdMapping;
     _stitcherOptions        = stitcherOptions;
     _geminiOptions          = geminiOptions;
     _maxDegreeOfParallelism = Math.Min(stitcherOptions.NumThreads, Environment.ProcessorCount);
 }
Exemplo n.º 3
0
        public void CreateBamReader()
        {
            // Should return a fully functional bam reader
            var tempPath = $"TemporaryBamFile_{Guid.NewGuid()}.bam";

            if (File.Exists(tempPath))
            {
                File.Delete(tempPath);
            }

            using (var bamWriter = new BamWriter(tempPath, "header", new List <GenomeMetadata.SequenceMetadata>()))
            {
                var bamWriterHandle = new BamWriterHandle(bamWriter);
                bamWriterHandle.WriteAlignment(TestHelpers.CreateBamAlignment("ATCG", 8, 10, 30, true));
                bamWriterHandle.WriteAlignment(null);
            }

            Assert.True(File.Exists(tempPath));

            var stitcherOptions = new StitcherOptions();
            var factory         = new GeminiDataSourceFactory(stitcherOptions, "fakeGenomePath", false);

            using (var bamReader = factory.CreateBamReader(tempPath))
            {
                BamAlignment alignment = new BamAlignment();
                var          getNext   = bamReader.GetNextAlignment(ref alignment, true);
                Assert.True(getNext);
                Assert.Equal(7, alignment.Position);
            }

            File.Delete(tempPath);
        }
Exemplo n.º 4
0
        public void ProcessBam()
        {
            var stitcherOptions = new StitcherOptions()
            {
            };
            var geminiOptions = new GeminiOptions()
            {
                RegionSize = 1000,
            };


            var readPair1 = TestHelpers.GetPair("5M1I5M", "5M1I5M", name: "Pair1");
            var readPair2 = TestHelpers.GetPair("5M1I5M", "5M1I5M", read1Position: 1001, name: "Pair2");
            var readPair3 = TestHelpers.GetPair("5M1I5M", "5M1I5M", read1Position: 1201, name: "Pair3");
            var readPair4 = TestHelpers.GetPair("5M1I5M", "5M1I5M", read1Position: 10000, name: "Pair4");
            var reads     = new List <ReadPair>()
            {
                readPair1, readPair2, readPair3, readPair4
            };

            var read = TestHelpers.CreateBamAlignment("AAAAAAAATA", 999, 1001, 30, true,
                                                      cigar: new CigarAlignment("10M"), name: "LonerPair1");

            read.SetIsProperPair(true);
            var lonerPair1Mate1 = new ReadPair(read, "LonerPair1");
            var read2           = TestHelpers.CreateBamAlignment("AAAAATAAAA", 1002, 999, 30, true,
                                                                 cigar: new CigarAlignment("10M"), name: "LonerPair1", isFirstMate: false);

            read2.SetIsProperPair(true);
            var lonerPair1Mate2 = new ReadPair(read2, "LonerPair1", readNumber: ReadNumber.Read2);

            var read3 = TestHelpers.CreateBamAlignment("AAAAAAAAAA", 999, 5001, 30, true,
                                                       cigar: new CigarAlignment("10M"), name: "LonerPairFarApart");

            read3.SetIsProperPair(true);
            var read4 = TestHelpers.CreateBamAlignment("AAAAAAAAAA", 5001, 999, 30, true,
                                                       cigar: new CigarAlignment("10M"), name: "LonerPairFarApart", isFirstMate: false);

            read4.SetIsProperPair(true);
            var lonerPair2Mate1 = new ReadPair(read3, name: "LonerPairFarApart");
            var lonerPair2Mate2 = new ReadPair(read4, name: "LonerPairFarApart", readNumber: ReadNumber.Read2);

            var lonerReads = new List <ReadPair>()
            {
                lonerPair1Mate1, lonerPair1Mate2, lonerPair2Mate1, lonerPair2Mate2
            };
            var alignments = new List <BamAlignment>();

            Execute(alignments, reads, geminiOptions, stitcherOptions, lonerReads);
            Assert.Equal(1, alignments.Count(x => x.Name == "Pair1"));
            Assert.Equal(1, alignments.Count(x => x.Name == "Pair2"));
            Assert.Equal(1, alignments.Count(x => x.Name == "Pair3"));
            Assert.Equal(1, alignments.Count(x => x.Name == "Pair4"));
            Assert.Equal(1, alignments.Count(x => x.Name == "LonerPair1"));
            Assert.Equal(2, alignments.Count(x => x.Name == "LonerPairFarApart"));
            Assert.Equal(7, alignments.Count);

            alignments.Clear();
        }
Exemplo n.º 5
0
 public GeminiDataSourceFactory(StitcherOptions stitcherOptions, string genomePath, bool skipAndRemoveDuplicates, int?refId = null, string regionsFile = null, bool debug = false)
 {
     _stitcherOptions         = stitcherOptions;
     _genomePath              = genomePath;
     _skipAndRemoveDuplicates = skipAndRemoveDuplicates;
     _refId = refId;
     _debug = debug;
 }
 public BamRealignmentFactory(GeminiOptions geminiOptions,
                              RealignmentAssessmentOptions realignmentAssessmentOptions, StitcherOptions stitcherOptions, RealignmentOptions realignmentOptions, string outputDir)
 {
     _geminiOptions = geminiOptions;
     _realignmentAssessmentOptions = realignmentAssessmentOptions;
     _stitcherOptions    = stitcherOptions;
     _realignmentOptions = realignmentOptions;
     _outputDir          = outputDir;
 }
Exemplo n.º 7
0
 public GeminiApplicationOptions()
 {
     StitcherOptions              = new StitcherOptions();
     GeminiSampleOptions          = new GeminiSampleOptions();
     IndelFilteringOptions        = new IndelFilteringOptions();
     RealignmentAssessmentOptions = new RealignmentAssessmentOptions();
     RealignmentOptions           = new RealignmentOptions();
     GeminiOptions = new GeminiOptions();
 }
Exemplo n.º 8
0
        public void CreateReadPairSource()
        {
            var stitcherOptions = new StitcherOptions();
            var factory         = new GeminiDataSourceFactory(stitcherOptions, "fakeGenomePath", false);

            var bamReader      = new Mock <IBamReader>();
            var readPairSource = factory.CreateReadPairSource(bamReader.Object, new ReadStatusCounter());

            Assert.Equal(typeof(PairFilterReadPairSource), readPairSource.GetType());
            // TODO maybe I can do some asserts on the configuration of the readpair source by passing through some reads and checking result? that's pretty indirect though.
        }
Exemplo n.º 9
0
 public BlockFactorySource(StitcherOptions stitcherOptions, GeminiOptions geminiOptions, Dictionary <int, string> refIdMapping, BamRealignmentFactory bamRealignmentFactory,
                           IGeminiDataSourceFactory dataSourceFactory, GeminiSampleOptions geminiSampleOptions, RealignmentOptions realignmentOptions, IGeminiFactory geminiFactory)
 {
     _stitcherOptions        = stitcherOptions;
     _geminiOptions          = geminiOptions;
     _refIdMapping           = refIdMapping;
     _bamRealignmentFactory  = bamRealignmentFactory;
     _dataSourceFactory      = dataSourceFactory;
     _geminiSampleOptions    = geminiSampleOptions;
     _realignmentOptions     = realignmentOptions;
     _geminiFactory          = geminiFactory;
     _maxDegreeOfParallelism = Math.Min(_stitcherOptions.NumThreads, Environment.ProcessorCount);
 }
Exemplo n.º 10
0
        public void TestBamProcessor()
        {
            var inBam     = Path.Combine(TestPaths.SharedBamDirectory, "Bcereus_S4.bam");
            var expBam    = Path.Combine(TestPaths.LocalTestDataDirectory, "Bcereus_S4.stitched.bam");
            var outFolder = Path.Combine(TestPaths.LocalScratchDirectory);
            var outBam    = Path.Combine(outFolder, "Bcereus_S4.stitched.bam");

            var stitcherOptions = new StitcherOptions();

            if (File.Exists(outBam))
            {
                File.Delete(outBam);
            }

            RunProcessorTest(inBam, outBam, expBam, outFolder, false, stitcherOptions);
        }
Exemplo n.º 11
0
        public GeminiWorkflow(IGeminiDataSourceFactory dataSourceFactory,
                              IGeminiDataOutputFactory dataOutputFactory, GeminiOptions geminiOptions,
                              GeminiSampleOptions geminiSampleOptions, RealignmentOptions realignmentOptions, StitcherOptions stitcherOptions, string outputDirectory, RealignmentAssessmentOptions realignmentAssessmentOptions, IndelFilteringOptions indelFilteringOptions, ISamtoolsWrapper samtoolsWrapper)
        {
            _dataSourceFactory   = dataSourceFactory;
            _dataOutputFactory   = dataOutputFactory;
            _geminiOptions       = geminiOptions;
            _geminiSampleOptions = geminiSampleOptions;
            _realignmentOptions  = realignmentOptions;
            _samtoolsWrapper     = samtoolsWrapper;
            _stitcherOptions     = stitcherOptions ?? new StitcherOptions();

            _geminiFactory = new GeminiFactory(geminiOptions, indelFilteringOptions);
            var bamRealignmentFactory = new BamRealignmentFactory(geminiOptions,
                                                                  realignmentAssessmentOptions, stitcherOptions, realignmentOptions,
                                                                  outputDirectory);

            _bamRealignmentFactory = bamRealignmentFactory;
        }
Exemplo n.º 12
0
        private static void Execute(List <BamAlignment> alignments, List <ReadPair> reads, GeminiOptions geminiOptions, StitcherOptions stitcherOptions, List <ReadPair> lonerpairs = null)
        {
            var mockOutcomesWriter    = new Mock <IOutcomesWriter>();
            var mockDataOutputFactory = DataflowMocks.MockDataOutputFactory(alignments);
            var mockTextWriter        = new Mock <ITextWriter>();

            mockDataOutputFactory.Setup(x => x.GetTextWriter(It.IsAny <string>()))
            .Returns(mockTextWriter.Object);
            var mockReader            = DataflowMocks.MockReader();
            var mockReadPairSource    = DataflowMocks.MockDataSource(reads, lonerpairs);
            var mockDataSourceFactory = DataflowMocks.MockDataSourceFactory(mockReader, mockReadPairSource);
            var mockSamtoolsWrapper   = new Mock <ISamtoolsWrapper>();
            var geminiSampleOptions   = new GeminiSampleOptions()
            {
                RefId = 1, OutputFolder = "OutFolder"
            };

            var geminiWorkflow = new GeminiWorkflow(mockDataSourceFactory.Object, mockDataOutputFactory.Object,
                                                    geminiOptions, geminiSampleOptions, new RealignmentOptions(), stitcherOptions, "outdir",
                                                    new RealignmentAssessmentOptions(), new IndelFilteringOptions(), mockSamtoolsWrapper.Object);

            geminiWorkflow.Execute();
        }
Exemplo n.º 13
0
        private static void RunProcessorTest(string inBam, string outBam, string expBam, string outFolder, bool threadbyChr, StitcherOptions stitcherOptions)
        {
            if (File.Exists(outBam))
            {
                File.Delete(outBam);
            }


            Logger.OpenLog(TestPaths.LocalScratchDirectory, "StitcherTestLog.txt", true);
            var processor = threadbyChr ? (IStitcherProcessor) new GenomeProcessor(inBam) : new BamProcessor();

            processor.Process(inBam, outFolder, stitcherOptions);
            Logger.CloseLog();


            Assert.True(File.Exists(outBam));

            var observedAlignment = new BamAlignment();
            var expectedAlignment = new BamAlignment();

            using (var outReader = new BamReader(outBam))
                using (var expReader = new BamReader(expBam))
                {
                    while (true)
                    {
                        var nextObservation = outReader.GetNextAlignment(ref observedAlignment, true);

                        var nextExpected = expReader.GetNextAlignment(ref expectedAlignment, true);

                        if ((nextExpected == false) || (expectedAlignment == null))
                        {
                            break;
                        }


                        Assert.Equal(expectedAlignment.Bases, observedAlignment.Bases);
                        Assert.Equal(expectedAlignment.Position, observedAlignment.Position);
                        Assert.Equal(expectedAlignment.Qualities, observedAlignment.Qualities);
                    }

                    outReader.Close();
                    expReader.Close();
                }
        }