예제 #1
0
        public static void CallStrandedVariantsWithMockData(string vcfOutputPath, ApplicationOptions options, AmpliconTestFactory testFactory)
        {
            var appFactory = new MockFactoryWithDefaults(options);

            using (var vcfWriter = appFactory.CreateVcfWriter(vcfOutputPath, new VcfWriterInputContext()))
            {
                using (var biasWriter = new StrandBiasFileWriter(vcfOutputPath))
                {
                    var svc = CreateMockVariantCaller(vcfWriter, options, testFactory.ChrInfo, testFactory.AlignmentExtractor, biasWriter);
                    vcfWriter.WriteHeader();
                    biasWriter.WriteHeader();
                    svc.Execute();
                    biasWriter.Dispose();
                }
            }
            Assert.True(File.Exists(vcfOutputPath));
        }
예제 #2
0
        public void TestReadLoadingOnStitchingScenarios(StitchingScenario scenario, string resultFile)
        {
            //limit the scope of concern for now.
            if (scenario.ShouldStitch != true)
            {
                return;
            }

            //limit the scope of concern for now.
            if (scenario.ShouldRefStitch != true)
            {
                return;
            }

            var resultsSummary = Path.Combine(Options.OutputFolder, LoadingSummaryFileName);

            using (StreamWriter sw = new StreamWriter(resultsSummary, true))
            {
                var sb = new StringBuilder(
                    string.Join(",", DateTime.Today.ToShortDateString(),
                                DateTime.Now.ToLongTimeString(),
                                scenario.Category, scenario.Id));

                // If it was supposed to stitch, there should only be one read in the output reads, and it's the stitched one.

                var factory = new AmpliconTestFactory(RefGenomeSequence);

                try
                {
                    byte qualityForAll = 30;

                    var MNVdata = StageMNVdata(scenario);

                    var varRead = BuildRead(scenario.OutputRead1, qualityForAll, MNVdata);
                    var refRead = BuildRead(scenario.OutputRefRead1, qualityForAll, NoMNVdata(scenario));

                    if ((varRead == null) || (refRead == null))
                    {
                        //total fail.
                        sb.Append(",total fail to build reads");
                        sw.WriteLine(sb.ToString());
                        return;
                    }

                    //check the reads all loaded with the right counts into the right directions.
                    var varLoadingResults = StitchedReadLoadingHelper.CheckReadLoading(varRead, Options, ChrInfo, true, scenario);
                    if (varLoadingResults.Length == 1)
                    {
                        //total fail. get error msg
                        sb.Append("," + varLoadingResults[0]);
                        sw.WriteLine(sb.ToString());
                        return;
                    }

                    var refLoadingResults = StitchedReadLoadingHelper.CheckReadLoading(refRead, Options, ChrInfo, false, scenario);
                    if (refLoadingResults.Length == 1)
                    {
                        //total fail. get error msg
                        sb.Append("," + refLoadingResults[0]);
                        sw.WriteLine(sb.ToString());
                        return;
                    }


                    List <string> expectedValues = new List <string>()
                    {
                        scenario.VarLoading, scenario.RefLoading, scenario.CandidateDirection, "0"
                    };

                    List <string> observedValues = new List <string>()
                    {
                        varLoadingResults[0], refLoadingResults[0], varLoadingResults[1], refLoadingResults[1]
                    };

                    sb.Append(GetResultString(expectedValues, observedValues));

                    sw.WriteLine(sb.ToString());
                }
                catch (Exception ex)
                {
                    sb.Append(",Fail:  " + ex);
                    sw.WriteLine(sb.ToString());
                }
            }
        }
예제 #3
0
        private void CallVariantsWithMockData(string vcfOutputPath, ApplicationOptions options, AmpliconTestFactory atf)
        {
            var appFactory = new MockFactoryWithDefaults(options);

            using (var vcfWriter = appFactory.CreateVcfWriter(vcfOutputPath, new VcfWriterInputContext()))
            {
                var svc = CreateMockVariantCaller(vcfWriter, options, atf.ChrInfo, atf._MAE);
                vcfWriter.WriteHeader();
                svc.Execute();
            }

            Assert.True(File.Exists(vcfOutputPath));
        }
