Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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
                    });
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// perfom a Venn split between two samples
        /// </summary>
        /// <param name="sampleName"></param>
        /// <param name="consensusFilePath"></param>
        /// <param name="inputPaths"></param>
        /// <param name="outputTwoSampleResults"></param>
        public void DoPairwiseVenn(bool mFirst)
        {
            bool doConsensus      = (consensusBuilder != null);
            bool requireGenotypes = false;

            using (VcfReader ReaderA = new VcfReader(_inputPaths[0], requireGenotypes))
                using (VcfReader ReaderB = new VcfReader(_inputPaths[1], requireGenotypes))
                {
                    if (doConsensus)
                    {
                        consensusBuilder.OpenConsensusFile(ReaderA.HeaderLines);
                    }

                    OpenVennDiagramStreams(ReaderA.HeaderLines);

                    //read the first variant from each gvcf file...
                    var currentAllele          = new CalledAllele();
                    var backLogPoolAVcfVariant = new VcfVariant();
                    var backLogPoolBVcfVariant = new VcfVariant();

                    var backLogExistPoolA = ReaderA.GetNextVariant(backLogPoolAVcfVariant);
                    var backLogExistPoolB = ReaderB.GetNextVariant(backLogPoolBVcfVariant);

                    var backLogPoolAAlleles = backLogExistPoolA ? VcfVariantUtilities.Convert(new List <VcfVariant> {
                        backLogPoolAVcfVariant
                    }).ToList() : null;
                    var backLogPoolBAlleles = backLogExistPoolB ? VcfVariantUtilities.Convert(new List <VcfVariant> {
                        backLogPoolBVcfVariant
                    }).ToList() : null;

                    //keep reading and processing until we are done with both gvcfs
                    while (true)
                    {
                        try
                        {
                            //1) Get the next set of variants. Pull from the backlog first,
                            //choosing all the variants at the first available position.
                            var coLocatedPoolAAlleles = new List <CalledAllele>();
                            var coLocatedPoolBAlleles = new List <CalledAllele>();

                            //We need to set up which location to look at next.
                            //Choose the first one from the backlog.

                            if (backLogExistPoolA || backLogExistPoolB)
                            {
                                if (backLogExistPoolA && backLogExistPoolB)
                                {
                                    int OrderResult = AlleleCompareByLoci.OrderAlleles(
                                        backLogPoolAAlleles.First(), backLogPoolBAlleles.First(), mFirst);
                                    if (OrderResult < 0)
                                    {
                                        currentAllele.Chromosome        = backLogPoolAAlleles.First().Chromosome;
                                        currentAllele.ReferencePosition = backLogPoolAAlleles.First().ReferencePosition;
                                    }
                                    else
                                    {
                                        currentAllele.Chromosome        = backLogPoolBAlleles.First().Chromosome;
                                        currentAllele.ReferencePosition = backLogPoolBAlleles.First().ReferencePosition;
                                    }
                                }
                                else if (backLogExistPoolB)
                                {
                                    currentAllele.Chromosome        = backLogPoolBAlleles.First().Chromosome;
                                    currentAllele.ReferencePosition = backLogPoolBAlleles.First().ReferencePosition;
                                }
                                else //if (backLogExistPoolA)
                                {
                                    currentAllele.Chromosome        = backLogPoolAAlleles.First().Chromosome;
                                    currentAllele.ReferencePosition = backLogPoolAAlleles.First().ReferencePosition;
                                }

                                //assemble lists of co-located variants at the position of the current variant
                                coLocatedPoolAAlleles = AssembleColocatedList(ReaderA, currentAllele, mFirst,
                                                                              ref backLogExistPoolA, ref backLogPoolAAlleles);

                                coLocatedPoolBAlleles = AssembleColocatedList(ReaderB, currentAllele, mFirst,
                                                                              ref backLogExistPoolB, ref backLogPoolBAlleles);
                            } //else, if there is nothing in either backlog, the colocated-variant list should stay empty.

                            //2) Now we have finshed reading out all the co-located variants...
                            //We need organize them into pairs, to know which allele to compare with which.
                            var             Pairs                      = SelectPairs(coLocatedPoolAAlleles, coLocatedPoolBAlleles);
                            var             ConsensusVariants          = new List <CalledAllele>();
                            AggregateAllele lastConsensusReferenceCall = null;

                            //3) For each pair, combine them and mark if biased or not.
                            for (int PairIndex = 0; PairIndex < Pairs.Count; PairIndex++)
                            {
                                var VariantA = Pairs[PairIndex][0];
                                var VariantB = Pairs[PairIndex][1];

                                var ComparisonCase = GetComparisonCase(VariantA, VariantB);


                                //add VarA and VarB to appropriate venn diagram files.
                                WriteVarsToVennFiles(ComparisonCase, VariantA, VariantB);
                                AggregateAllele Consensus = null;

                                if (doConsensus)
                                {
                                    Consensus = consensusBuilder.CombineVariants(
                                        VariantA, VariantB, ComparisonCase);


                                    //Its possible for multiallelic sites, a pair of variants could
                                    //end up as a concensus reference. And we already may have
                                    //called a reference for this loci already.
                                    //we might have some cleaning up to do...
                                    if (Consensus.Genotype == Pisces.Domain.Types.Genotype.HomozygousRef)
                                    {
                                        //this is the first time we see a reference at this loci
                                        if (lastConsensusReferenceCall == null)
                                        {
                                            lastConsensusReferenceCall = Consensus;
                                            //its OK to fall through and add our Consensus variant to the list.
                                        }

                                        //Else, if we have already called a reference variant
                                        // for this loci already
                                        // we want to merge the results from this reference with the old one.
                                        // *before* we write it to file.
                                        else
                                        {
                                            //the chr, pos, ref, alt,and depth should be correct.
                                            //We'll merge the filters,
                                            //and take the max SB and PB. (where a higher value indicates worse value, so we stay conservative)
                                            lastConsensusReferenceCall.Filters = ConsensusBuilder.CombineFilters(lastConsensusReferenceCall, Consensus);

                                            lastConsensusReferenceCall.StrandBiasResults = new Pisces.Domain.Models.BiasResults()
                                            {
                                                GATKBiasScore = Math.Max(lastConsensusReferenceCall.StrandBiasResults.GATKBiasScore, Consensus.StrandBiasResults.GATKBiasScore)
                                            };

                                            lastConsensusReferenceCall.PoolBiasResults = new Pisces.Domain.Models.BiasResults()
                                            {
                                                GATKBiasScore = Math.Max(lastConsensusReferenceCall.PoolBiasResults.GATKBiasScore, Consensus.PoolBiasResults.GATKBiasScore)
                                            };

                                            //we are going to take the min Q and NL score, to be conservative
                                            lastConsensusReferenceCall.NoiseLevelApplied = Math.Min(lastConsensusReferenceCall.NoiseLevelApplied, Consensus.NoiseLevelApplied);
                                            lastConsensusReferenceCall.GenotypeQscore    = Math.Min(lastConsensusReferenceCall.GenotypeQscore, Consensus.GenotypeQscore);
                                            lastConsensusReferenceCall.VariantQscore     = Math.Min(lastConsensusReferenceCall.VariantQscore, Consensus.GenotypeQscore);

                                            continue;
                                        }
                                    }

                                    ConsensusVariants.Add(Consensus);
                                }
                            }

                            //4) Write out the results to file. (this will be a list of co-located variants)

                            if (doConsensus)
                            {
                                consensusBuilder.WriteConsensusVariantsToFile(ConsensusVariants);
                            }

                            //we assembled everyone and no one is left.
                            if ((backLogPoolAAlleles == null) &&
                                (backLogPoolBAlleles == null))
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            OnError(string.Format("Fatal error encountered comparing paired sample vcfs; Check {0}, position {1}.  Exception: {2}",
                                                  currentAllele.Chromosome, currentAllele.ReferencePosition, ex));
                            throw;
                        }
                    } //close assemble list
                }//close usings

            if (doConsensus)
            {
                consensusBuilder.CloseConsensusFile();
            }

            CloseVennDiagramStreams();
        }
Ejemplo n.º 4
0
        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
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
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;
            }
        }