public void CallSomaticVariants_LowDepthTest() { List <ChrReference> chrRef = new List <ChrReference>() { new ChrReference() { Name = "chr19", Sequence = "TTGTCAGTGCGCTTTTCCCAACACCACCTGCTCCGACCACCACCAGTTTGTACTCAGTCATTTCACACCAGCAAGAACCTGTTGGAAACCAGTAATCAGGGTTAATTGGCGGCGAAAAAAAAAAAAAAAAAAAAAAAAAA" } }; var options = new ApplicationOptions() { BAMPaths = new[] { _bamSmallS1 }, GenomePaths = new[] { _genomeChr19 }, //IntervalPaths = new[] { _intervalsChr17Chr19 }, DebugMode = true, CallMNVs = true, UseMNVReallocation = false, MaxSizeMNV = 100, OutputgVCFFiles = true, MinimumCoverage = 1000, OutputFolder = UnitTestPaths.TestDataDirectory }; var vcfFilePath = Path.ChangeExtension(options.BAMPaths[0], "genome.vcf"); var factory = new Factory(options); IGenome genomeRef; genomeRef = new MockGenome(chrRef); var bp = new BamProcessor(factory, genomeRef); bp.Execute(1); List <VcfVariant> coverage1000results = VcfReader.GetAllVariantsInFile(vcfFilePath); options = new ApplicationOptions() { BAMPaths = new[] { _bamSmallS1 }, GenomePaths = new[] { _genomeChr19 }, // IntervalPaths = new[] { _intervalsChr17Chr19 }, DebugMode = true, CallMNVs = true, UseMNVReallocation = false, OutputgVCFFiles = true, OutputFolder = UnitTestPaths.TestDataDirectory }; factory = new Factory(options); bp = new BamProcessor(factory, genomeRef); bp.Execute(1); List <VcfVariant> coverage10results = VcfReader.GetAllVariantsInFile(vcfFilePath); // Assert.NotEqual(coverage1000results.Count, coverage10results.Count); // Assert.Equal(coverage1000results.Count, 84); // Assert.Equal(coverage10results.Count, 100); }
public void Execute() { var factory = new Factory(_options); if (!_options.ThreadByChr) { var distinctGenomeDirectories = _options.GenomePaths.Distinct(); foreach (var genomeDirectory in distinctGenomeDirectories) { var genome = factory.GetReferenceGenome(genomeDirectory); var genomeProcessor = new GenomeProcessor(factory, genome); genomeProcessor.Execute(_options.MaxNumThreads); } } else { var workRequest = factory.WorkRequests.First(); var genome = factory.GetReferenceGenome(workRequest.GenomeDirectory); var bamProcessor = new BamProcessor(factory, genome); bamProcessor.Execute(_options.MaxNumThreads); } }
public void Execute( string bamFilePath, string vcfFilePath, string intervalPath, List <BaseCalledAllele> expectedVariants, List <ChrReference> fakeReferences = null, bool doCheckVariants = true, bool doCheckReferences = false, int expectedNumCoveredPositions = 0, bool threadByChr = false, int doCountsOnly = 0, bool doLog = false, bool callMnvs = true, ApplicationOptions applicationOptions = null) { if (doCheckReferences) { vcfFilePath = Path.ChangeExtension(vcfFilePath, "genome.vcf"); } if (applicationOptions == null) { applicationOptions = new ApplicationOptions { BAMPaths = new[] { bamFilePath }, IntervalPaths = string.IsNullOrEmpty(intervalPath) ? null : new[] { intervalPath }, GenomePaths = new[] { GenomeDirectory }, OutputgVCFFiles = doCheckReferences, OutputBiasFiles = true, DebugMode = doLog, MinimumBaseCallQuality = 20, CallMNVs = callMnvs }; } Logger.TryOpenLog(applicationOptions.LogFolder, ApplicationOptions.LogFileName); var factory = GetFactory(applicationOptions); IGenome genome; if (fakeReferences == null) { genome = factory.GetReferenceGenome(GenomeDirectory); } else { genome = new MockGenome(fakeReferences, GenomeDirectory); } if (threadByChr) { var processor = new BamProcessor(factory, genome); processor.Execute(1); } else { var processor = new GenomeProcessor(factory, genome); processor.Execute(1); } Logger.TryCloseLog(); using (var reader = new VcfReader(vcfFilePath)) { var alleles = reader.GetVariants().ToList(); var variantCalls = alleles.Where(a => a.VariantAlleles[0] != ".").ToList(); if (doCheckVariants) { if (doCountsOnly > 0) { Assert.Equal(variantCalls.Count(), doCountsOnly); } else { CheckVariants(variantCalls, expectedVariants); } } if (doCheckReferences) { var referenceAlleles = alleles.Where(a => a.VariantAlleles[0] == ".").ToList(); // make sure no reference calls at variant positions Assert.Equal(referenceAlleles.Count(), alleles.Count(a => !variantCalls.Select(v => v.ReferencePosition).Contains(a.ReferencePosition))); } } }
private void ExecuteChromosomeThreadingTest(int numberOfThreads, int expectedNumberOfThreads) { var bamFilePath = Path.Combine(UnitTestPaths.TestDataDirectory, "var123var35.bam"); var vcfFilePath = Path.Combine(UnitTestPaths.TestDataDirectory, "var123var35.vcf"); var genomePath = Path.Combine(UnitTestPaths.TestGenomesDirectory, "chr17chr19"); var options = new ApplicationOptions { BAMPaths = new[] { bamFilePath }, GenomePaths = new[] { genomePath }, }; var logFile = Path.Combine(options.LogFolder, ApplicationOptions.LogFileName); if (File.Exists(logFile)) { File.Delete(logFile); } Logger.TryOpenLog(options.LogFolder, ApplicationOptions.LogFileName); var factory = new MockFactoryWithDefaults(options); factory.MockSomaticVariantCaller = new Mock <ISomaticVariantCaller>(); factory.MockSomaticVariantCaller.Setup(s => s.Execute()).Callback(() => { Thread.Sleep(500); }); var processor = new BamProcessor(factory, factory.GetReferenceGenome(genomePath)); processor.Execute(numberOfThreads); Assert.False(File.Exists(vcfFilePath + "_chr17")); Assert.False(File.Exists(vcfFilePath + "_chr19")); Assert.True(File.Exists(vcfFilePath)); 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 chr")) { break; } if (line.Contains("Start processing chr")) { threadsSpawnedBeforeFirstCompleted++; } } } Assert.Equal(expectedNumberOfThreads, threadsSpawnedBeforeFirstCompleted); }