Exemple #1
0
        public void RecalibrateVcf()
        {
            var vcfPath    = Path.Combine(UnitTestPaths.TestDataDirectory, "Test.vcf");
            var countsPath = Path.Combine(UnitTestPaths.TestDataDirectory, "Expected.counts");

            var outFile      = Path.Combine(UnitTestPaths.TestDataDirectory, "Test.vcf.recal");
            var expectedFile = Path.Combine(UnitTestPaths.TestDataDirectory, "ExpectedTest.vcf.recal");

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

            QualityRecalibration.Recalibrate(vcfPath, countsPath, 30, 0, 66, -1);


            Assert.True(File.Exists(outFile));

            var observedLines = File.ReadAllLines(outFile);
            var expectedLines = File.ReadAllLines(expectedFile);

            Assert.Equal(expectedLines.Length, observedLines.Length);

            for (int i = 0; i < expectedLines.Length; i++)
            {
                Assert.Equal(expectedLines[0], observedLines[0]);
            }
        }
Exemple #2
0
        public void RecalibrateCleanVcf()
        {
            var vcfPath      = Path.Combine(TestPaths.LocalTestDataDirectory, "Test.vcf");
            var countsPath   = Path.Combine(TestPaths.LocalTestDataDirectory, "Clean.counts");
            var outDir       = Path.Combine(TestPaths.LocalScratchDirectory, "RecalibrateDirtyVcf");
            var outFile      = Path.Combine(outDir, "Test.vcf.recal");
            var expectedFile = Path.Combine(TestPaths.LocalTestDataDirectory, "ExpectedTest.vcf.recal");

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

            Logger.OpenLog(TestPaths.LocalScratchDirectory, "RecalibrateCleanVcfLog.txt", true);

            QualityRecalibration.Recalibrate(vcfPath, countsPath, outDir, 30, 0, 66, -1, null);

            Logger.CloseLog();

            //no recalibration should occur for a clean file.
            Assert.True(!File.Exists(outFile));

            //redirect log incase any other thread is logging here.
            var SafeLogDir = TestPaths.LocalScratchDirectory;

            Logger.OpenLog(SafeLogDir, "DefaultLog.txt", true);
            Logger.CloseLog();
        }
Exemple #3
0
        public void RecalibrateDirtyVcf()
        {
            var vcfPath      = Path.Combine(TestPaths.LocalTestDataDirectory, "TestWithArtifacts.vcf");
            var countsPath   = Path.Combine(TestPaths.LocalTestDataDirectory, "Dirty.counts");
            var outDir       = Path.Combine(TestPaths.LocalScratchDirectory, "RecalibrateDirtyVcf");
            var outFile      = Path.Combine(outDir, "TestWithArtifacts.vcf.recal");
            var expectedFile = Path.Combine(TestPaths.LocalTestDataDirectory, "ExpectedDirty.vcf.recal");

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

            Logger.OpenLog(outDir, "RecalibrateDirtyVcfLog.txt", true);

            QualityRecalibration.Recalibrate(vcfPath, countsPath, outDir, 30, 0, 66, -1, "\"-vcf TestWithArtifacts.vcf\"");

            Logger.CloseLog();

            Assert.True(File.Exists(outFile));

            TestUtilities.TestHelper.CompareFiles(outFile, expectedFile);

            //redirect log incase any other thread is logging here.
            var SafeLogDir = TestPaths.LocalScratchDirectory;

            Logger.OpenLog(SafeLogDir, "DefaultLog.txt", true);
            Logger.CloseLog();

            //delete our log
            File.Delete(outFile);
        }
