Пример #1
0
        private void ExecuteDiploidGenotypeTest(
            Genotype expectedGenotype, int expectedNumAllelesToPrune,
            List <float> refFrequencies, List <float> altFrequencies, List <FilterType> filters, int coverage)
        {
            var    alleles = new List <CalledAllele>();
            double refFreq = 0;

            foreach (float rf in refFrequencies)
            {
                var variant = TestHelper.CreatePassingVariant(true);
                variant.AlleleSupport    = (int)(rf * coverage);
                variant.TotalCoverage    = (int)coverage;
                variant.ReferenceSupport = variant.AlleleSupport;
                alleles.Add(variant);
                refFreq = rf;
            }

            if (refFreq == 0)
            {
                refFreq = (1.0 - altFrequencies.Sum());
            }

            foreach (float vf in altFrequencies)
            {
                var variant = TestHelper.CreatePassingVariant(false);
                variant.AlleleSupport    = (int)(vf * coverage);
                variant.TotalCoverage    = (int)coverage;
                variant.ReferenceSupport = (int)(refFreq * coverage);
                alleles.Add(variant);
            }

            //set filters for at least one allele. they should affect all results.
            alleles[0].Filters = filters;

            DiploidGenotypeCalculator GTC = GetOriginalSettings();

            GTC.MinDepthToGenotype = 100;
            var allelesToPrune = GTC.SetGenotypes(alleles);

            Assert.Equal(expectedNumAllelesToPrune, allelesToPrune.Count);
            foreach (var allele in alleles)
            {
                Assert.Equal(expectedGenotype, allele.Genotype);
            }
        }
