コード例 #1
0
        private static BiasResults GetProbePoolBiasScore(VariantComparisonCase Case, CalledAllele Consensus,
                                                         float ProbePoolBiasThreshold, VariantCallingParameters variantCallingParameters, int AltCountA, int AltCountB, int DepthA, int DepthB, Genotype Genotype, bool AltChangeToRef)
        {
            double      ProbePoolPScore        = 0;    //no bias;
            double      ProbePoolGATKBiasScore = -100; //no bias;
            int         NoiseLevel             = Consensus.NoiseLevelApplied;
            BiasResults PB = new BiasResults();

            if ((AltChangeToRef) || (Case == VariantComparisonCase.AgreedOnReference))
            {
                PB.GATKBiasScore = ProbePoolGATKBiasScore;
                PB.BiasScore     = ProbePoolPScore;
                return(PB);
            }

            if ((Case == VariantComparisonCase.OneReferenceOneAlternate) ||
                (Case == VariantComparisonCase.CanNotCombine))
            {
                Consensus.Filters.Add(FilterType.PoolBias);
                PB.GATKBiasScore = 0;
                PB.BiasScore     = 1;
                return(PB);
            }

            if (Case == VariantComparisonCase.AgreedOnAlternate)
            {
                int[] supportByPool = new int[]
                {
                    AltCountA, AltCountB, 0
                };
                int[] covByPool = new int[]
                {
                    DepthA, DepthB, 0
                };


                BiasResults ProbePoolBiasResults =
                    StrandBiasCalculator.CalculateStrandBiasResults(
                        covByPool, supportByPool,
                        NoiseLevel, variantCallingParameters.MinimumFrequency, ProbePoolBiasThreshold, StrandBiasModel.Extended);

                ProbePoolGATKBiasScore = Math.Min(0, ProbePoolBiasResults.GATKBiasScore);        //just cap it at upperbound 0, dont go higher.
                ProbePoolGATKBiasScore = Math.Max(-100, ProbePoolGATKBiasScore);                 //just cap it at lowerbound -100, dont go higher.

                ProbePoolPScore = Math.Min(1, ProbePoolBiasResults.BiasScore);

                if (!ProbePoolBiasResults.BiasAcceptable)
                {
                    Consensus.Filters.Add(FilterType.PoolBias);
                }
            }

            PB.GATKBiasScore = ProbePoolGATKBiasScore;
            PB.BiasScore     = ProbePoolPScore;
            return(PB);
        }
コード例 #2
0
        /// <summary>
        /// Combine two variants.
        /// Variant B can be null.
        /// We never try to combine two different variant alleles.
        /// </summary>
        /// <param name="VariantsA"></param>
        /// <param name="VariantsB"></param>
        /// <param name="ComparisonCase"></param>
        /// <param name="Consensus"></param>
        public AggregateAllele CombineVariants(CalledAllele VariantA, CalledAllele VariantB,
                                               VariantComparisonCase ComparisonCase)
        {
            SampleAggregationParameters SampleAggregationOptions = _options.SampleAggregationParameters;
            var Consensus = new AggregateAllele(new List <CalledAllele> {
                VariantA, VariantB
            });
            int DepthA = 0;
            int DepthB = 0;

            //(A) set the reference data.
            //this should be the same for both.
            if (VariantA != null)
            {
                DoDefensiveGenotyping(VariantA);
                Consensus.Chromosome        = VariantA.Chromosome;
                Consensus.ReferencePosition = VariantA.ReferencePosition;
                Consensus.ReferenceAllele   = VariantA.ReferenceAllele;
                DepthA = VariantA.TotalCoverage;
            }
            if (VariantB != null)
            {
                DoDefensiveGenotyping(VariantB);
                Consensus.Chromosome        = VariantB.Chromosome;
                Consensus.ReferencePosition = VariantB.ReferencePosition;
                Consensus.ReferenceAllele   = VariantB.ReferenceAllele;
                DepthB = VariantB.TotalCoverage;
            }

            //normally the reference data is the same for both, no matter what the case.
            //but if we have one deletion and one not, we might have different ref alleles.
            //So we need to get this right.
            Consensus.ReferenceAllele = CombineReferenceAlleles(VariantA, VariantB, ComparisonCase);

            // (B) set the Alternate data
            Consensus.AlternateAllele = CombineVariantAlleles(VariantA, VariantB, ComparisonCase);

            // (C) set filters, etc.
            Consensus.Filters = CombineFilters(VariantA, VariantB);

            // (E) set GT data, includes calculating the probe-pool bias and quality scores
            RecalculateScoring(VariantA, VariantB, ComparisonCase, Consensus, SampleAggregationOptions, _options.VariantCallingParams);

            return(Consensus);
        }
コード例 #3
0
        private static void CheckSimpleCombinations(
            CalledAllele VarA, CalledAllele VarB, ConsensusBuilder cb,
            Genotype ExpectedGT, string ExpectedAlt,
            VariantComparisonCase ComparisonCase)
        {
            var AandB               = cb.CombineVariants(VarA, VarB, ComparisonCase);
            var BandA               = cb.CombineVariants(VarB, VarA, ComparisonCase);
            var AandNull            = cb.CombineVariants(VarA, null, VariantComparisonCase.CanNotCombine);
            var NullAndB            = cb.CombineVariants(null, VarB, VariantComparisonCase.CanNotCombine);
            int ExpectedAlleleCount = VarA.AlleleSupport + VarB.AlleleSupport;

            if (ComparisonCase == VariantComparisonCase.OneReferenceOneAlternate)
            {
                //for this test, we presume we are calling alternate.
                ExpectedAlleleCount = (VarA.Type == AlleleCategory.Snv) ? VarA.AlleleSupport : VarB.AlleleSupport;
            }

            //check alt-and-nocalls

            Assert.Equal(ExpectedGT, AandB.Genotype);
            Assert.Equal(VarA.ReferenceAllele, AandB.ReferenceAllele);
            Assert.Equal(ExpectedAlt, AandB.AlternateAllele);
            Assert.Equal(VarA.TotalCoverage + VarB.TotalCoverage, AandB.TotalCoverage);
            Assert.Equal(ExpectedAlleleCount, AandB.AlleleSupport);

            Assert.Equal(ExpectedGT, BandA.Genotype);
            Assert.Equal(VarA.ReferenceAllele, BandA.ReferenceAllele);
            Assert.Equal(ExpectedAlt, BandA.AlternateAllele);
            Assert.Equal(VarA.TotalCoverage + VarB.TotalCoverage, BandA.TotalCoverage);
            Assert.Equal(ExpectedAlleleCount, BandA.AlleleSupport);

            Assert.Equal(ConsensusBuilder.DoDefensiveGenotyping(VarA), AandNull.Genotype);
            Assert.Equal(VarA.ReferenceAllele, AandNull.ReferenceAllele);
            Assert.Equal(VarA.AlternateAllele, AandNull.AlternateAllele);
            Assert.Equal(VarA.TotalCoverage, AandNull.TotalCoverage);
            Assert.Equal(VarA.AlleleSupport, AandNull.AlleleSupport);

            Assert.Equal(ConsensusBuilder.DoDefensiveGenotyping(VarB), NullAndB.Genotype);
            Assert.Equal(VarB.ReferenceAllele, NullAndB.ReferenceAllele);
            Assert.Equal(VarB.AlternateAllele, NullAndB.AlternateAllele);
            Assert.Equal(VarB.TotalCoverage, NullAndB.TotalCoverage);
            Assert.Equal(VarB.AlleleSupport, NullAndB.AlleleSupport);
        }
コード例 #4
0
ファイル: VennVcf.cs プロジェクト: arnoldliaoILMN/Pisces
        private void WriteVarsToVennFiles(VariantComparisonCase ComparisonCase,
                                          CalledAllele VariantA, CalledAllele VariantB)
        {
            AggregateAllele AggregateA = AggregateAllele.SafeCopy(VariantA, new List <CalledAllele> {
                VariantA, VariantB
            });
            AggregateAllele AggregateB = AggregateAllele.SafeCopy(VariantB, new List <CalledAllele> {
                VariantB, VariantA
            });

            if (ComparisonCase == VariantComparisonCase.AgreedOnAlternate)
            {
                _vennDiagramWriters["AandB"].Write(new List <AggregateAllele>()
                {
                    AggregateA
                });
                _vennDiagramWriters["BandA"].Write(new List <AggregateAllele>()
                {
                    AggregateB
                });
            }

            if ((ComparisonCase == VariantComparisonCase.OneReferenceOneAlternate) ||
                (ComparisonCase == VariantComparisonCase.CanNotCombine))
            {
                if ((VariantA != null) && (VariantA.Type != Pisces.Domain.Types.AlleleCategory.Reference))
                {
                    _vennDiagramWriters["AnotB"].Write(new List <CalledAllele>()
                    {
                        VariantA
                    });
                }

                if ((VariantB != null) && (VariantB.Type != Pisces.Domain.Types.AlleleCategory.Reference))
                {
                    _vennDiagramWriters["BnotA"].Write(new List <CalledAllele>()
                    {
                        VariantB
                    });
                }
            }
        }
コード例 #5
0
ファイル: VennProcessorTests.cs プロジェクト: tamsen/Pisces
        public void VennVcf_CombineTwoPoolVariants_Qscore_DiffentNL_Test()
        {
            //chr3	41266161	.	A	G	30	PASS	DP=3067	GT:GQ:AD:VF:NL:SB	0/1:30:3005,54:0.0176:35:-100.0000
            CalledAllele VarA = new CalledAllele()
            {
                Chromosome        = "chr3",
                ReferencePosition = 41266161,
                TotalCoverage     = 3067,
                Genotype          = Pisces.Domain.Types.Genotype.HeterozygousAltRef,
                VariantQscore     = 30,
                GenotypeQscore    = 30,
                AlleleSupport     = 54,
                ReferenceSupport  = 3005,
                NoiseLevelApplied = 35,
                StrandBiasResults = new Pisces.Domain.Models.BiasResults()
                {
                    GATKBiasScore = -100.0000
                },
                ReferenceAllele = "A",
                AlternateAllele = "G",
                Type            = Pisces.Domain.Types.AlleleCategory.Snv
            };


            ///chr3	41266161	.	A	.	75	PASS	DP=3795	GT:GQ:AD:VF:NL:SB	0/0:75:3780:0.0040:2:-100.0000
            CalledAllele VarB = new CalledAllele()
            {
                Chromosome        = "chr3",
                ReferencePosition = 41266161,
                TotalCoverage     = 3795,
                Genotype          = Pisces.Domain.Types.Genotype.HomozygousRef,
                VariantQscore     = 75,
                GenotypeQscore    = 75,
                AlleleSupport     = 3780,
                ReferenceSupport  = 3780,
                NoiseLevelApplied = 2,
                StrandBiasResults = new Pisces.Domain.Models.BiasResults()
                {
                    GATKBiasScore = -100.0000
                },
                ReferenceAllele = "A",
                AlternateAllele = ".",
                Type            = Pisces.Domain.Types.AlleleCategory.Reference
            };



            //old answer
            //chr3	41266161	.	A	.	100.00	PASS	DP=6862;cosmic=COSM1423020,COSM1423021;EVS=0|69.0|6503;phastCons	GT:GQ:AD:VF:NL:SB:PB:GQX	0/0:100:6785:0.0079:35:-100:-100.0000:100

            SampleAggregationParameters SampleAggregationOptions = new SampleAggregationParameters();

            SampleAggregationOptions.ProbePoolBiasThreshold = 0.5f;
            SampleAggregationOptions.HowToCombineQScore     = SampleAggregationParameters.CombineQScoreMethod.CombinePoolsAndReCalculate;

            _basicOptions.BamFilterParams.MinimumBaseCallQuality      = 20;
            _basicOptions.VariantCallingParams.MinimumFrequency       = 0.01f;
            _basicOptions.VariantCallingParams.MinimumFrequencyFilter = 0.03f;
            _basicOptions.SampleAggregationParameters = SampleAggregationOptions;

            string consensusOut = Path.Combine(_TestDataPath, "ConsensusOut.vcf");
            VariantComparisonCase ComparisonCase   = VennProcessor.GetComparisonCase(VarA, VarB);
            ConsensusBuilder      consensusBuilder = new ConsensusBuilder(consensusOut, _basicOptions);
            AggregateAllele       consensus        = consensusBuilder.CombineVariants(VarA, VarB, ComparisonCase);

            Console.WriteLine(consensus.ToString());

            double expectedNoiseLevel = MathOperations.PtoQ(
                (MathOperations.QtoP(35) + MathOperations.QtoP(2)) / (2.0)); // 5

            //GT:GQ:AD:VF:NL:SB:PB:GQX	0/0:100:6785:0.0079:35:-100:-100.0000:100
            Assert.NotNull(consensus);
            Assert.Equal(consensus.VariantQscore, 100);
            Assert.Equal(consensus.ReferenceAllele, "A");
            Assert.Equal(consensus.AlternateAllele, ".");
            Assert.Equal(consensus.Genotype, Pisces.Domain.Types.Genotype.HomozygousRef);
            Assert.Equal(consensus.TotalCoverage, 6862);
            Assert.Equal(consensus.ReferenceSupport, 6785);
            Assert.Equal(consensus.AlleleSupport, 6785);
            Assert.Equal(consensus.GenotypeQscore, 100);
            Assert.Equal(consensus.Frequency, 0.98877877f);
            Assert.Equal(consensus.NoiseLevelApplied, ((int)expectedNoiseLevel));
            Assert.Equal(consensus.NoiseLevelApplied, 5);
            Assert.Equal(consensus.StrandBiasResults.GATKBiasScore, -100);
            Assert.Equal(consensus.PoolBiasResults.GATKBiasScore, -100.0000);


            //now check, we take the min NL score if we are taking the min Q score.
            // (in this case of combined alt+ref -> ref, the q score will still need to be recalculated.
            //just with the MIN NL.
            SampleAggregationOptions.HowToCombineQScore = SampleAggregationParameters.CombineQScoreMethod.TakeMin;
            ComparisonCase = VennProcessor.GetComparisonCase(VarA, VarB);
            consensus      = consensusBuilder.CombineVariants(VarA, VarB, ComparisonCase);
            Assert.Equal(consensus.NoiseLevelApplied, 2);
            Assert.Equal(consensus.VariantQscore, 100);


            //ok, now sanity check we dont barf if either input is null:
            ComparisonCase = VennProcessor.GetComparisonCase(VarA, null);
            consensus      = consensusBuilder.CombineVariants(VarA, null, ComparisonCase);
            Assert.Equal(consensus.NoiseLevelApplied, 35);
            Assert.Equal(consensus.VariantQscore, 100);

            ComparisonCase = VennProcessor.GetComparisonCase(null, VarB);
            consensus      = consensusBuilder.CombineVariants(null, VarB, ComparisonCase);
            Assert.Equal(consensus.NoiseLevelApplied, 2);
            Assert.Equal(consensus.VariantQscore, 100);

            //ok, lets check this again, for the PoolQScores option.
            //sanity check we dont barf if either input is null:
            SampleAggregationOptions.HowToCombineQScore = SampleAggregationParameters.CombineQScoreMethod.CombinePoolsAndReCalculate;
            ComparisonCase = VennProcessor.GetComparisonCase(VarA, null);
            consensus      = consensusBuilder.CombineVariants(VarA, null, ComparisonCase);
            Assert.Equal(consensus.NoiseLevelApplied, 35);
            Assert.Equal(consensus.VariantQscore, 100);//low freq variant -> nocall. note, qscore would be 41 if NL = 20.

            ComparisonCase = VennProcessor.GetComparisonCase(null, VarB);
            consensus      = consensusBuilder.CombineVariants(null, VarB, ComparisonCase);
            Assert.Equal(consensus.NoiseLevelApplied, 2);
            Assert.Equal(consensus.VariantQscore, 100); //sold ref
        }
コード例 #6
0
ファイル: VennProcessorTests.cs プロジェクト: tamsen/Pisces
        public void VennVcf_CombineTwoPoolVariants_Qscore_Test()
        {
            //Var A, kdot-43_S3.genome.vcf
            //chr3	41266161	.	A	G	30	PASS	DP=3067	GT:GQ:AD:VF:NL:SB	0/1:30:3005,54:0.0176:35:-100.0000
            CalledAllele VarA = new CalledAllele();

            VarA.Chromosome        = "chr3";
            VarA.ReferencePosition = 41266161;
            VarA.TotalCoverage     = 3067;
            VarA.Genotype          = Pisces.Domain.Types.Genotype.HeterozygousAltRef;
            VarA.GenotypeQscore    = 30;
            VarA.AlleleSupport     = 54;
            VarA.ReferenceSupport  = 3005;
            //              "VF", "0.0176"
            VarA.NoiseLevelApplied = 35;
            VarA.StrandBiasResults = new Pisces.Domain.Models.BiasResults()
            {
                GATKBiasScore = -100
            };
            VarA.ReferenceAllele = "A";
            VarA.AlternateAllele = "G";
            VarA.Filters         = new List <Pisces.Domain.Types.FilterType>();
            VarA.VariantQscore   = 30;
            VarA.Type            = Pisces.Domain.Types.AlleleCategory.Snv;

            //Var B, kdot-43_S4.genome.vcf
            //chr3	41266161	.	A	.	75	PASS	DP=3795	GT:GQ:AD:VF:NL:SB	0/0:75:3780:0.0040:35:-100.0000
            CalledAllele VarB = new CalledAllele();

            VarB.Chromosome        = "chr3";
            VarB.ReferencePosition = 41266161;
            VarB.TotalCoverage     = 3795;
            VarB.Genotype          = Pisces.Domain.Types.Genotype.HomozygousRef;
            VarB.GenotypeQscore    = 75;
            VarB.AlleleSupport     = 3780;
            VarB.ReferenceSupport  = 3780;
            //              "VF", "0.0040"
            VarB.NoiseLevelApplied = 35;
            VarB.StrandBiasResults = new Pisces.Domain.Models.BiasResults()
            {
                GATKBiasScore = -100
            };
            VarB.ReferenceAllele = "A";
            VarB.AlternateAllele = ".";
            VarB.Filters         = new List <Pisces.Domain.Types.FilterType>();
            VarB.VariantQscore   = 75;
            VarB.Type            = Pisces.Domain.Types.AlleleCategory.Reference;

            //old answer
            //chr3	41266161	.	A	.	100.00	PASS	DP=6862;cosmic=COSM1423020,COSM1423021;EVS=0|69.0|6503;phastCons	GT:GQ:AD:VF:NL:SB:PB:GQX	0/0:100:6785:0.0079:35:-100:-100.0000:100

            VennVcfOptions parameters = new VennVcfOptions();

            parameters.VariantCallingParams.MinimumFrequencyFilter        = 0.03f;
            parameters.VariantCallingParams.MinimumFrequency              = 0.01f;
            parameters.BamFilterParams.MinimumBaseCallQuality             = 20;
            parameters.SampleAggregationParameters.ProbePoolBiasThreshold = 0.5f;
            parameters.SampleAggregationParameters.HowToCombineQScore     = SampleAggregationParameters.CombineQScoreMethod.TakeMin;

            VariantComparisonCase ComparisonCase   = VennProcessor.GetComparisonCase(VarA, VarB);
            ConsensusBuilder      consensusBuilder = new ConsensusBuilder("", parameters);
            AggregateAllele       consensus        = consensusBuilder.CombineVariants(VarA, VarB, ComparisonCase);

            //GT:GQ:AD:VF:NL:SB:PB:GQX	0/0:100:6785:0.0079:35:-100:-100.0000:100
            Assert.NotNull(consensus);
            Assert.Equal(consensus.VariantQscore, 100);
            Assert.Equal(consensus.GenotypeQscore, 100);
            Assert.Equal(consensus.ReferenceAllele, "A");
            Assert.Equal(consensus.AlternateAllele, ".");
            Assert.Equal(consensus.Genotype, Pisces.Domain.Types.Genotype.HomozygousRef);
            Assert.Equal(consensus.GenotypeQscore, 100);
            Assert.Equal(consensus.AlleleSupport, 6785);
            Assert.Equal(consensus.ReferenceSupport, 6785);
            Assert.Equal(consensus.TotalCoverage, 6862);
            Assert.Equal(consensus.Frequency, 0.98877, 4);
            Assert.Equal(consensus.NoiseLevelApplied, 35);
            Assert.Equal(consensus.StrandBiasResults.GATKBiasScore, -100);
            Assert.Equal(consensus.PoolBiasResults.GATKBiasScore, -100);
        }
コード例 #7
0
ファイル: VennProcessorTests.cs プロジェクト: tamsen/Pisces
        public void VennVcf_CombineTwoPoolVariants_RulesAthroughD_Tests()
        {
            var outDir      = TestPaths.LocalScratchDirectory;
            var VcfPathRoot = _TestDataPath;

            string OutputPath = Path.Combine(outDir, "outEandF.vcf");

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

            VennVcfOptions parameters = new VennVcfOptions();

            parameters.VariantCallingParams.MinimumFrequencyFilter = 0.03f;
            parameters.VariantCallingParams.MinimumFrequency       = 0.01f;
            parameters.ConsensusFileName = OutputPath;

            string VcfPath_PoolA = Path.Combine(VcfPathRoot, "09H-03403-MT1-1_S7.genome.vcf");
            var    PoolAVariants = (AlleleReader.GetAllVariantsInFile(VcfPath_PoolA)).ToList();

            string VcfPath_PoolB = Path.Combine(VcfPathRoot, "09H-03403-MT1-1_S8.genome.vcf");
            var    PoolBVariants = (AlleleReader.GetAllVariantsInFile(VcfPath_PoolB)).ToList();

            CalledAllele VariantA = PoolAVariants[0];
            CalledAllele VariantB = PoolBVariants[0];

            List <CalledAllele[]> pairs = VennProcessor.SelectPairs(
                new List <CalledAllele>()
            {
                VariantA
            },
                new List <CalledAllele>
            {
                VariantB
            });

            VariantComparisonCase ComparisonCase   = VennProcessor.GetComparisonCase(pairs[0][0], pairs[0][1]);
            ConsensusBuilder      consensusBuilder = new ConsensusBuilder("", parameters);
            CalledAllele          Consensus        = consensusBuilder.CombineVariants(
                VariantA, VariantB, ComparisonCase);

            //Rule "A" test
            //A	if combined VF<1% and less than 2.6% in each pool, call REF
            //(note, we were Alt in one pool and ref in another)

            Assert.Equal(VariantA.Genotype, Pisces.Domain.Types.Genotype.HomozygousRef);
            Assert.Equal(VariantA.Frequency, 0.9979, 4);
            Assert.Equal(VariantA.VariantQscore, 100);
            Assert.Equal(VariantA.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(VariantB.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantB.Frequency, 0.0173, 4);
            Assert.Equal(VariantB.VariantQscore, 100);
            Assert.Equal(VariantB.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(ComparisonCase, VariantComparisonCase.OneReferenceOneAlternate);
            Assert.Equal(Consensus.Genotype, Pisces.Domain.Types.Genotype.HomozygousRef);
            Assert.Equal(Consensus.Frequency, 0.9907, 4);
            Assert.Equal(Consensus.VariantQscore, 100);
            Assert.Equal(Consensus.Filters, new List <Pisces.Domain.Types.FilterType> {
            });                                                                            //<-low VF tag will NOT added by post-processing b/c is ref call

            //B	if combined VF<1% and more than 2.6% in one pool, call NO CALL

            VariantA = PoolAVariants[1];
            VariantB = PoolBVariants[1];

            ComparisonCase = VennProcessor.GetComparisonCase(VariantA, VariantB);
            Consensus      = consensusBuilder.CombineVariants(
                VariantA, VariantB, ComparisonCase);

            Assert.Equal(VariantA.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantA.Frequency, 0.0776, 4);
            Assert.Equal(VariantA.VariantQscore, 100);
            Assert.Equal(VariantA.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(VariantB.Genotype, Pisces.Domain.Types.Genotype.HomozygousRef);
            Assert.Equal(VariantB.Frequency, 0.9989, 4);
            Assert.Equal(VariantB.VariantQscore, 100);
            Assert.Equal(VariantB.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(ComparisonCase, VariantComparisonCase.OneReferenceOneAlternate);
            Assert.Equal(Consensus.Genotype, Pisces.Domain.Types.Genotype.AltLikeNoCall);
            Assert.Equal(Consensus.Frequency, 0.0070, 4);
            Assert.Equal(Consensus.VariantQscore, 0);
            Assert.Equal(Consensus.Filters, new List <Pisces.Domain.Types.FilterType>
            {
                Pisces.Domain.Types.FilterType.PoolBias
            });                                          //<-low VF tag will also get added by post-processing

            //Rule "Ca" test
            //C-a	if combined 1%<VF<2.6%
            // and more than 2.6% in one pool and less than 1% in the other, call NO CALL w/PB

            VariantA = PoolAVariants[2];
            VariantB = PoolBVariants[2];

            ComparisonCase = VennProcessor.GetComparisonCase(VariantA, VariantB);
            Consensus      = consensusBuilder.CombineVariants(
                VariantA, VariantB, ComparisonCase);

            Assert.Equal(VariantA.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantA.Frequency, 0.0367, 4);
            Assert.Equal(VariantA.VariantQscore, 100);
            Assert.Equal(VariantA.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(VariantB.Genotype, Pisces.Domain.Types.Genotype.HomozygousRef);
            Assert.Equal(VariantB.Frequency, 0.9976, 4);
            Assert.Equal(VariantB.VariantQscore, 100);
            Assert.Equal(VariantB.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(ComparisonCase, VariantComparisonCase.OneReferenceOneAlternate);
            Assert.Equal(Consensus.Genotype, Pisces.Domain.Types.Genotype.AltLikeNoCall);
            Assert.Equal(Consensus.Frequency, 0.0117, 4);
            Assert.Equal(Consensus.VariantQscore, 23);
            Assert.Equal(Consensus.Filters, new List <Pisces.Domain.Types.FilterType> {
                Pisces.Domain.Types.FilterType.PoolBias
            });
            //Rule "Cb" test
            //C-a	if combined 1%<VF<2.6%
            // and more than 2.6% in one pool and between 1% and 2.6% in the other, call NO CALL w/ no PB

            VariantA = PoolAVariants[3];
            VariantB = PoolBVariants[3];

            ComparisonCase = VennProcessor.GetComparisonCase(VariantA, VariantB);
            Consensus      = consensusBuilder.CombineVariants(
                VariantA, VariantB, ComparisonCase);

            Assert.Equal(VariantA.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantA.Frequency, 0.01725, 4);
            Assert.Equal(VariantA.VariantQscore, 100);
            Assert.Equal(VariantA.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(VariantB.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantB.Frequency, 0.03667, 4);
            Assert.Equal(VariantB.VariantQscore, 100);
            Assert.Equal(VariantB.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(ComparisonCase, VariantComparisonCase.AgreedOnAlternate);
            Assert.Equal(Consensus.Genotype, Pisces.Domain.Types.Genotype.AltLikeNoCall);
            Assert.Equal(Consensus.Frequency, 0.02347, 4);
            Assert.Equal(Consensus.VariantQscore, 100);
            Assert.Equal(Consensus.Filters, new List <Pisces.Domain.Types.FilterType> {
            });                                                                            //<-low VF tag will also get added by post-processing

            //Rule "D" test
            //D	if combined VF>=2.6% call VARIANT (PB if only present in one pool, using 1% as the cutoff)

            VariantA = PoolAVariants[4];
            VariantB = PoolBVariants[4];

            ComparisonCase = VennProcessor.GetComparisonCase(VariantA, VariantB);
            Consensus      = consensusBuilder.CombineVariants(
                VariantA, VariantB, ComparisonCase);

            Assert.Equal(VariantA.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantA.Frequency, 0.2509, 4);
            Assert.Equal(VariantA.VariantQscore, 100);
            Assert.Equal(VariantA.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(VariantB.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(VariantB.Frequency, 0.0367, 4);
            Assert.Equal(VariantB.VariantQscore, 100);
            Assert.Equal(VariantB.Filters, new List <Pisces.Domain.Types.FilterType> {
            });

            Assert.Equal(ComparisonCase, VariantComparisonCase.AgreedOnAlternate);
            Assert.Equal(Consensus.Genotype, Pisces.Domain.Types.Genotype.HeterozygousAltRef);
            Assert.Equal(Consensus.Frequency, 0.1716, 4);
            Assert.Equal(Consensus.VariantQscore, 100);
            Assert.Equal(Consensus.Filters, new List <Pisces.Domain.Types.FilterType> {
            });                                                                            //<-low VF tag will also get set by post processor
        }
コード例 #8
0
        private static Genotype GetGenotype(CalledAllele VariantA, CalledAllele VariantB, VariantComparisonCase Case,
                                            int TotalDepth, double VarFrequency, double VarFrequencyA, double VarFrequencyB, SampleAggregationParameters SampleAggregationOptions, VariantCallingParameters variantCallingParameters)
        {
            var gtA    = Genotype.RefLikeNoCall;
            var gtB    = Genotype.RefLikeNoCall;
            var tempGT = Genotype.RefLikeNoCall;

            if (VariantB != null)
            {
                gtB = VariantB.Genotype;
            }
            if (VariantA != null)
            {
                gtA = VariantA.Genotype;
            }

            //cases:  {0/0 , 0/1,  1/1, ./.} , choose 2.

            //if (A == B)  GTString  = A;

            bool RefPresent = ((VariantA != null && VariantA.HasARefAllele) || (VariantB != null && VariantB.HasARefAllele));
            bool AltPresent = ((VariantA != null && VariantA.HasAnAltAllele) || (VariantB != null && VariantB.HasAnAltAllele));

            if (!AltPresent && RefPresent)
            {
                tempGT = Genotype.HomozygousRef;
            }
            else if (AltPresent && RefPresent)
            {
                tempGT = Genotype.HeterozygousAltRef;
            }
            else if (AltPresent && !RefPresent)
            {
                tempGT = Genotype.HomozygousAlt;

                //todo, expand to cover nocalls and heterozygous calls.
            }
            else //(no alt and no reference detected.)
            {
                tempGT = Genotype.RefLikeNoCall;
            }

            //if its  no call, thats fine. we are done
            if (tempGT == Genotype.RefLikeNoCall)
            {
                return(tempGT);
            }

            //if the merged GT implies a variant call,
            //it has to pass some minimal criteria, or it gets
            //re-classified as a ref type or a no-call.
            //So. now, check the combined result passed some minimum criteria:

            //First, never call it a Variant if the combined freq
            //is smaller than the reporting threshold.
            //If the freq is low, we should call "0/0" or "./.".  , but not "1/1" or "0/1"
            //So change any "0/1"s or "1/1"s over to "./.".

            //if we would have called a variant... but...
            if (Case != VariantComparisonCase.AgreedOnReference)
            {
                // ifcombined freq <1% and both per-pool freq <3% -> 0/0
                // ifcombined freq <1% and a per-pool freq >3% -> ./.
                // ifcombined freq >1% and <3%      -> ./.

                //if combined freq <1%
                if (VarFrequency < variantCallingParameters.MinimumFrequency)
                {
                    //if its < 3% in both pools but still <1% overall
                    if ((VarFrequencyA < variantCallingParameters.MinimumFrequencyFilter) &&
                        (VarFrequencyB < variantCallingParameters.MinimumFrequencyFilter))
                    {
                        tempGT = Genotype.HomozygousRef;
                    }
                    else                     //if its > 3% in at least one pool but still <1% overall
                    {
                        tempGT = Genotype.AltLikeNoCall;
                    }
                }
                else if (VarFrequency < variantCallingParameters.MinimumFrequencyFilter)
                {//if combined freq more than 1% but still < 3%
                    tempGT = Genotype.AltLikeNoCall;
                }

                //next - we have to clean up any multiple allelic sites.
            }
            // also, dont call it a variant *or* a reference
            // if the combined Depth is less than the minimum.
            // (this case is defensive programing.  The SVC should already call
            // each pool variant as ".\." , due to indiviudal low depth,
            // so the combined results
            // shoud already be ".\." by default. )
            else if (TotalDepth < variantCallingParameters.MinimumCoverage)
            {
                // note, this could happen even though your input variants are one 'no call' and one 'var',
                //or even two variants-failing-filters.
                tempGT = Genotype.RefLikeNoCall;
            }
            return(tempGT);
        }
コード例 #9
0
        private static bool PushThroughRamificationsOfGTChange(CalledAllele VariantA, CalledAllele VariantB,
                                                               CalledAllele Consensus, int RefCountA, int RefCountB, int DepthA, int DepthB,
                                                               Genotype GT, int MaxQScore, VariantComparisonCase Case)
        {
            int NoiseLevel = Consensus.NoiseLevelApplied;

            if (((GT == Genotype.HomozygousRef) || (GT == Genotype.RefLikeNoCall)) && (Case == VariantComparisonCase.OneReferenceOneAlternate))
            {
                Consensus.AlternateAllele = ".";
                Consensus.ReferenceAllele = Consensus.ReferenceAllele.Substring(0, 1);

                if (VariantA != null)
                {
                    VariantA.VariantQscore = VariantQualityCalculator.AssignPoissonQScore(
                        RefCountA, DepthA, NoiseLevel, MaxQScore);
                }

                if (VariantB != null)
                {
                    VariantB.VariantQscore = VariantQualityCalculator.AssignPoissonQScore(
                        RefCountB, DepthB, NoiseLevel, MaxQScore);
                }

                Consensus.AlleleSupport = Consensus.ReferenceSupport;
                return(true);
            }

            return(false);
        }
コード例 #10
0
        private static void RecalculateScoring(CalledAllele VariantA, CalledAllele VariantB,
                                               VariantComparisonCase Case,
                                               AggregateAllele ConsensusAllele, SampleAggregationParameters SampleAggregationOptions, VariantCallingParameters variantCallingParameters)
        {
            int RefCountB = 0, RefCountA = 0;
            int AltCountB = 0, AltCountA = 0;
            int DepthA = 0;
            int DepthB = 0;

            //1) first, calculate all the component values (variant frequency, etc...)
            if (VariantA != null)
            {
                RefCountA = VariantA.ReferenceSupport;
                AltCountA = (VariantA.IsRefType) ? 0 : VariantA.AlleleSupport;
                DepthA    = VariantA.TotalCoverage;
            }

            if (VariantB != null)
            {
                RefCountB = VariantB.ReferenceSupport;
                AltCountB = (VariantB.IsRefType) ? 0 : VariantB.AlleleSupport;
                DepthB    = VariantB.TotalCoverage;
            }


            int TotalDepth     = DepthA + DepthB;
            int ReferenceDepth = RefCountA + RefCountB;
            int AltDepth       = AltCountA + AltCountB;

            double VarFrequency  = ((AltDepth == 0) || (TotalDepth == 0)) ? 0.0 : ((double)AltDepth) / ((double)(TotalDepth));
            double VarFrequencyA = ((AltCountA == 0) || (DepthA == 0)) ? 0.0 : ((double)AltCountA) / ((double)(DepthA));
            double VarFrequencyB = ((AltCountB == 0) || (DepthB == 0)) ? 0.0 : ((double)AltCountB) / ((double)(DepthB));

            ConsensusAllele.TotalCoverage    = TotalDepth;
            ConsensusAllele.AlleleSupport    = AltDepth;
            ConsensusAllele.ReferenceSupport = ReferenceDepth;

            var GT = GetGenotype(VariantA, VariantB, Case,
                                 TotalDepth, VarFrequency, VarFrequencyA, VarFrequencyB, SampleAggregationOptions, variantCallingParameters);

            ConsensusAllele.NoiseLevelApplied = GetCombinedNLValue(VariantA, VariantB, SampleAggregationOptions);
            ConsensusAllele.StrandBiasResults = GetCombinedSBValue(VariantA, VariantB, SampleAggregationOptions);

            //its possible the GTString went from var -> ref when we combined the results.
            //If that is the case we do not want to write "variant" anymore to the .vcf.
            //We also have to re-calculate the Q scores for a reference call.
            //They need to be based on a reference model, not a variant model.
            bool AltChangedToRef = PushThroughRamificationsOfGTChange(VariantA, VariantB,
                                                                      ConsensusAllele, RefCountA, RefCountB, DepthA, DepthB, GT,
                                                                      variantCallingParameters.MaximumVariantQScore, Case);

            ConsensusAllele.Genotype        = GT;
            ConsensusAllele.PoolBiasResults = GetProbePoolBiasScore(Case, ConsensusAllele,
                                                                    SampleAggregationOptions.ProbePoolBiasThreshold, variantCallingParameters, AltCountA, AltCountB, DepthA, DepthB, GT, AltChangedToRef);

            if (SampleAggregationOptions.HowToCombineQScore == SampleAggregationParameters.CombineQScoreMethod.TakeMin)
            {
                ConsensusAllele.VariantQscore = CombineQualitiesByTakingMinValue(VariantA, VariantB);
            }
            else //VariantCallingCombinePoolSettings.CombineQScoreMethod.CombinePoolsAndReCalculate
            {
                //where we apply the reference Q model:
                if (Case == VariantComparisonCase.AgreedOnReference)
                {
                    ConsensusAllele.VariantQscore = CombineQualitiesByPoolingReads(ReferenceDepth, TotalDepth, ConsensusAllele.NoiseLevelApplied,
                                                                                   variantCallingParameters.MaximumVariantQScore);
                }
                else if ((Case == VariantComparisonCase.OneReferenceOneAlternate) && (AltChangedToRef))
                {
                    ConsensusAllele.VariantQscore = CombineQualitiesByPoolingReads(ReferenceDepth, TotalDepth, ConsensusAllele.NoiseLevelApplied,
                                                                                   variantCallingParameters.MaximumVariantQScore);
                }
                else if ((Case == VariantComparisonCase.CanNotCombine) && (AltDepth == 0)) //so the only call we had must have been ref
                {
                    ConsensusAllele.VariantQscore = CombineQualitiesByPoolingReads(ReferenceDepth, TotalDepth, ConsensusAllele.NoiseLevelApplied,
                                                                                   variantCallingParameters.MaximumVariantQScore);
                }

                //where we apply the variant Q model. this is most cases
                else // cases are aggreed on alt, or one alt call.  in which case, apply variant Q model.
                {
                    ConsensusAllele.VariantQscore = CombineQualitiesByPoolingReads(AltDepth, TotalDepth, ConsensusAllele.NoiseLevelApplied,
                                                                                   variantCallingParameters.MaximumVariantQScore);
                }
            }

            //assuming this is only used on Somatic...
            ConsensusAllele.GenotypeQscore = ConsensusAllele.VariantQscore;
            ConsensusAllele.SetType();

            if (ConsensusAllele.IsRefType)
            {
                ConsensusAllele.AlleleSupport = ConsensusAllele.ReferenceSupport;
            }
        }
コード例 #11
0
        private static string CombineVariantAlleles(CalledAllele VariantA, CalledAllele VariantB, VariantComparisonCase ComparisonCase)
        {
            if (ComparisonCase == VariantComparisonCase.AgreedOnReference)
            {
                return(".");
            }

            if (ComparisonCase == VariantComparisonCase.AgreedOnAlternate)
            {
                return(VariantA.AlternateAllele);
            }

            if (ComparisonCase == VariantComparisonCase.OneReferenceOneAlternate)
            {
                CalledAllele NonRef = (VariantA.Type == AlleleCategory.Reference) ? VariantB : VariantA;
                return(NonRef.AlternateAllele);
            }

            if ((ComparisonCase == VariantComparisonCase.CanNotCombine))
            {
                //if we have two different alleles, then we shoud only be trying to combine one at once.
                if (VariantB == null)
                {
                    return(VariantA.AlternateAllele);
                }
                else
                {
                    return(VariantB.AlternateAllele);
                }
            }
            else
            {
                throw new ArgumentException("Option not supported");
            }
        }