Exemple #4
0
        public void CanSkipVcfLineTests()
        {
            //lines we can skip

            string skip1 = "chr4\t169663557\t.\tT\t.\t100\tPASS\tDP=23\tGT:GQ:AD:DP:VF:NL:SB:NC:US\t0/0:34:22:23:0.043:20:-100.0000:0.0000:0,0,0,0,0,0,0,1,0,0,0,2";
            string skip2 = "chr4\t169663558\t.\tT\tTGGTGAGTCGTCGGCAGCGTCAGATGTGTATAAGAGACAG\t100\tPASS\tDP=71\tGT:GQ:AD:DP:VF:NL:SB:NC:US\t0/1:32:25,46:71:0.648:20:-10.1946:0.0000:0,0,0,0,0,0,0,1,0,0,0,2";
            string skip3 = "chr15\t91310151\t.\tATATCTGA\tATTAGATTC,<M>\t0\tq20;SB;LowVariantFreq;ForcedReport\tDP=34\tGT:GQ:AD:DP:VF\t2/2:10:34,0,0:34:0.000";
            string skip4 = "chr4\t169663673\t.\tAT\tTG\t100\tPASS\tDP=56\tGT:GQ:AD:DP:VF:NL:SB\t1/1:100:6,50:56:0.893:20:-15.2723";

            Assert.Equal(TypeOfUpdateNeeded.NoChangeNeeded, QualityRecalibration.CanSkipVcfLine(skip1));
            Assert.Equal(TypeOfUpdateNeeded.NoChangeNeeded, QualityRecalibration.CanSkipVcfLine(skip2));
            Assert.Equal(TypeOfUpdateNeeded.NoChangeNeeded, QualityRecalibration.CanSkipVcfLine(skip3));
            Assert.Equal(TypeOfUpdateNeeded.NoChangeNeeded, QualityRecalibration.CanSkipVcfLine(skip4));

            //lines we must process

            string do1 = "chr4\t169663557\t.\tT\tG\t100\tPASS\tDP=23\tGT:GQ:AD:DP:VF:NL:SB:NC:US\t0/0:34:22:23:0.043:20:-100.0000:0.0000:0,0,0,0,0,0,0,1,0,0,0,2";
            string do2 = "chr4\t169663558\t.\tT\tA\t100\tPASS\tDP=71\tGT:GQ:AD:DP:VF:NL:SB:NC:US\t0/1:32:25,46:71:0.648:20:-10.1946:0.0000:0,0,0,0,0,0,0,1,0,0,0,2";
            string do3 = "chr15\t91310151\t.\tA\tC\t0\tq20;SB;LowVariantFreq;ForcedReport\tDP=34\tGT:GQ:AD:DP:VF\t2/2:10:34,0,0:34:0.000";
            string do4 = "chr4\t169663673\t.\tA\tG\t100\tPASS\tDP=56\tGT:GQ:AD:DP:VF:NL:SB\t1/1:100:6,50:56:0.893:20:-15.2723";


            Assert.Equal(TypeOfUpdateNeeded.Modify, QualityRecalibration.CanSkipVcfLine(do1));
            Assert.Equal(TypeOfUpdateNeeded.Modify, QualityRecalibration.CanSkipVcfLine(do2));
            Assert.Equal(TypeOfUpdateNeeded.Modify, QualityRecalibration.CanSkipVcfLine(do3));
            Assert.Equal(TypeOfUpdateNeeded.Modify, QualityRecalibration.CanSkipVcfLine(do4));
        }
Exemple #5
0
        public void TestOnADiploidVcf()
        {
            var vcfPath      = Path.Combine(TestPaths.LocalTestDataDirectory, "TestWithDiploidCalls.vcf");
            var countsPath   = Path.Combine(TestPaths.LocalTestDataDirectory, "Dirty.counts");
            var outDir       = Path.Combine(TestPaths.LocalScratchDirectory, "RecalibrateDiploidVcf");
            var outFile      = Path.Combine(outDir, "TestWithDiploidCalls.vcf.recal");
            var expectedFile = Path.Combine(TestPaths.LocalTestDataDirectory, "ExpectedDiploidCalls.vcf.recal");

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

            Logger.OpenLog(outDir, "RecalibrateDiploidCallsLog.txt", true);

            VQROptions options = new VQROptions
            {
                CommandLineArguments = new string[] { "-vcf", "TestWithDiploidCalls.vcf" },
                // FilterQScore = 30, <- set below
                ZFactor   = 0,
                MaxQScore = 66,
                // BaseQNoise = 30, <- set below
                VcfPath         = vcfPath,
                OutputDirectory = outDir,
            };

            options.BamFilterParams.MinimumBaseCallQuality          = 30; //-1
            options.VariantCallingParams.MinimumVariantQScoreFilter = 30;
            options.VariantCallingParams.PloidyModel = PloidyModel.DiploidByThresholding;
            options.VcfWritingParams.AllowMultipleVcfLinesPerLoci    = false;
            options.VariantCallingParams.AmpliconBiasFilterThreshold = null;

            SignatureSorterResultFiles resultFiles = new SignatureSorterResultFiles(countsPath, "foo.txt", "foo.txt");

            QualityRecalibration.Recalibrate(resultFiles, options);


            Logger.CloseLog();

            Assert.True(File.Exists(outFile));

            TestUtilities.TestHelper.CompareFiles(outFile, expectedFile);

            //redirect log incase any other thread is logging here.
            var SafeLogDir = TestPaths.LocalScratchDirectory;

            Logger.OpenLog(SafeLogDir, "DefaultLog.txt", true);
            Logger.CloseLog();

            //delete our log
            File.Delete(outFile);
        }