Пример #2
0
        private void ExecuteDiploidIndelGenotypeTest()
        {
            //test cases:
            // (1) SNP + indel + indel
            // (2) indel + SNP + SNP
            // (3) 3 indels (OK)
            // (4) 3 indels - ploidy violation

            Genotype expectedGenotype          = Genotype.HeterozygousAlt1Alt2;
            int      expectedNumAllelesToPrune = 1;

            // (1) SNP + indel + indel
            // should be 1/2 with the lowest freq thrown out
            List <float> refFrequencies = new List <float>()
            {
                0.40F, 0.60F, 0.90F
            };
            List <float> altFrequencies = new List <float>()
            {
                0.60F, 0.40F, 0.10F
            };
            List <string> refAllele = new List <string>()
            {
                "A", "A", "ACT"
            };
            List <string> altAllele = new List <string>()
            {
                "C", "AGGG", "A"
            };
            double coverage = 1000;

            var alleles = new List <CalledAllele>();

            for (int i = 0; i < 3; i++)
            {
                var variant = TestHelper.CreatePassingVariant(false);
                variant.AlleleSupport    = (int)(altFrequencies[i] * coverage);
                variant.TotalCoverage    = (int)coverage;
                variant.ReferenceSupport = (int)(refFrequencies[i] * coverage);
                variant.AlternateAllele  = altAllele[i];
                variant.ReferenceAllele  = refAllele[i];
                alleles.Add(variant);
            }
            alleles[1].Type = AlleleCategory.Insertion;
            alleles[2].Type = AlleleCategory.Deletion;

            var GTC = new DiploidGenotypeCalculator();

            GTC.MinDepthToGenotype = 100;
            var allelesToPrune = GTC.SetGenotypes(alleles);

            Assert.Equal(expectedNumAllelesToPrune, allelesToPrune.Count);
            foreach (var allele in alleles)
            {
                Assert.Equal(expectedGenotype, allele.Genotype);
                Assert.Equal(0, allele.Filters.Count());
            }

            Assert.Equal(allelesToPrune[0].ReferenceAllele, "ACT");
            Assert.Equal(allelesToPrune[0].AlternateAllele, "A");
            Assert.Equal(allelesToPrune[0].Frequency, 0.10F);


            // (2) indel + SNP + SNP
            // should be 1/2 with the lowest freq thrown out
            refFrequencies = new List <float>()
            {
                0.40F, 0.20F, 0.20F
            };
            altFrequencies = new List <float>()
            {
                0.60F, 0.10F, 0.40F
            };
            refAllele = new List <string>()
            {
                "A", "A", "A"
            };
            altAllele = new List <string>()
            {
                "ACCAT", "G", "C"
            };


            alleles = new List <CalledAllele>();
            for (int i = 0; i < 3; i++)
            {
                var variant = TestHelper.CreatePassingVariant(false);
                variant.AlleleSupport    = (int)(altFrequencies[i] * coverage);
                variant.TotalCoverage    = (int)coverage;
                variant.ReferenceSupport = (int)(refFrequencies[i] * coverage);
                variant.AlternateAllele  = altAllele[i];
                variant.ReferenceAllele  = refAllele[i];
                alleles.Add(variant);
            }
            alleles[0].Type = AlleleCategory.Insertion;

            GTC = new DiploidGenotypeCalculator();
            GTC.MinDepthToGenotype = 100;
            allelesToPrune         = GTC.SetGenotypes(alleles);

            Assert.Equal(expectedNumAllelesToPrune, allelesToPrune.Count);
            foreach (var allele in alleles)
            {
                Assert.Equal(expectedGenotype, allele.Genotype);
                Assert.Equal(0, allele.Filters.Count());
            }

            Assert.Equal(allelesToPrune[0].ReferenceAllele, "A");
            Assert.Equal(allelesToPrune[0].AlternateAllele, "G");
            Assert.Equal(allelesToPrune[0].Frequency, 0.10F);


            // (3) 3 indels (OK)
            // should be 1/2 with the lowest freq thrown out
            refFrequencies = new List <float>()
            {
                0.40F, 0.90F, 0.60F
            };
            altFrequencies = new List <float>()
            {
                0.60F, 0.10F, 0.40F
            };
            refAllele = new List <string>()
            {
                "A", "ACT", "A"
            };
            altAllele = new List <string>()
            {
                "ACCAT", "A", "CC"
            };

            alleles = new List <CalledAllele>();
            for (int i = 0; i < 3; i++)
            {
                var variant = TestHelper.CreatePassingVariant(false);
                variant.AlleleSupport    = (int)(altFrequencies[i] * coverage);
                variant.TotalCoverage    = (int)coverage;
                variant.ReferenceSupport = (int)(refFrequencies[i] * coverage);
                variant.AlternateAllele  = altAllele[i];
                variant.ReferenceAllele  = refAllele[i];
                alleles.Add(variant);
            }
            alleles[0].Type = AlleleCategory.Insertion;
            alleles[1].Type = AlleleCategory.Deletion;
            alleles[2].Type = AlleleCategory.Insertion;

            GTC = new DiploidGenotypeCalculator();
            GTC.MinDepthToGenotype = 100;
            allelesToPrune         = GTC.SetGenotypes(alleles);

            Assert.Equal(expectedNumAllelesToPrune, allelesToPrune.Count);
            foreach (var allele in alleles)
            {
                Assert.Equal(expectedGenotype, allele.Genotype);
                Assert.Equal(0, allele.Filters.Count());
            }

            Assert.Equal(allelesToPrune[0].ReferenceAllele, "ACT");
            Assert.Equal(allelesToPrune[0].AlternateAllele, "A");
            Assert.Equal(allelesToPrune[0].Frequency, 0.10F);


            // (4) 3 indels - ploidy violation
            // should be ./. with the lowest freq thrown out
            refFrequencies = new List <float>()
            {
                0.60F, 0.60F, 0.60F
            };
            altFrequencies = new List <float>()
            {
                0.31F, 0.30F, 0.31F
            };
            refAllele = new List <string>()
            {
                "A", "ACT", "A"
            };
            altAllele = new List <string>()
            {
                "ACCAT", "A", "AC"
            };

            expectedGenotype = Genotype.Alt12LikeNoCall;
            alleles          = new List <CalledAllele>();
            for (int i = 0; i < 3; i++)
            {
                var variant = TestHelper.CreatePassingVariant(false);
                variant.AlleleSupport    = (int)(altFrequencies[i] * coverage);
                variant.TotalCoverage    = (int)coverage;
                variant.ReferenceSupport = (int)(refFrequencies[i] * coverage);
                variant.AlternateAllele  = altAllele[i];
                variant.ReferenceAllele  = refAllele[i];
                alleles.Add(variant);
            }
            alleles[0].Type = AlleleCategory.Insertion;
            alleles[1].Type = AlleleCategory.Deletion;
            alleles[2].Type = AlleleCategory.Insertion;

            GTC = new DiploidGenotypeCalculator();
            GTC.MinDepthToGenotype = 100;
            allelesToPrune         = GTC.SetGenotypes(alleles);

            Assert.Equal(expectedNumAllelesToPrune, allelesToPrune.Count);
            foreach (var allele in alleles)
            {
                Assert.Equal(expectedGenotype, allele.Genotype);
                Assert.Equal(FilterType.MultiAllelicSite, allele.Filters[0]);
            }

            Assert.Equal(allelesToPrune[0].ReferenceAllele, "ACT");
            Assert.Equal(allelesToPrune[0].AlternateAllele, "A");
            Assert.Equal(allelesToPrune[0].Frequency, 0.30F);
        }