Esempio n. 1
0
        public double CalculateInbreedingCoefficient(ICollection <PedigreeUnit> pedigree, Guid fatherId, Guid motherId)
        {
            var father = pedigree.FirstOrDefault(x => x.ItemId.Equals(fatherId));
            var mother = pedigree.FirstOrDefault(x => x.ItemId.Equals(motherId));

            if (father == null || mother == null)
            {
                return(0);
            }

            var paths = new List <PedigreePath>();

            var path = new PedigreePath();

            path.AddNode(new PedigreePathNode()
            {
                Id = mother.ItemId, Name = mother.Name
            });

            ProceedParents(mother, pedigree, path, paths);

            paths = paths.Where(x => x.Nodes.Last().Id.Equals(father.ItemId)).ToList();

            return(paths.Select(x => Math.Pow(0.5, x.NumberOfNodes())).Sum());
        }
Esempio n. 2
0
        private void ProceedParents
            (PedigreeUnit root,
            ICollection <PedigreeUnit> pedigree,
            PedigreePath path,
            ICollection <PedigreePath> paths)
        {
            var parents = pedigree.Where(x => x.Children.Any(y => y.ItemId.Equals(root.ItemId))).ToList();

            if (!parents.Any())
            {
                paths.Add(path);
            }

            foreach (var parent in parents)
            {
                var currentPath = path.Copy();

                currentPath.AddNode(new PedigreePathNode()
                {
                    Id = parent.ItemId, Name = parent.Name
                });

                ProceedChildren(root, parent, currentPath, paths);

                ProceedParents(parent, pedigree, currentPath, paths);
            }
        }
Esempio n. 3
0
        private void ProceedChildren(PedigreeUnit chosenChild, PedigreeUnit parent, PedigreePath path, ICollection <PedigreePath> paths)
        {
            if (!parent.Children.Any())
            {
                paths.Add(path);
            }

            foreach (var child in parent.Children)
            {
                if (child.ItemId.Equals(chosenChild.ItemId))
                {
                    continue;
                }

                var currentPath = path.Copy();

                currentPath.AddNode(new PedigreePathNode()
                {
                    Id = child.ItemId, Name = child.Name
                });

                ProceedChildren(parent, child, currentPath, paths);
            }
        }