Exemple #6
0
        public void UpdateVariant()
        {
            var v = SetUpCalledAllele();

            var catalog = new Dictionary <MutationCategory, int>();

            catalog.Add(MutationCategory.CtoA, 12);

            Assert.Equal(666, v.VariantQscore);

            QualityRecalibration.UpdateVariantQScoreAndRefilter(100, 5, catalog, v, MutationCategory.CtoA, false);

            Assert.Equal(12, v.NoiseLevelApplied);
            Assert.Equal(10, v.GenotypeQscore);
            Assert.Equal(10, v.VariantQscore);
            Assert.Equal(0, v.Filters.Count);

            v.VariantQscore = 666;
            QualityRecalibration.UpdateVariantQScoreAndRefilter(100, 30, catalog, v, MutationCategory.CtoA, false);
            Assert.Equal(10, v.VariantQscore);
            Assert.Equal(1, v.Filters.Count);
            Assert.Equal(FilterType.LowVariantQscore, v.Filters[0]);

            v.VariantQscore = 666;
            v.Filters.Add(FilterType.OffTarget);//any filter will do to test, that isnt the q30 one.
            QualityRecalibration.UpdateVariantQScoreAndRefilter(100, 30, catalog, v, MutationCategory.CtoA, false);
            Assert.Equal(10, v.VariantQscore);
            Assert.Equal(2, v.Filters.Count);
            Assert.Equal(FilterType.LowVariantQscore, v.Filters[0]);
            Assert.Equal(FilterType.OffTarget, v.Filters[1]);

            v.VariantQscore = 666;
            v.Filters       = new List <FilterType>()
            {
                FilterType.LowVariantQscore
            };
            QualityRecalibration.UpdateVariantQScoreAndRefilter(100, 30, catalog, v, MutationCategory.CtoA, false);
            Assert.Equal(10, v.VariantQscore);
            Assert.Equal(1, v.Filters.Count);
            Assert.Equal(FilterType.LowVariantQscore, v.Filters[0]);

            v.VariantQscore = 666;
            v.Filters       = new List <FilterType>()
            {
                FilterType.LowVariantQscore, FilterType.OffTarget
            };
            QualityRecalibration.UpdateVariantQScoreAndRefilter(100, 30, catalog, v, MutationCategory.CtoA, false);
            Assert.Equal(10, v.VariantQscore);
            Assert.Equal(FilterType.LowVariantQscore, v.Filters[0]);
            Assert.Equal(FilterType.OffTarget, v.Filters[1]);
        }
Exemple #7
0
        public void HaveInfoToUpdateQ()
        {
            var    v = SetUpCalledAllele(); //(by default, this is reference type)
            double depth;
            double callCount;

            Assert.Equal(true, QualityRecalibration.HaveInfoToUpdateQ(v, out depth, out callCount));

            v.Type = AlleleCategory.Unsupported;
            Assert.Equal(false, QualityRecalibration.HaveInfoToUpdateQ(v, out depth, out callCount));

            v.Type = AlleleCategory.Deletion;
            Assert.Equal(true, QualityRecalibration.HaveInfoToUpdateQ(v, out depth, out callCount));
            Assert.Equal(100, depth);
            Assert.Equal(10, callCount);
        }
Exemple #8
0
        public void InsertNewQ()
        {
            var v = SetUpCalledAllele();

            Assert.Equal(20, v.NoiseLevelApplied);
            Assert.Equal(72, v.GenotypeQscore);
            Assert.Equal(666, v.VariantQscore);

            var catalog = new Dictionary <MutationCategory, int>();

            catalog.Add(MutationCategory.CtoA, 12);

            QualityRecalibration.InsertNewQ(catalog, v, MutationCategory.CtoA, 42, true);

            Assert.Equal(12, v.NoiseLevelApplied);
            Assert.Equal(42, v.GenotypeQscore);
            Assert.Equal(42, v.VariantQscore);
        }
