Esempio n. 1
0
        private void ExecuteNeighborhoodThreadingTest(int numberOfThreads, int expectedNumberOfThreads)
        {
            var bamFilePath = Path.Combine(TestPaths.LocalTestDataDirectory, "MNV-25-var216_S216.bam");
            var vcfFilePath = Path.Combine(TestPaths.LocalTestDataDirectory, "MNV-25-var216_S216.vcf");
            var outFolder   = Path.Combine(TestPaths.LocalScratchDirectory, "Out");

            var options = new ScyllaApplicationOptions
            {
                BamPath         = bamFilePath,
                VcfPath         = vcfFilePath,
                OutputDirectory = outFolder
            };

            options.SetIODirectories("Scylla");

            var logFile = Path.Combine(options.LogFolder, options.LogFileNameBase);

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


            var factory = new MockFactoryWithDefaults(options);

            factory.MockVcfWriter = new Mock <IVcfFileWriter <CalledAllele> >();
            factory.MockVcfWriter.Setup(s => s.Write(It.IsAny <IEnumerable <CalledAllele> >(), It.IsAny <IRegionMapper>())).Callback(() =>
            {
                Thread.Sleep(500);
            });



            var neighborhoods = GetNeighborhoods(expectedNumberOfThreads);

            factory.MockNeighborhoodBuilder = new Mock <INeighborhoodBuilder>();
            factory.MockNeighborhoodBuilder.Setup(s => s.GetBatchOfNeighborhoods(0))
            .Returns(neighborhoods);

            factory.MockVeadSource = MockVeadSource();

            factory.MockVariantSource = new Mock <IVcfVariantSource>();
            factory.MockVariantSource.Setup(s => s.GetVariants()).Returns(new List <VcfVariant>()
            {
                new VcfVariant()
                {
                    ReferenceName     = "chr1",
                    ReferencePosition = 123,
                    VariantAlleles    = new[] { "A" },
                    GenotypeTagOrder  = new[] { "GT", "GQ", "AD", "VF", "NL", "SB", "NC" },
                    InfoTagOrder      = new[] { "DP" },
                    Genotypes         = new List <Dictionary <string, string> >()
                    {
                        new Dictionary <string, string>()
                        {
                            { "GT", "0/1" },
                            { "GQ", "100" },
                            { "AD", "6830,156" },
                            { "VF", "0.05" },
                            { "NL", "20" },
                            { "SB", "-20" },
                            { "NC", "0.01" }
                        }
                    },
                    InfoFields = new Dictionary <string, string>()
                    {
                        { "DP", "1000" }
                    },
                    ReferenceAllele = "C"
                },
                new VcfVariant()
                {
                    ReferenceName     = "chr2",
                    ReferencePosition = 123,
                    VariantAlleles    = new[] { "A" },
                    GenotypeTagOrder  = new[] { "GT", "GQ", "AD", "VF", "NL", "SB", "NC" },
                    InfoTagOrder      = new[] { "DP" },
                    Genotypes         = new List <Dictionary <string, string> >()
                    {
                        new Dictionary <string, string>()
                        {
                            { "GT", "0/1" },
                            { "GQ", "100" },
                            { "AD", "6830,156" },
                            { "VF", "0.05" },
                            { "NL", "20" },
                            { "SB", "-20" },
                            { "NC", "0.01" }
                        }
                    },
                    InfoFields = new Dictionary <string, string>()
                    {
                        { "DP", "1000" }
                    },
                    ReferenceAllele = "T"
                }
            });

            Logger.OpenLog(options.LogFolder, options.LogFileNameBase, true);
            var processor = new VariantPhaser(factory);

            processor.Execute(numberOfThreads);

            Logger.CloseLog();

            var threadsSpawnedBeforeFirstCompleted = 0;

            using (var reader = new StreamReader(new FileStream(logFile, FileMode.Open)))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.Contains("Completed processing"))
                    {
                        break;
                    }

                    if (line.Contains("Processing Neighborhood"))
                    {
                        threadsSpawnedBeforeFirstCompleted++;
                    }
                }
            }

            Assert.Equal(expectedNumberOfThreads, threadsSpawnedBeforeFirstCompleted);
        }
Esempio n. 2
0
        private void ExecuteNeighborhoodThreadingTest(int numberOfThreads, int expectedNumberOfThreads)
        {
            var bamFilePath = Path.Combine(TestPaths.LocalTestDataDirectory, "MNV-25-var216_S216.bam");
            var vcfFilePath = Path.Combine(TestPaths.LocalTestDataDirectory, "MNV-25-var216_S216.vcf");
            var outFolder   = Path.Combine(TestPaths.LocalScratchDirectory, "Out");

            var options = new ScyllaApplicationOptions
            {
                BamPath         = bamFilePath,
                VcfPath         = vcfFilePath,
                OutputDirectory = outFolder
            };

            options.SetIODirectories("Scylla");

            var logFile = Path.Combine(options.LogFolder, options.LogFileNameBase);

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


            var factory = new MockFactoryWithDefaults(options);

            factory.MockVcfWriter = new Mock <IVcfFileWriter <CalledAllele> >();
            factory.MockVcfWriter.Setup(s => s.Write(It.IsAny <IEnumerable <CalledAllele> >(), It.IsAny <IRegionMapper>())).Callback(() =>
            {
                Thread.Sleep(500);
            });



            var neighborhoods = GetNeighborhoods(expectedNumberOfThreads);

            factory.MockNeighborhoodBuilder = new Mock <INeighborhoodBuilder>();
            var numRaw = 0;

            factory.MockNeighborhoodBuilder.Setup(s => s.GetBatchOfCallableNeighborhoods(0, out numRaw))
            .Returns(neighborhoods);

            factory.MockVeadSource = MockVeadSource();

            factory.MockVariantSource = new Mock <IAlleleSource>();
            factory.MockVariantSource.Setup(s => s.GetVariants()).Returns(new List <CalledAllele>()
            {
                new CalledAllele()
                {
                    Chromosome        = "chr1",
                    ReferencePosition = 123,
                    AlternateAllele   = "A",
                    ReferenceAllele   = "C",
                    Genotype          = Pisces.Domain.Types.Genotype.HeterozygousAltRef,
                    TotalCoverage     = 10000
                },
                new CalledAllele()
                {
                    Chromosome        = "chr2",
                    ReferencePosition = 123,
                    AlternateAllele   = "A",
                    ReferenceAllele   = "T",
                    Genotype          = Pisces.Domain.Types.Genotype.HeterozygousAltRef,
                    TotalCoverage     = 10000
                }
            });

            Logger.OpenLog(options.LogFolder, options.LogFileNameBase, true);
            var processor = new VariantPhaser(factory);

            processor.Execute(numberOfThreads);

            Logger.CloseLog();

            var threadsSpawnedBeforeFirstCompleted = 0;

            using (var reader = new StreamReader(new FileStream(logFile, FileMode.Open)))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.Contains("Completed processing"))
                    {
                        break;
                    }

                    if (line.Contains("Processing Neighborhood"))
                    {
                        threadsSpawnedBeforeFirstCompleted++;
                    }
                }
            }

            Assert.Equal(expectedNumberOfThreads, threadsSpawnedBeforeFirstCompleted);
        }