private PedigreeIndividual GetLeftmostIndividualOfSet(PedigreeIndividualSet individualSet, PedigreeIndividualSet exclusionSet) { PedigreeIndividual retval = null; foreach (PedigreeIndividual individual in individualSet) { if (exclusionSet.Contains(individual) == false) { if (retval == null) { retval = individual; } else { if (individual.point.x < retval.point.x) { retval = individual; } } } } return(retval); //PedigreeIndividual leftmostIndividual = individualSet[0]; //double minX = leftmostIndividual.point.x; //foreach (PedigreeIndividual individual in individualSet) //{ // if (individual.point.x < minX) // { // minX = individual.point.x; // leftmostIndividual = individual; // } // foreach (PedigreeCouple pc in individual.spouseCouples) // { // if (pc.mother != null && pc.father != null) // { // PedigreeIndividual spouse; // if (individual.HraPerson.relativeID == pc.mother.HraPerson.relativeID) // spouse = pc.father; // else // spouse = pc.mother; // if (exclusionSet.Contains(spouse) == false) // { // if (spouse.point.x < minX) // { // minX = spouse.point.x; // leftmostIndividual = spouse; // } // } // } // } //} //return leftmostIndividual; }
private PedigreeIndividual GetLeftmostIndividualOfSet(PedigreeIndividualSet individualSet) { PedigreeIndividual leftmostIndividual = individualSet[0]; double minX = leftmostIndividual.point.x; foreach (PedigreeIndividual individual in individualSet) { if (individual.point.x < minX) { minX = individual.point.x; leftmostIndividual = individual; } } return(leftmostIndividual); }
private PedigreeIndividual GetRightmostIndividualOfSet(PedigreeIndividualSet individualSet) { PedigreeIndividual rightmostIndividual = individualSet[0]; double maxX = rightmostIndividual.point.x; foreach (PedigreeIndividual individual in individualSet) { if (individual.point.x > maxX) { maxX = individual.point.x; rightmostIndividual = individual; } } return(rightmostIndividual); ; }
private void ApplyForceToParents(PedigreeIndividualSet iSet, double force) { foreach (PedigreeIndividual individual in iSet) { if (individual.Parents != null) { PedigreeCouple parents = individual.Parents; //only apply the force to the parent which has a parent if (parents.mother.Parents != null) { parents.mother.point.dx += force; } if (parents.father.Parents != null) { parents.father.point.dx += force; } } } }
public RepelIndividualSets(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) { return; } //foreach (PedigreeCouple pc in model.couples) //{ // pc.childOverlap = 0; //} int setId = 0; //for each generation, for (int generationalLevel = 0; generationalLevel < model.individualSets.Count; generationalLevel++) { //sort the individual sets of the current generation if (model.individualSets.ContainsKey(generationalLevel)) { List <PedigreeIndividualSet> levelIndividualSets = model.individualSets[generationalLevel]; levelIndividualSets.Sort(delegate(PedigreeIndividualSet a, PedigreeIndividualSet b) { double ax = a.associatedCouple.point.x; double bx = b.associatedCouple.point.x; return(ax.CompareTo(bx)); }); //then repel adjacent individual sets if necessary for (int i = 0; i < levelIndividualSets.Count - 1; i++) { setId++; PedigreeIndividualSet leftSet = levelIndividualSets[i]; PedigreeIndividualSet rightSet = levelIndividualSets[i + 1]; PedigreeIndividual rightmostOfLeftSet = GetRightmostIndividualOfSet(leftSet, rightSet); PedigreeIndividual leftmostOfRightSet = GetLeftmostIndividualOfSet(rightSet, leftSet); PedigreeIndividual rightmostOfRightSet = GetRightmostIndividualOfSet(rightSet, leftSet); PedigreeIndividual leftmostOfLefttSet = GetLeftmostIndividualOfSet(leftSet, rightSet); if (rightmostOfLeftSet != null && leftmostOfRightSet != null && rightmostOfRightSet != null && leftmostOfLefttSet != null) { //double interSetDistance = Math.Abs(leftmostOfRightSet.point.x - rightmostOfLeftSet.point.x); double interSetDistance = leftmostOfRightSet.point.x - rightmostOfLeftSet.point.x; double h = model.parameters.horizontalSpacing; //if (leftmostOfRightSet.point.x < leftmostOfLefttSet.point.x && rightmostOfRightSet.point.x > rightmostOfLeftSet.point.x) //{ // interSetDistance = 0; //} double x = -1 * (interSetDistance - h); //double x = (interSetDistance - h); //double force = 1 / (1 + Math.Pow(2, x)); double force = Math.Pow(2, x); if (force > 5) { force = 5; } force *= model.parameters.repelIndividualSetsStrength; foreach (PedigreeIndividual leftIndividual in leftSet) { leftIndividual.point.dx -= force; } foreach (PedigreeIndividual rightIndividual in rightSet) { rightIndividual.point.dx += force; } ApplyForceToParents(leftSet, -force, x); ApplyForceToParents(rightSet, force, x); } } } } }; }
private PedigreeIndividual GetRightmostIndividualOfSet(PedigreeIndividualSet individualSet, PedigreeIndividualSet exclusionSet) { PedigreeIndividual retval = null; foreach (PedigreeIndividual individual in individualSet) { if (exclusionSet.Contains(individual) == false) { if (retval == null) { retval = individual; } else { if (individual.point.x > retval.point.x) { retval = individual; } } } } return retval; //PedigreeIndividual rightmostIndividual = individualSet[0]; //double maxX = rightmostIndividual.point.x; //foreach (PedigreeIndividual individual in individualSet) //{ // if (individual.point.x > maxX) // { // maxX = individual.point.x; // rightmostIndividual = individual; // } // foreach (PedigreeCouple pc in individual.spouseCouples) // { // if (pc.mother != null && pc.father != null) // { // PedigreeIndividual spouse; // if (individual.HraPerson.relativeID == pc.mother.HraPerson.relativeID) // spouse = pc.father; // else // spouse = pc.mother; // if (exclusionSet.Contains(spouse) == false) // { // if (spouse.point.x > maxX) // { // maxX = spouse.point.x; // rightmostIndividual = spouse; // } // } // } // } //} //return rightmostIndividual; }
private void ApplyForceToParents(PedigreeIndividualSet iSet, double force, double overlap) { foreach (PedigreeIndividual individual in iSet) { if (individual.Parents != null) { PedigreeCouple parents = individual.Parents; //only apply the force to the parent which has a parent if (parents.mother.Parents != null) parents.mother.point.dx += force; if (parents.father.Parents != null) parents.father.point.dx += force; } } }
private PedigreeIndividual GetRightmostIndividualOfSet(PedigreeIndividualSet individualSet) { PedigreeIndividual rightmostIndividual = individualSet[0]; double maxX = rightmostIndividual.point.x; foreach (PedigreeIndividual individual in individualSet) { if (individual.point.x > maxX) { maxX = individual.point.x; rightmostIndividual = individual; } } return rightmostIndividual; ; }
private PedigreeIndividual GetLeftmostIndividualOfSet(PedigreeIndividualSet individualSet) { PedigreeIndividual leftmostIndividual = individualSet[0]; double minX = leftmostIndividual.point.x; foreach (PedigreeIndividual individual in individualSet) { if (individual.point.x < minX) { minX = individual.point.x; leftmostIndividual = individual; } } return leftmostIndividual; }
private void AddIndividualSet(int generationalLevel, PedigreeIndividualSet individualSet) { if (!individualSets.ContainsKey(generationalLevel)) individualSets[generationalLevel] = new List<PedigreeIndividualSet>(); individualSets[generationalLevel].Add(individualSet); }
public PedigreeModel(FamilyHistory p_familyHistory) { familyHistory = p_familyHistory; //Store the individuals as PedigreeIndividuals lock (familyHistory.Relatives) { foreach (Person Person in familyHistory.Relatives) { PedigreeIndividual pedigreeIndividual = new PedigreeIndividual(Person); individuals.Add(pedigreeIndividual); individualsDictionary[Person.relativeID] = pedigreeIndividual; points.Add(pedigreeIndividual.point); } } //here keys are the couple ids, values are the couples to which they map couplesDictionary = new Dictionary<CoupleID, PedigreeCouple>(); //Link PedigreeIndividuals with their parents in the object model, derive couples foreach (PedigreeIndividual child in individuals) { //determine whether or not each parent exists in the data bool hasMother = individualsDictionary.ContainsKey(child.HraPerson.motherID); bool hasFather = individualsDictionary.ContainsKey(child.HraPerson.fatherID); CoupleID coupleId = new CoupleID(child.HraPerson.fatherID, child.HraPerson.motherID); if (hasMother || hasFather) { //link individuals with their parents in the object model, forming a pointer graph if (hasMother) child.Mother = individualsDictionary[child.HraPerson.motherID]; if (hasFather) child.Father = individualsDictionary[child.HraPerson.fatherID]; //derive couples and store them { //if this individual has parents, set it's "parents" pointer to the //couple representing it's parents (deriving couples from the data as needed). //get the parents couple PedigreeCouple parents = null; { //check if the parents have already been stored as a couple if (couplesDictionary.ContainsKey(coupleId)) //if so, then use the previously stored couple. parents = couplesDictionary[coupleId]; else { //if not store parents as a couple if they haven't been already parents = new PedigreeCouple(child.Mother, child.Father); couplesDictionary[coupleId] = parents; couples.Add(parents); points.Add(parents.point); //link participating individuals with the new couple if (child.Mother != null) if (child.Mother.spouseCouples != null) child.Mother.spouseCouples.Add(parents); if (child.Father != null) if (child.Father.spouseCouples != null) child.Father.spouseCouples.Add(parents); } } //set this individual's "parents" pointer to the parents couple child.Parents = parents; //add the child to the children of the parents couple parents.children.Add(child); } } } // derive the intergenerational edges of the couples graph foreach (PedigreeIndividual parent in individuals) { bool parentHasGrandparents = parent.Parents != null; bool parentIsPartOfACouple = parent.spouseCouples.Count != 0; if (parentHasGrandparents && parentIsPartOfACouple) { foreach (PedigreeCouple parents in parent.spouseCouples) { PedigreeCouple grandparents = parent.Parents; bool intergenerational = true; coupleEdges.Add(new PedigreeCoupleEdge(grandparents, parents, intergenerational)); } } } // derive the intragenerational edges of the couples graph // (from half sibling relationships) foreach (PedigreeIndividual parent in individuals) { if (parent.spouseCouples.Count == 2) { PedigreeCouple u = parent.spouseCouples[0]; PedigreeCouple v = parent.spouseCouples[1]; bool intergenerational = false; coupleEdges.Add(new PedigreeCoupleEdge(u, v, intergenerational)); } //else if (parent.spouseCouples.Count > 2) // throw new Exception("Pedigree not drawable: individual " + parent.relativeID + " has more than two spouses"); } //derive generational levels bool undefinedLevelsRemain = true; int minGenerationalLevel = 0; int maxGenerationalLevel = 0; if (couples.Count > 0) { //assign the seed level couples[0].GenerationalLevel = 0; //propagate the seed level through the graph int NULL = PedigreeCouple.UNDEFINED_GENERATION; while (undefinedLevelsRemain) { undefinedLevelsRemain = false; foreach (PedigreeCoupleEdge e in coupleEdges) { if (e.intergenerational) { PedigreeCouple grandparents = e.u; PedigreeCouple parents = e.v; bool parentsHaveLevel = parents.GenerationalLevel != NULL; bool grandparentsHaveLevel = grandparents.GenerationalLevel != NULL; if (!parentsHaveLevel || !grandparentsHaveLevel) undefinedLevelsRemain = true; if (!parentsHaveLevel && !grandparentsHaveLevel) { undefinedLevelsRemain = false; } if (parentsHaveLevel && !grandparentsHaveLevel) { grandparents.GenerationalLevel = parents.GenerationalLevel - 1; if (grandparents.GenerationalLevel < minGenerationalLevel) minGenerationalLevel = grandparents.GenerationalLevel; } else if (!parentsHaveLevel && grandparentsHaveLevel) { parents.GenerationalLevel = grandparents.GenerationalLevel + 1; if (parents.GenerationalLevel > maxGenerationalLevel) maxGenerationalLevel = parents.GenerationalLevel; } } else { //propagate levels through intragenerational edges (half siblings) if (e.u.GenerationalLevel == NULL) e.u.GenerationalLevel = e.v.GenerationalLevel; else if (e.v.GenerationalLevel == NULL) e.v.GenerationalLevel = e.u.GenerationalLevel; } } } } //normalize the levels foreach (PedigreeCouple couple in couples) couple.GenerationalLevel -= minGenerationalLevel; //store the (normalized) max level in the model this.maxGenerationalLevel = maxGenerationalLevel - minGenerationalLevel; //when a parent set of half siblings (father, mother, father) //is detedted, the mother id is added to this list. If a //couple involving this mother is detected later, this //list is checked to see if she has already been counted. List<int> halfSiblingParentsMotherIds = new List<int>(); //derive individual sets foreach (PedigreeCouple couple in couples) { //add the [mother,father] individual sets if (couple.mother != null && couple.father != null) { if (couple.mother.Parents == null && couple.father.Parents == null) { //if the mother has a single spouse if (couple.mother.spouseCouples.Count == 1) { PedigreeIndividualSet parentsIndividualSet = new PedigreeIndividualSet(couple); parentsIndividualSet.Add(couple.mother); parentsIndividualSet.Add(couple.father); AddIndividualSet(couple.GenerationalLevel, parentsIndividualSet); } //if the mother has a two spouses else if (couple.mother.spouseCouples.Count == 2) { //collapse parents of half siblings into a single individual set if (!halfSiblingParentsMotherIds.Contains(couple.mother.HraPerson.relativeID)) { halfSiblingParentsMotherIds.Add(couple.mother.HraPerson.relativeID); PedigreeIndividualSet parentsIndividualSet = new PedigreeIndividualSet(couple); parentsIndividualSet.Add(couple.mother); parentsIndividualSet.Add(couple.mother.spouseCouples[0].father); parentsIndividualSet.Add(couple.mother.spouseCouples[1].father); AddIndividualSet(couple.GenerationalLevel, parentsIndividualSet); } } } try { //add the children individual sets PedigreeIndividualSet childrenIndividualSet = new PedigreeIndividualSet(couple); foreach (PedigreeIndividual child in couple.children) { childrenIndividualSet.Add(child); foreach (PedigreeCouple pc in child.spouseCouples) { if (pc.mother.HraPerson.relativeID == child.HraPerson.relativeID) { childrenIndividualSet.Add(pc.father); } else { childrenIndividualSet.Add(pc.mother); } } } AddIndividualSet(couple.GenerationalLevel + 1, childrenIndividualSet); } catch (Exception e) { Logger.Instance.WriteToLog(e.ToString()); } } } if (individualsDictionary.ContainsKey(1)) SetBloodRelatives(individualsDictionary[1]); foreach(PedigreeIndividual pi in individuals) { if (pi.bloodRelative == false) { if (pi.spouseCouples.Count == 0) { pi.bloodRelative = true; } else { bool bloodFound = false; foreach (PedigreeCouple pc in pi.spouseCouples) { if ((pc.mother != null) && (pc.father != null)) { if (pc.mother.bloodRelative == true || pc.father.bloodRelative == true) bloodFound = true; } } if (bloodFound == false) { foreach (PedigreeCouple pc in pi.spouseCouples) { if (pc.mother != null) pc.mother.bloodRelative = true; if (pc.father != null) pc.father.bloodRelative = true; } } } } } this.FamilialVariants = p_familyHistory.ReloadFamilialVariants(); }