예제 #4
0
        public void TestForStrandBiasOnStitchingScenarios(StitchingScenario scenario, string resultFile)
        {
            //limit the scope of concern for now.
            if (scenario.ShouldRefStitch != true)
            {
                return;
            }


            //limit the scope of concern for now.
            if (scenario.ShouldStitch != true)
            {
                return;
            }

            var resultsSummary = Path.Combine(Options.OutputFolder, StrandBiasSummaryFileName);

            using (StreamWriter sw = new StreamWriter(resultsSummary, true))
            {
                var sb = new StringBuilder(
                    string.Join(",", DateTime.Today.ToShortDateString(),
                                DateTime.Now.ToLongTimeString(),
                                scenario.Category, scenario.Id));

                try
                {
                    if (!Directory.Exists(Options.OutputFolder))
                    {
                        Directory.CreateDirectory(Options.OutputFolder);
                    }


                    var factory = new AmpliconTestFactory(new string('A', 100), sourceIsStitched: true);

                    byte qualityForAll      = 30;
                    int  numVariantCounts   = 2; // 10;
                    int  numReferenceCounts = 2; // 90;
                    var  varRead            = BuildRead(scenario.OutputRead1, qualityForAll, StageMNVdata(scenario));
                    var  refRead            = BuildRead(scenario.OutputRefRead1, qualityForAll, NoMNVdata(scenario));

                    if (refRead == null)
                    {
                        return;
                    }

                    factory.StageStitchedVariant(
                        varRead, numVariantCounts,
                        refRead, numReferenceCounts);

                    var outputFileName = string.Format("{0}_{1}.vcf", scenario.Category, scenario.Id);
                    var vcfOutputPath  = Path.Combine(Options.OutputFolder, outputFileName);
                    var biasOutputPath = StrandBiasFileWriter.GetBiasFilePath(vcfOutputPath);

                    File.Delete(vcfOutputPath);
                    File.Delete(biasOutputPath);

                    StitchedReadBiasHelper.CallStrandedVariantsWithMockData(vcfOutputPath, Options, factory);
                    var varResults  = StitchedReadBiasHelper.GetResults(VcfReader.GetAllVariantsInFile(vcfOutputPath));
                    var biasResults = StitchedReadBiasHelper.GetStrandResultsFromFile(biasOutputPath);

                    var observedFrequency = (varResults.Count == 0) ? "0": "";
                    var observedSB        = (biasResults.Count == 0) ? "FN": "";

                    for (int i = 0; i < varResults.Count; i++)
                    {
                        var varResult = varResults[i];
                        if (i != 0)
                        {
                            observedFrequency += ";";
                        }
                        observedFrequency += varResult.VariantFrequency;
                    }

                    for (int i = 0; i < biasResults.Count; i++)
                    {
                        var biasResult = biasResults[i];
                        if (i != 0)
                        {
                            observedSB += ";";
                        }
                        observedSB += biasResult.HasStrandBias;

                        //there should be no SB on our current set of stitched scenarios.
                        Assert.True(!biasResult.HasStrandBias);
                    }

                    var expectedValues = new List <string>()
                    {
                        "1", scenario.Frequency, scenario.ShouldBias
                    };

                    var observedValues = new List <string>()
                    {
                        varResults.Count.ToString(), observedFrequency, observedSB
                    };

                    sb.Append(GetResultString(expectedValues, observedValues));

                    sw.WriteLine(sb.ToString());
                }
                catch (Exception ex)
                {
                    sb.Append(",Fail:  " + ex);
                    sw.WriteLine(sb.ToString());
                }
            }
        }
예제 #5
0
        /// <summary>
        /// MNV within overlap region's edge
        /// </summary>
        //[Fact]
        //[Trait("Category", "ReadStitching")]
        //public void MNV_PartialOverlap()
        //{
        //    var outputFileName = "Mnv-PartialOverlap_S1.genome.vcf";

        //    var test = new AmpliconMnvTest()
        //    {
        //        StitchPairedReads = true,
        //        RequireXCTagToStitch = true,
        //        ReadLength = 30,
        //        ReferenceSequenceRelative = "GTTGGTCTTC" + "TATTTTATGCGAATTCTTCT" + "AAGATTCCCA",
        //        VariantPositionRelative = 9,
        //        ChangedSequence = "AAG",
        //        VariantDepth = 25,
        //        ReferenceDepth = 25
        //    };

        //    var expectedResults = new AmpliconTestResult()
        //    {
        //        VariantFrequency = 0.5f,
        //        TotalDepth = 50,
        //        VariantDepth = 25,
        //        ReferenceDepth = 25
        //    };

        //    ExecuteTest(test, outputFileName, expectedResults);
        //    test.RequireXCTagToStitch = false;
        //    ExecuteTest(test, outputFileName, expectedResults);

        //    // Note: don't test without stitch reads
        //    // this test would fail because the two reads would detect different variants
        //    // test.StitchPairedReads = false;
        //    // ExecuteTest(test, outputFileName, expectedResults);

        //    test.VariantDepth = 10;
        //    test.ReferenceDepth = 90;
        //    test.RequireXCTagToStitch = true;

        //    expectedResults = new AmpliconTestResult()
        //    {
        //        VariantFrequency = 0.1f,
        //        TotalDepth = 100,
        //        VariantDepth = 10,
        //        ReferenceDepth = 90
        //    };

        //    ExecuteTest(test, outputFileName, expectedResults);
        //    test.RequireXCTagToStitch = false;
        //    ExecuteTest(test, outputFileName, expectedResults);
        //}

        #region Helpers
        private void ExecuteTest(AmpliconTest test, string outputFileName, AmpliconTestResult expectedResult)
        {
            var appOptions = new ApplicationOptions()
            {
                BAMPaths             = new[] { string.Empty },
                GenomePaths          = new[] { _genomeChr19 },
                OutputFolder         = UnitTestPaths.TestDataDirectory,
                OutputgVCFFiles      = true,
                StitchReads          = test.StitchPairedReads,
                RequireXCTagToStitch = test.RequireXCTagToStitch,
                CallMNVs             = true,
                MaxSizeMNV           = 3,
                MaxGapBetweenMNV     = 1
            };

            var vcfOutputPath = Path.Combine(appOptions.OutputFolder, outputFileName);

            File.Delete(vcfOutputPath);

            test.ChrOffset = CHR_OFFSET;

            // test execution
            var factory = new AmpliconTestFactory(test.ReferenceSequenceAbsolute, test.StitchPairedReads);

            factory.ChrOffset = CHR_OFFSET;

            if (test is AmpliconInsertionTest)
            {
                factory.StageInsertion(
                    test.ReadLength,
                    ((AmpliconInsertionTest)test).InsertionSequence,
                    test.VariantPositionAbsolute,
                    test.VariantDepth,
                    test.ReferenceDepth);
            }
            else if (test is AmpliconDeletionTest)
            {
                factory.StageDeletion(
                    test.ReadLength,
                    ((AmpliconDeletionTest)test).NumberDeletedBases,
                    test.VariantPositionAbsolute,
                    test.VariantDepth,
                    test.ReferenceDepth);
            }
            else if (test is AmpliconMnvTest)
            {
                factory.StageMnv(
                    test.ReadLength,
                    ((AmpliconMnvTest)test).ChangedSequence,
                    test.VariantPositionAbsolute,
                    test.VariantDepth,
                    test.ReferenceDepth);
            }

            CallVariantsWithMockData(vcfOutputPath, appOptions, factory);

            var results = GetResults(VcfReader.GetAllVariantsInFile(vcfOutputPath));

            Assert.True(results.Count == 1);

            var result = results[0];

            if (test is AmpliconInsertionTest)
            {
                Assert.True(result.VariantAllele.Substring(1) == ((AmpliconInsertionTest)test).InsertionSequence);
            }
            else if (test is AmpliconDeletionTest)
            {
                Assert.True(result.ReferenceAllele.Length == ((AmpliconDeletionTest)test).NumberDeletedBases + 1);
            }
            else if (test is AmpliconMnvTest)
            {
                Assert.True(result.VariantAllele == ((AmpliconMnvTest)test).ChangedSequence);
            }

            Assert.True(result.Filters == "PASS");
            Assert.True(result.Filters.Split(',').Count() == 1);
            Assert.True(result.Position == test.VariantPositionAbsolute);

            VerifyEqual(result.VariantFrequency, expectedResult.VariantFrequency, 0.1f);
            VerifyEqual(result.TotalDepth, expectedResult.TotalDepth, 1f);
            VerifyEqual(result.VariantDepth, expectedResult.VariantDepth, 1f);
            VerifyEqual(result.ReferenceDepth, expectedResult.ReferenceDepth, 1f);
        }