예제 #1
0
        public void Execute()
        {
            if (_options == null)
            {
                return;
            }

            var factory = new Factory(_options);
            var phaser  = new Phaser(factory);

            phaser.Execute(_options.NumThreads);
        }
예제 #2
0
        private void ExecuteNeighborhoodThreadingTest(int numberOfThreads, int expectedNumberOfThreads)
        {
            var bamFilePath = Path.Combine(UnitTestPaths.TestDataDirectory, "MNV-25-var216_S216.bam");
            var vcfFilePath = Path.Combine(UnitTestPaths.TestDataDirectory, "MNV-25-var216_S216.vcf");
            var outFolder   = Path.Combine(UnitTestPaths.TestDataDirectory, "Out");

            var options = new ApplicationOptions
            {
                BamPath   = bamFilePath,
                VcfPath   = vcfFilePath,
                OutFolder = outFolder
            };

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

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

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

            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.GetNeighborhoods())
            .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"
                }
            });

            var processor = new Phaser(factory);

            processor.Execute(numberOfThreads);

            Logger.TryCloseLog();

            var threadsSpawnedBeforeFirstCompleted = 0;

            using (var reader = new StreamReader(logFile))
            {
                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);
        }