Exemple #9
0
        public void RecalibrateCleanVcf()
        {
            var vcfPath      = Path.Combine(TestPaths.LocalTestDataDirectory, "Test.vcf");
            var countsPath   = Path.Combine(TestPaths.LocalTestDataDirectory, "Clean.counts");
            var outDir       = Path.Combine(TestPaths.LocalScratchDirectory, "RecalibrateDirtyVcf");
            var outFile      = Path.Combine(outDir, "Test.vcf.recal");
            var expectedFile = Path.Combine(TestPaths.LocalTestDataDirectory, "ExpectedTest.vcf.recal");

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

            Logger.OpenLog(TestPaths.LocalScratchDirectory, "RecalibrateCleanVcfLog.txt", true);
            VQROptions options = new VQROptions
            {
                CommandLineArguments = null,
                //          FilterQScore = -1,
                ZFactor   = 0,
                MaxQScore = 66,
                //          BaseQNoise = 30,
                OutputDirectory = outDir
            };

            options.VariantCallingParams.MinimumVariantQScoreFilter = -1;
            options.BamFilterParams.MinimumBaseCallQuality          = 30;
            SignatureSorterResultFiles resultFiles = new SignatureSorterResultFiles(countsPath, "foo.txt", "foo.txt");

            QualityRecalibration.Recalibrate(resultFiles, options);

            Logger.CloseLog();

            //no recalibration should occur for a clean file.
            Assert.True(!File.Exists(outFile));

            //redirect log incase any other thread is logging here.
            var SafeLogDir = TestPaths.LocalScratchDirectory;

            Logger.OpenLog(SafeLogDir, "DefaultLog.txt", true);
            Logger.CloseLog();
        }
Exemple #10
0
        public void InsertNewQ()
        {
            var v = SetUpVariant();

            Assert.Equal("20", v.Genotypes[0]["NL"]);
            Assert.Equal("72", v.Genotypes[0]["GQ"]);
            Assert.Equal("34", v.Genotypes[0]["GQX"]);
            Assert.Equal(666, v.Quality);


            var catalog = new Dictionary <MutationCategory, int>();

            catalog.Add(MutationCategory.CtoA, 12);

            QualityRecalibration.InsertNewQ(catalog, v, MutationCategory.CtoA, 42);

            Assert.Equal("12", v.Genotypes[0]["NL"]);
            Assert.Equal("42", v.Genotypes[0]["GQ"]);
            Assert.Equal("42", v.Genotypes[0]["GQX"]);
            Assert.Equal(42, v.Quality);
        }
Exemple #11
0
        public void UpdateVariant()
        {
            var v       = SetUpVariant();
            var catalog = new Dictionary <MutationCategory, int>();

            catalog.Add(MutationCategory.CtoA, 12);

            Assert.Equal(666, v.Quality);

            QualityRecalibration.UpdateVariant(100, 5, catalog, v, MutationCategory.CtoA);

            Assert.Equal("12", v.Genotypes[0]["NL"]);
            Assert.Equal("10", v.Genotypes[0]["GQ"]);
            Assert.Equal("10", v.Genotypes[0]["GQX"]);
            Assert.Equal(10, v.Quality);
            Assert.Equal("PASS", v.Filters);

            v.Quality = 666;
            QualityRecalibration.UpdateVariant(100, 30, catalog, v, MutationCategory.CtoA);
            Assert.Equal(10, v.Quality);
            Assert.Equal("q30", v.Filters);

            v.Quality = 666;
            v.Filters = "Snoopy";
            QualityRecalibration.UpdateVariant(100, 30, catalog, v, MutationCategory.CtoA);
            Assert.Equal(10, v.Quality);
            Assert.Equal("Snoopy;q30", v.Filters);

            v.Quality = 666;
            v.Filters = "q30";
            QualityRecalibration.UpdateVariant(100, 30, catalog, v, MutationCategory.CtoA);
            Assert.Equal(10, v.Quality);
            Assert.Equal("q30", v.Filters);

            v.Quality = 666;
            v.Filters = "Snoopy;q30";
            QualityRecalibration.UpdateVariant(100, 30, catalog, v, MutationCategory.CtoA);
            Assert.Equal(10, v.Quality);
            Assert.Equal("Snoopy;q30", v.Filters);
        }
Exemple #12
0
        public void HaveInfoToUpdateQ()
        {
            var v = new VcfVariant();
            int depth;
            int callCount;

            Assert.Equal(false, QualityRecalibration.HaveInfoToUpdateQ(v, out depth, out callCount));

            v.Genotypes = new List <Dictionary <string, string> >()
            {
                new Dictionary <string, string>()
            };
            v.InfoFields = new Dictionary <string, string>();

            v.InfoFields.Add("PX", "42");
            v.Genotypes[0].Add("blah", "??");
            Assert.Equal(false, QualityRecalibration.HaveInfoToUpdateQ(v, out depth, out callCount));

            v.InfoFields.Add("DP", "100");
            v.Genotypes[0].Add("AD", "90,10");
            Assert.Equal(true, QualityRecalibration.HaveInfoToUpdateQ(v, out depth, out callCount));
            Assert.Equal(100, depth);
            Assert.Equal(10, callCount);
        }