libStatGen Software 1
Family Class Reference
Collaboration diagram for Family:

Public Member Functions

bool isNuclear ()
 
 Family (Pedigree &ped, int top, int bottom, int serial=0)
 
int ConnectedGroups (IntArray *groupMembership=NULL)
 

Public Attributes

Pedigreeped
 
String famid
 
int serial
 
int first
 
int last
 
int count
 
int founders
 
int nonFounders
 
int mzTwins
 
int * path
 
int generations
 

Detailed Description

Definition at line 27 of file PedigreeFamily.h.

Constructor & Destructor Documentation

◆ Family()

Family::Family ( Pedigree ped,
int  top,
int  bottom,
int  serial = 0 
)

Definition at line 28 of file PedigreeFamily.cpp.

28 :
29 ped(pedigree)
30{
31 serial = _serial;
32 first = _first;
33 last = _last;
34 count = last - first + 1;
35 path = new int [count];
36 famid = ped[first].famid;
37
38 founders = mzTwins = 0;
39
40 for (int i=first; i<=last; i++)
41 if (ped[i].isFounder())
42 {
43 ped[i].traverse = founders;
44 path[founders++] = ped[i].serial;
45 }
46 else
47 {
48 ped[i].traverse = -1;
49 if (ped[i].isMzTwin(ped[i]))
50 for (int j = first; j < i; j++)
51 if (ped[i].isMzTwin(ped[j]))
52 {
53 mzTwins++;
54 break;
55 }
56 }
57
58 nonFounders = count - founders;
59 generations = nonFounders == 0 ? 1 : 2;
60
61 int next = founders;
62 while (next < count)
63 {
64 bool check = false;
65
66 // Create traversal where path ancestors precede their offspring
67 for (int i=first; i<=last; i++)
68 if (ped[i].traverse == -1)
69 {
70 int fatherSerial = ped[i].father->traverse;
71 int motherSerial = ped[i].mother->traverse;
72
73 if (fatherSerial >= 0 && motherSerial >= 0)
74 {
75 check = true;
76
77 ped[i].traverse = next;
78 path[next++] = i;
79
80 if (fatherSerial >= founders || motherSerial >= founders)
81 generations = 3;
82
83 // If this individual is part of a set of MZ twins
84 if (ped[i].zygosity & 1)
85 for (int j = 0; j < ped[i].sibCount; j++)
86 {
87 Person & sib = *ped[i].sibs[j];
88
89 // Insert all co-twins at the same position in traversal
90 // order
91 if (sib.traverse == -1 && ped[i].zygosity == sib.zygosity)
92 {
93 sib.traverse = next;
94 path[next++] = sib.serial;
95 }
96 }
97 }
98 }
99
100 if (!check) ShowInvalidCycles();
101 }
102}

◆ ~Family()

Family::~Family ( )

Definition at line 104 of file PedigreeFamily.cpp.

105{
106 delete [] path;
107}

Member Function Documentation

◆ ConnectedGroups()

int Family::ConnectedGroups ( IntArray groupMembership = NULL)

Definition at line 165 of file PedigreeFamily.cpp.

166{
167 IntArray groups(count);
168
169 // Use the quick union algorithm to identify connected groups
170 groups.SetSequence(0, 1);
171 for (int i = count - 1; i >= founders; i--)
172 {
173 // Lookup parents
174 int group0 = i;
175 int group1 = ped[path[i]].father->traverse;
176 int group2 = ped[path[i]].mother->traverse;
177
178 // Identify their corresponding groupings
179 while (groups[group0] != group0) group0 = groups[group0];
180 while (groups[group1] != group1) group1 = groups[group1];
181 while (groups[group2] != group2) group2 = groups[group2];
182
183 int group = group1 < group2 ? group1 : group2;
184 if (group0 < group) group = group0;
185
186 groups[group0] = groups[group1] = groups[group2] = group;
187 }
188
189 // Count groupings
190 int groupCount = 0;
191 for (int i = 0; i < founders; i++)
192 if (groups[i] == i)
193 groupCount++;
194
195 if (groupMembership == NULL)
196 return groupCount;
197
198 // Flatten tree so all items point to root
199 for (int i = 1; i < count; i++)
200 groups[i] = groups[groups[i]];
201
202 // Update group membership info
203 int group = 0;
204 groupMembership->Dimension(count);
205 for (int i = 0; i < count; i++)
206 if (groups[i] == i)
207 (*groupMembership)[i] = ++group;
208 else
209 (*groupMembership)[i] = (*groupMembership)[groups[i]];
210
211#if 0
212 // This stretch of code outputs family structure and group membership
213 // And should usually be commented out!
214 for (int j = first; j <= last; j++)
215 printf("%s %s %s %s %d %d\n",
216 (const char *) famid, (const char *) ped[j].pid,
217 (const char *) ped[j].fatid, (const char *) ped[j].motid,
218 ped[j].sex, groups[ped[j].traverse]);
219#endif
220
221 return groupCount;
222}

◆ isNuclear()

bool Family::isNuclear ( )
inline

Definition at line 46 of file PedigreeFamily.h.

47 {
48 return (generations == 2) && (founders == 2);
49 }

Member Data Documentation

◆ count

int Family::count

Definition at line 34 of file PedigreeFamily.h.

◆ famid

String Family::famid

Definition at line 31 of file PedigreeFamily.h.

◆ first

int Family::first

Definition at line 33 of file PedigreeFamily.h.

◆ founders

int Family::founders

Definition at line 35 of file PedigreeFamily.h.

◆ generations

int Family::generations

Definition at line 41 of file PedigreeFamily.h.

◆ last

int Family::last

Definition at line 33 of file PedigreeFamily.h.

◆ mzTwins

int Family::mzTwins

Definition at line 37 of file PedigreeFamily.h.

◆ nonFounders

int Family::nonFounders

Definition at line 36 of file PedigreeFamily.h.

◆ path

int* Family::path

Definition at line 38 of file PedigreeFamily.h.

◆ ped

Pedigree& Family::ped

Definition at line 30 of file PedigreeFamily.h.

◆ serial

int Family::serial

Definition at line 32 of file PedigreeFamily.h.


The documentation for this class was generated from the following files: