示例#1
0
        public void ContainsSharedAllelesTester_TotalCopyNumberOnly()
        {
            var genotype1 = Genotype.Create(3);
            var genotype2 = Genotype.Create(2);

            Assert.NotEqual(genotype1, genotype2);

            genotype2 = Genotype.Create(new PhasedGenotype(2, 1));
            Assert.Equal(genotype1, genotype2);

            genotype2 = Genotype.Create(3);
            Assert.Equal(genotype1, genotype2);
        }
示例#2
0
        public void ContainsSharedAllelesTester_PhasedGenotype()
        {
            var genotype1 = Genotype.Create(new PhasedGenotype(2, 1));
            var genotype2 = Genotype.Create(new PhasedGenotype(2, 1));

            Assert.Equal(genotype1, genotype2);

            genotype2 = Genotype.Create(new PhasedGenotype(1, 2));
            Assert.NotEqual(genotype1, genotype2);

            genotype2 = Genotype.Create(new PhasedGenotype(1, 1));
            Assert.NotEqual(genotype1, genotype2);
        }
示例#3
0
        public static List <Genotype> GeneratePhasedGenotype(int numCnStates)
        {
            var genotypes = new List <Genotype>();

            for (int cn = 0; cn < numCnStates; cn++)
            {
                for (int gt = 0; gt <= cn; gt++)
                {
                    genotypes.Add(Genotype.Create(new PhasedGenotype(gt, cn - gt)));
                }
            }
            return(genotypes);
        }
示例#4
0
        /// <summary>
        /// Estimate joint likelihood and most likely CN assignment within a pedigree using total CN Genotype likelihoods and transition matrix
        /// </summary>
        /// <param name="pedigreeInfo"></param>
        /// <param name="copyNumbersLikelihoods"></param>
        /// <returns></returns>
        private (ISampleMap <Genotype> copyNumbersGenotypes, JointLikelihoods jointLikelihood) GetPedigreeCopyNumbers(PedigreeInfo pedigreeInfo, ISampleMap <Dictionary <Genotype, double> > copyNumbersLikelihoods)
        {
            int nHighestLikelihoodGenotypes = pedigreeInfo != null && pedigreeInfo.OffspringIds.Count >= 2 ? 3 : _callerParameters.MaximumCopyNumber;

            copyNumbersLikelihoods = copyNumbersLikelihoods.SelectValues(l => l.OrderByDescending(kvp => kvp.Value).Take(nHighestLikelihoodGenotypes).ToDictionary());

            var sampleCopyNumbersGenotypes = new SampleMap <Genotype>();
            var jointLikelihood            = new JointLikelihoods();

            if (!pedigreeInfo.HasFullPedigree())
            {
                return(sampleCopyNumbersGenotypes, jointLikelihood);
            }
            // parent 1 total CNs and likelihoods
            foreach (var copyNumberParent1 in copyNumbersLikelihoods[pedigreeInfo.ParentsIds.First()])
            {
                // parent 2 total CNs and likelihoods
                foreach (var copyNumberParent2 in copyNumbersLikelihoods[pedigreeInfo.ParentsIds.Last()])
                {
                    // for offspring in addition to querying likelihoods using total CNs, iterate over all possible genotype combination (CopyNumberA/B) for a given
                    // CN and estimate likely transition probabilities using TransitionMatrix
                    foreach (var offspringGtStates in pedigreeInfo.OffspringPhasedGenotypes)
                    {
                        if (!pedigreeInfo.OffspringIds.All(id => copyNumbersLikelihoods[id].ContainsKey(
                                                               Genotype.Create(Math.Min(offspringGtStates[pedigreeInfo.OffspringIds.IndexOf(id)].PhasedGenotype.CopyNumberA + offspringGtStates[pedigreeInfo.OffspringIds.IndexOf(id)].PhasedGenotype.CopyNumberB,
                                                                                        _callerParameters.MaximumCopyNumber - 1)))))
                        {
                            // unavailable total CN
                            continue;
                        }
                        // For a given combination of offspring copy numbers, only the genotypes that result in the maximum likelihood contribute to the final result."
                        double currentLikelihood        = copyNumberParent1.Value * copyNumberParent2.Value;
                        var    totalCopyNumberGenotypes = new List <Genotype>();
                        for (var counter = 0; counter < pedigreeInfo.OffspringIds.Count; counter++)
                        {
                            var child = pedigreeInfo.OffspringIds[counter];
                            var copyNumberGenotypeChild = Genotype.Create(Math.Min(offspringGtStates[counter].PhasedGenotype.CopyNumberA + offspringGtStates[counter].PhasedGenotype.CopyNumberB,
                                                                                   _callerParameters.MaximumCopyNumber - 1));
                            totalCopyNumberGenotypes.Add(copyNumberGenotypeChild);
                            currentLikelihood *= pedigreeInfo.TransitionMatrix[copyNumberParent1.Key.TotalCopyNumber][offspringGtStates[counter].PhasedGenotype.CopyNumberA] *
                                                 pedigreeInfo.TransitionMatrix[copyNumberParent2.Key.TotalCopyNumber][offspringGtStates[counter].PhasedGenotype.CopyNumberB] *
                                                 copyNumbersLikelihoods[child][copyNumberGenotypeChild];
                        }
                        currentLikelihood = Double.IsNaN(currentLikelihood) || Double.IsInfinity(currentLikelihood) ? 0 : currentLikelihood;

                        var genotypesInPedigree = new SampleMap <Genotype>
                        {
                            { pedigreeInfo.ParentsIds.First(), copyNumberParent1.Key },
                            { pedigreeInfo.ParentsIds.Last(), copyNumberParent2.Key }
                        };
                        pedigreeInfo.OffspringIds.Zip(totalCopyNumberGenotypes).ForEach(sampleIdGenotypeKvp => genotypesInPedigree.Add(sampleIdGenotypeKvp.Item1, sampleIdGenotypeKvp.Item2));
                        genotypesInPedigree = genotypesInPedigree.OrderBy(pedigreeInfo.AllSampleIds);
                        jointLikelihood.AddJointLikelihood(genotypesInPedigree, currentLikelihood);
                        double currentLogLikelihood = Math.Log(currentLikelihood);
                        if (currentLogLikelihood > jointLikelihood.MaximalLogLikelihood)
                        {
                            jointLikelihood.MaximalLogLikelihood = currentLogLikelihood;
                            sampleCopyNumbersGenotypes           = genotypesInPedigree;
                        }
                    }
                }
            }
            if (sampleCopyNumbersGenotypes.Empty())
            {
                throw new IlluminaException("Maximal likelihood was not found");
            }
            return(sampleCopyNumbersGenotypes, jointLikelihood);
        }
示例#5
0
        public void TestCommonCnvAssignment_DeNovoVariants()
        {
            var bins = new List <SampleGenomicBin>
            {
                new SampleGenomicBin("chr1", 1, 2, 100),
                new SampleGenomicBin("chr1", 1, 2, 100),
                new SampleGenomicBin("chr1", 1, 2, 100)
            };
            var balleles = new Balleles(new List <Ballele> {
                new Ballele(5501, 30, 30)
            });
            var segmentParent1 = new CanvasSegment("chr1", 1, 2, bins, balleles)
            {
                CopyNumber = 2
            };

            bins = new List <SampleGenomicBin>
            {
                new SampleGenomicBin("chr1", 1, 2, 100),
                new SampleGenomicBin("chr1", 1, 2, 100),
                new SampleGenomicBin("chr1", 1, 2, 100)
            };
            balleles = new Balleles(new List <Ballele> {
                new Ballele(5501, 30, 30)
            });
            var segmentParent2 = new CanvasSegment("chr1", 1, 2, bins, balleles)
            {
                CopyNumber = 2
            };

            bins = new List <SampleGenomicBin>
            {
                new SampleGenomicBin("chr1", 1, 2, 0),
                new SampleGenomicBin("chr1", 1, 2, 0),
                new SampleGenomicBin("chr1", 1, 2, 0)
            };
            balleles = new Balleles(new List <Ballele> {
                new Ballele(5501, 0, 0)
            });
            var segmentProband = new CanvasSegment("chr1", 1, 2, bins, balleles)
            {
                CopyNumber = 0
            };

            var pedigreeSegments = new SampleMap <CanvasSegment>
            {
                { new SampleId("parent1"), segmentParent1 },
                { new SampleId("parent2"), segmentParent2 },
                { new SampleId("proband"), segmentProband }
            };

            var sampleMetricsParent1 = SampleMetrics.GetSampleInfo(new List <CanvasSegment> {
                segmentParent1
            },
                                                                   ploidyBedPath: null,
                                                                   numberOfTrimmedBins: 2, id: new SampleId("parent1"));
            var sampleMetricsParent2 = SampleMetrics.GetSampleInfo(new List <CanvasSegment> {
                segmentParent2
            },
                                                                   ploidyBedPath: null,
                                                                   numberOfTrimmedBins: 2, id: new SampleId("parent2"));
            var sampleMetricsProband = SampleMetrics.GetSampleInfo(new List <CanvasSegment> {
                segmentProband
            },
                                                                   ploidyBedPath: null,
                                                                   numberOfTrimmedBins: 2, id: new SampleId("proband"));

            var sampleMetrics = new SampleMap <SampleMetrics>
            {
                { new SampleId("parent1"), sampleMetricsParent1 },
                { new SampleId("parent2"), sampleMetricsParent2 },
                { new SampleId("proband"), sampleMetricsProband }
            };

            bool isCommonCnv = global::CanvasPedigreeCaller.CanvasPedigreeCaller.IsSharedCnv(pedigreeSegments, sampleMetrics,
                                                                                             new List <SampleId> {
                new SampleId("parent1"), new SampleId("parent2")
            },
                                                                                             new SampleId("proband"), maximumCopyNumber: 5);

            Assert.False(isCommonCnv);

            var pedigreeGenotypes = new SampleMap <Genotype>
            {
                { new SampleId("parent1"), Genotype.Create(new PhasedGenotype(1, 1)) },
                { new SampleId("parent2"), Genotype.Create(new PhasedGenotype(1, 1)) },
                { new SampleId("proband"), Genotype.Create(new PhasedGenotype(0, 1)) }
            };

            isCommonCnv = global::CanvasPedigreeCaller.CanvasPedigreeCaller.IsSharedCnv(pedigreeGenotypes, pedigreeSegments,
                                                                                        sampleMetrics, new List <SampleId> {
                new SampleId("parent1"), new SampleId("parent2")
            },
                                                                                        new SampleId("proband"), maximumCopyNumber: 5);

            Assert.False(isCommonCnv);

            pedigreeGenotypes = new SampleMap <Genotype>
            {
                { new SampleId("parent1"), Genotype.Create(new PhasedGenotype(2, 1)) },
                { new SampleId("parent2"), Genotype.Create(new PhasedGenotype(1, 1)) },
                { new SampleId("proband"), Genotype.Create(new PhasedGenotype(0, 1)) }
            };

            isCommonCnv = global::CanvasPedigreeCaller.CanvasPedigreeCaller.IsSharedCnv(pedigreeGenotypes, pedigreeSegments,
                                                                                        sampleMetrics, new List <SampleId> {
                new SampleId("parent1"), new SampleId("parent2")
            },
                                                                                        new SampleId("proband"), maximumCopyNumber: 5);

            Assert.False(isCommonCnv);
        }