Exemplo n.º 1
0
        protected override void ProgramExecution()
        {
            AdjustOptions(ref _options);
            try
            {
                var factory       = new Factory(_options);
                var variantPhaser = new VariantPhaser(factory);
                variantPhaser.Execute(_options.NumThreads);
            }
            catch (Exception ex)
            {
                var wrappedException = new Exception("Unable to process: " + ex.Message, ex);
                Logger.WriteExceptionToLog(wrappedException);

                throw wrappedException;
            }
        }
Exemplo n.º 2
0
        public void GetPhasingProbabilities()
        {
            var variantSites = new List <VariantSite>
            {
                new VariantSite(1),
                new VariantSite(2),
                new VariantSite(45)
            };

            var clusters = new SetOfClusters(new ClusteringParameters());

            // There should be a PhasingResult for each variant in variantSites
            var phasingProbabilities = VariantPhaser.GetPhasingProbabilities(variantSites, clusters);

            Assert.Equal(variantSites.Count, phasingProbabilities.Count);
            Assert.Equal(variantSites.Select(x => x), phasingProbabilities.Keys.ToList());
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }