Exemplo n.º 1
0
        // tests two bams in different folders
        // expectations:
        // - if outputfolder is not specified, logs are in directory of first bam
        // - if outputfolder specified, logs are in output folder
        // - vcf files have header and both chromosomes, output is where normally expected
        private void ExecuteTest(int numberOfThreads, string outputFolder = null)
        {
            var sourcePath         = Path.Combine(TestPaths.LocalTestDataDirectory, "Chr17Chr19.bam");
            var otherTestDirectory = Path.Combine(TestPaths.LocalScratchDirectory, "MultiProcessIn");
            var bamFilePath1       = Stage(sourcePath, "In1", otherTestDirectory + "1");
            var bamFilePath2       = Stage(sourcePath, "In2", otherTestDirectory + "2");

            var genomePath = Path.Combine(TestPaths.SharedGenomesDirectory, "chr17chr19");

            var options = new PiscesApplicationOptions
            {
                BAMPaths             = new[] { bamFilePath1, bamFilePath2 },
                GenomePaths          = new[] { genomePath },
                OutputDirectory      = outputFolder,
                CommandLineArguments = string.Format("-B {0},{1} -g {2}{3} -gVCF false", bamFilePath1, bamFilePath2, genomePath, string.IsNullOrEmpty(outputFolder) ? string.Empty : " -OutFolder " + outputFolder).Split(' '),
                VcfWritingParameters = new VcfWritingParameters()
                {
                    OutputGvcfFile = true
                }
            };

            options.SetIODirectories("Pisces");
            var factory = new Factory(options);

            foreach (var workRequest in factory.WorkRequests)
            {
                if (File.Exists(workRequest.OutputFilePath))
                {
                    File.Delete(workRequest.OutputFilePath);
                }
            }

            Logger.OpenLog(options.LogFolder, options.LogFileName, true);

            var processor = new GenomeProcessor(factory, factory.GetReferenceGenome(options.GenomePaths[0]), false, true);

            processor.Execute(numberOfThreads);

            Logger.CloseLog();

            foreach (var workRequest in factory.WorkRequests)
            {
                using (var reader = new VcfReader(workRequest.OutputFilePath))
                {
                    Assert.True(reader.HeaderLines.Any());
                    var variants = reader.GetVariants().ToList();

                    Assert.Equal(251, variants.Count());
                    Assert.Equal("chr17", variants.First().ReferenceName);
                    Assert.Equal("chr19", variants.Last().ReferenceName);
                }
            }

            Assert.True(Directory.GetFiles(options.LogFolder, options.LogFileNameBase).Any());
        }
        private PiscesApplicationOptions GetBasicOptions()
        {
            var options = new PiscesApplicationOptions()
            {
                BAMPaths    = new[] { _existingBamPath },
                GenomePaths = new[] { _existingGenome }
            };

            options.SetIODirectories("Pisces");

            return(options);
        }
        public void CheckLogFolderTest()
        {
            var bamFilePath      = Path.Combine(TestPaths.SharedBamDirectory, "Chr17Chr19.bam");
            var genomePath       = Path.Combine(TestPaths.SharedGenomesDirectory, "chr17chr19");
            var outDir           = Path.Combine(TestPaths.LocalScratchDirectory, "PiscesApplicationsOptionsTests");
            var defaultLogFolder = "PiscesLogs";

            //check when an out folder is specified
            var options = new PiscesApplicationOptions
            {
                BAMPaths             = new[] { bamFilePath },
                GenomePaths          = new[] { genomePath },
                VcfWritingParameters = new VcfWritingParameters()
                {
                    OutputGvcfFile = false
                },
                OutputDirectory = outDir
            };

            options.SetIODirectories("Pisces");
            Assert.Equal(Path.Combine(outDir, defaultLogFolder), options.LogFolder);

            //check when a bam is specified w/no out folder
            options = new PiscesApplicationOptions
            {
                BAMPaths             = new[] { bamFilePath },
                GenomePaths          = new[] { genomePath },
                VcfWritingParameters = new VcfWritingParameters()
                {
                    OutputGvcfFile = false
                },
            };
            options.SetIODirectories("Pisces");
            Assert.Equal(Path.Combine(TestPaths.SharedBamDirectory, defaultLogFolder), options.LogFolder);

            //check when a bam parent folder does not exist
            options = new PiscesApplicationOptions
            {
                BAMPaths             = new[] { "mybam.bam" },
                GenomePaths          = new[] { genomePath },
                VcfWritingParameters = new VcfWritingParameters()
                {
                    OutputGvcfFile = false
                },
            };
            options.SetIODirectories("Pisces");
            Assert.Equal(defaultLogFolder, options.LogFolder);
        }
        private void ExecuteChromosomeThreadingTest(int numberOfThreads, int expectedNumberOfThreads, string outDir)
        {
            var bamFilePath = Path.Combine(TestPaths.LocalTestDataDirectory, "Chr17Chr19.bam");
            var vcfFilePath = Path.Combine(outDir, "Chr17Chr19.vcf");
            var genomePath  = Path.Combine(TestPaths.SharedGenomesDirectory, "chr17chr19");

            var options = new PiscesApplicationOptions
            {
                BAMPaths             = new[] { bamFilePath },
                GenomePaths          = new[] { genomePath },
                VcfWritingParameters = new VcfWritingParameters()
                {
                    OutputGvcfFile = false
                },
                OutputDirectory = outDir
            };

            options.SetIODirectories("Pisces");
            var logFile = Path.Combine(options.LogFolder, options.LogFileName);

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

            Logger.OpenLog(options.LogFolder, options.LogFileName);

            var factory = new MockFactoryWithDefaults(options);

            factory.MockSomaticVariantCaller = new Mock <ISmallVariantCaller>();
            factory.MockSomaticVariantCaller.Setup(s => s.Execute()).Callback(() =>
            {
                Thread.Sleep(500);
            });
            var processor = new GenomeProcessor(factory, factory.GetReferenceGenome(genomePath), false);

            processor.Execute(numberOfThreads);


            Assert.False(File.Exists(vcfFilePath + "_chr17"));
            Assert.False(File.Exists(vcfFilePath + "_chr19"));
            Assert.True(File.Exists(vcfFilePath));

            Logger.CloseLog();

            //var threadsSpawnedBeforeFirstCompleted = 0;

            /* dont worry about logging
             * using (var reader = new StreamReader(new FileStream(logFile, FileMode.Open, FileAccess.Read)))
             * {
             *  string line;
             *  while ((line = reader.ReadLine()) != null)
             *  {
             *      if (string.IsNullOrEmpty(line)) continue;
             *
             *      if (line.Contains("Completed processing chr")) break;
             *
             *      if (line.Contains("Start processing chr"))
             *          threadsSpawnedBeforeFirstCompleted++;
             *  }
             * }*/

            //Assert.Equal(expectedNumberOfThreads, threadsSpawnedBeforeFirstCompleted);
        }