libStatGen Software 1
Loading...
Searching...
No Matches
PedigreeGlobals Class Reference
Inheritance diagram for PedigreeGlobals:
Collaboration diagram for PedigreeGlobals:

Static Public Member Functions

static int GetTraitID (const char *name)
 
static int GetMarkerID (const char *name)
 
static int GetCovariateID (const char *name)
 
static int GetAffectionID (const char *name)
 
static int GetStringID (const char *name)
 
static int LookupTrait (const char *name)
 
static int LookupMarker (const char *name)
 
static int LookupCovariate (const char *name)
 
static int LookupAffection (const char *name)
 
static int LookupString (const char *name)
 
static void GrowMarkerInfo ()
 
static MarkerInfoGetMarkerInfo (String &name)
 
static MarkerInfoGetMarkerInfo (int marker)
 
static int SortMarkersInMapOrder (IntArray &markers, int chromosome=-1)
 
static void GetOrderedMarkers (IntArray &markers)
 
static void FlagMissingMarkers (IntArray &missingMarkers)
 
static bool MarkerPositionsAvailable ()
 
static bool AlleleFrequenciesAvailable ()
 
static void VerifySexSpecificOrder ()
 
static void LoadAlleleFrequencies (const char *filename, bool required=false)
 
static void LoadAlleleFrequencies (IFILE &file)
 
static void LoadMarkerMap (const char *filename, bool filter=false)
 
static void LoadMarkerMap (IFILE &file, bool filter=false)
 
static void LoadBasepairMap (const char *filename)
 
static void LoadBasepairMap (IFILE &file)
 
static void WriteMapFile (const char *filename)
 
static void WriteMapFile (FILE *file)
 
static void WriteFreqFile (const char *filename, bool old_format=false)
 
static void WriteFreqFile (FILE *file, bool old_format=false)
 
static int LoadAllele (int marker, String &label)
 
static int LoadAllele (MarkerInfo *info, String &label)
 

Static Public Attributes

static int traitCount = 0
 
static int markerCount = 0
 
static int affectionCount = 0
 
static int covariateCount = 0
 
static int stringCount = 0
 
static bool chromosomeX = false
 
static bool sexSpecificMap = false
 
static StringArray traitNames
 
static StringArray covariateNames
 
static StringArray affectionNames
 
static StringArray markerNames
 
static StringArray stringNames
 
static StringIntHash markerLookup
 
static StringIntHash traitLookup
 
static StringIntHash affectionLookup
 
static StringIntHash covariateLookup
 
static StringIntHash stringLookup
 
static int markerInfoCount = 0
 
static int markerInfoSize = 0
 
static MarkerInfo ** markerInfo = NULL
 
static StringHash markerInfoByName
 
static MarkerInfo ** markerInfoByInteger = NULL
 

Detailed Description

Definition at line 107 of file PedigreeGlobals.h.

Constructor & Destructor Documentation

◆ PedigreeGlobals()

PedigreeGlobals::PedigreeGlobals ( )
inline

Definition at line 204 of file PedigreeGlobals.h.

205 {
206 instanceCount++;
207 }

◆ ~PedigreeGlobals()

PedigreeGlobals::~PedigreeGlobals ( )

Definition at line 711 of file PedigreeGlobals.cpp.

712{
713 if (--instanceCount == 0 && markerInfoSize)
714 {
715 for (int i = 0; i < markerInfoCount; i++)
716 delete markerInfo[i];
717 delete [] markerInfo;
718 delete [] markerInfoByInteger;
719 }
720}

Member Function Documentation

◆ AlleleFrequenciesAvailable()

bool PedigreeGlobals::AlleleFrequenciesAvailable ( )
static

Definition at line 806 of file PedigreeGlobals.cpp.

807{
808 for (int i = 0; i < markerInfoCount; i++)
809 if (markerInfo[i]->freq.Length() > 1)
810 return true;
811
812 return false;
813}

◆ FlagMissingMarkers()

void PedigreeGlobals::FlagMissingMarkers ( IntArray missingMarkers)
static

Definition at line 263 of file PedigreeGlobals.cpp.

264{
265 int skipped_markers = 0;
266
267 if (missingMarkers.Length())
268 {
269 StringArray names;
270
271 printf("These markers couldn't be placed and won't be analysed:");
272
273 for (int i = 0; i < missingMarkers.Length(); i++)
274 names.Push(GetMarkerInfo(missingMarkers[i])->name);
275 names.Sort();
276
277 for (int i = 0, line = 80, lines = 0; i < missingMarkers.Length(); i++)
278 {
279 if (line + names[i].Length() + 1 > 79)
280 printf("\n "), line = 3, lines++;
281
282 if (lines < 5)
283 {
284 printf("%s ", (const char *) names[i]);
285 line += names[i].Length() + 1;
286 }
287 else
288 skipped_markers++;
289 }
290
291 if (skipped_markers)
292 printf("as well as %d other unlisted markers...", skipped_markers);
293
294 printf("\n\n");
295 }
296}

◆ GetAffectionID()

int PedigreeGlobals::GetAffectionID ( const char *  name)
static

Definition at line 148 of file PedigreeGlobals.cpp.

149{
150 int idx = affectionLookup.Integer(name);
151
152 if (idx != -1) return idx;
153
154 affectionNames.Add(name);
155 affectionLookup.SetInteger(name, affectionCount);
156 return affectionCount++;
157}

◆ GetCovariateID()

int PedigreeGlobals::GetCovariateID ( const char *  name)
static

Definition at line 159 of file PedigreeGlobals.cpp.

160{
161 int idx = covariateLookup.Integer(name);
162
163 if (idx != -1) return idx;
164
165 covariateNames.Add(name);
166 covariateLookup.SetInteger(name, covariateCount);
167 return covariateCount++;
168}

◆ GetMarkerID()

int PedigreeGlobals::GetMarkerID ( const char *  name)
static

Definition at line 181 of file PedigreeGlobals.cpp.

182{
183 int idx = markerLookup.Integer(name);
184
185 if (idx != -1) return idx;
186
187 markerNames.Add(name);
188 markerLookup.SetInteger(name, markerCount);
189
190 // Grow the marker info key ...
191 if (markerCount == 0)
192 {
193 markerInfoByInteger = new MarkerInfo * [16];
194
195 for (int i = 0; i < 16; i++)
196 markerInfoByInteger[i] = NULL;
197 }
198 else if ((markerCount & (markerCount - 1)) == 0 && markerCount > 15)
199 {
200 MarkerInfo ** newKey = new MarkerInfo * [markerCount * 2];
201
202 for (int i = 0; i < markerCount; i++)
203 newKey[i] = markerInfoByInteger[i];
204
205 for (int i = markerCount; i < markerCount * 2; i++)
206 newKey[i] = NULL;
207
208 delete [] markerInfoByInteger;
209
210 markerInfoByInteger = newKey;
211 }
212
213 return markerCount++;
214}

◆ GetMarkerInfo() [1/2]

MarkerInfo * PedigreeGlobals::GetMarkerInfo ( int  marker)
static

Definition at line 236 of file PedigreeGlobals.cpp.

237{
238 if (markerId >= markerCount)
239 error("Attempted to retrieve MarkerInfo using out-of-bounds index\n");
240
241 if (markerInfoByInteger[markerId] != NULL)
242 return markerInfoByInteger[markerId];
243 else
244 return GetMarkerInfo(markerNames[markerId]);
245}

◆ GetMarkerInfo() [2/2]

MarkerInfo * PedigreeGlobals::GetMarkerInfo ( String name)
static

Definition at line 216 of file PedigreeGlobals.cpp.

217{
218 MarkerInfo * info = (MarkerInfo *) markerInfoByName.Object(name);
219
220 if (info != NULL) return info;
221
222 info = new MarkerInfo(name);
223 markerInfoByName.Add(name, info);
224
225 if (markerInfoCount >= markerInfoSize)
226 GrowMarkerInfo();
227
228 markerInfo[markerInfoCount++] = info;
229
230 int markerId = LookupMarker(name);
231 if (markerId >= 0) markerInfoByInteger[markerId] = info;
232
233 return info;
234}

◆ GetOrderedMarkers()

void PedigreeGlobals::GetOrderedMarkers ( IntArray markers)
static

Definition at line 298 of file PedigreeGlobals.cpp.

299{
300 if (markers.Length() == 0)
301 {
302 markers.Dimension(markerCount);
303 markers.SetSequence(0, 1);
304 }
305
306 MarkerInfo ** subset = new MarkerInfo * [markers.Length()];
307
308 int count = 0;
309 IntArray missingMarkers;
310
311 for (int i = 0; i < markers.Length(); i++)
312 {
313 MarkerInfo * info = GetMarkerInfo(markers[i]);
314
315 if (info->chromosome != -1)
316 subset[count++] = info;
317 else
318 missingMarkers.Push(i);
319 }
320
321 FlagMissingMarkers(missingMarkers);
322
323 QuickSort(subset, count, sizeof(MarkerInfo *),
324 COMPAREFUNC MarkerInfo::ComparePosition);
325
326 markers.Clear();
327 for (int i = 0; i < count; i++)
328 markers.Push(GetMarkerID(subset[i]->name));
329}

◆ GetStringID()

int PedigreeGlobals::GetStringID ( const char *  name)
static

Definition at line 170 of file PedigreeGlobals.cpp.

171{
172 int idx = stringLookup.Integer(name);
173
174 if (idx != -1) return idx;
175
176 stringNames.Add(name);
177 stringLookup.SetInteger(name, stringCount);
178 return stringCount++;
179}

◆ GetTraitID()

int PedigreeGlobals::GetTraitID ( const char *  name)
static

Definition at line 137 of file PedigreeGlobals.cpp.

138{
139 int idx = traitLookup.Integer(name);
140
141 if (idx != -1) return idx;
142
143 traitNames.Add(name);
144 traitLookup.SetInteger(name, traitCount);
145 return traitCount++;
146}

◆ GrowMarkerInfo()

void PedigreeGlobals::GrowMarkerInfo ( )
static

Definition at line 247 of file PedigreeGlobals.cpp.

248{
249 int newSize = markerInfoSize ? 2 * markerInfoSize : 32;
250
251 MarkerInfo ** newArray = new MarkerInfo * [newSize];
252
253 if (markerInfoSize)
254 {
255 memcpy(newArray, markerInfo, sizeof(MarkerInfo *) * markerInfoSize);
256 delete [] markerInfo;
257 }
258
259 markerInfo = newArray;
260 markerInfoSize = newSize;
261}

◆ LoadAllele() [1/2]

int PedigreeGlobals::LoadAllele ( int  marker,
String label 
)
static

Definition at line 815 of file PedigreeGlobals.cpp.

816{
817 return LoadAllele(GetMarkerInfo(marker), token);
818}

◆ LoadAllele() [2/2]

int PedigreeGlobals::LoadAllele ( MarkerInfo info,
String label 
)
static

Definition at line 820 of file PedigreeGlobals.cpp.

821{
822 int allele = info->GetAlleleNumber(token);
823
824 if (allele >= 0) return allele;
825
826 static unsigned char lookup[128];
827 static bool init = false;
828
829 if (!init)
830 {
831 init = true;
832
833 for (int i = 0; i < 128; i++)
834 lookup[i] = 0;
835
836 for (int i = '1'; i <= '9'; i++)
837 lookup[i] = 1;
838
839 lookup[int('a')] = lookup[int('A')] = lookup[int('c')] = lookup[int('C')] = 2;
840 lookup[int('g')] = lookup[int('G')] = lookup[int('t')] = lookup[int('T')] = 2;
841 }
842
843 int first = token[0];
844 bool goodstart = first > 0 && first < 128;
845
846 if (token.Length() == 1 && goodstart && lookup[int(token[0])])
847 return info->NewAllele(token);
848
849 if (!goodstart || lookup[int(token[0])] != 1)
850 return 0;
851
852 int integer = token.AsInteger();
853 token = integer;
854
855 allele = info->GetAlleleNumber(token);
856
857 if (allele > 0)
858 return allele;
859
860 if (integer <= 0) return 0;
861
862 if (integer > 1000000)
863 {
864 static bool warn_user = true;
865
866 if (warn_user)
867 {
868 printf("Some allele numbers for marker %s are > 1000000\n"
869 "All allele numbers >1000000 will be treated as missing\n\n",
870 (const char *) info->name);
871 warn_user = false;
872 }
873
874 return 0;
875 }
876
877 return info->NewAllele(token);
878}

◆ LoadAlleleFrequencies() [1/2]

void PedigreeGlobals::LoadAlleleFrequencies ( const char *  filename,
bool  required = false 
)
static

Definition at line 433 of file PedigreeGlobals.cpp.

434{
435 // This function is often called with an empty string, and not
436 // all implementations of the C library like that ...
437 if (filename[0] == 0)
438 {
439 if (required)
440 error("No name provided for required allele freuquency file\n");
441 else
442 return;
443 }
444
445 // If we get here, the filename is not empty and things should
446 // work as planned
447 IFILE f = ifopen(filename, "rb");
448
449 if (f == NULL)
450 {
451 if (required)
452 error("Failed to open required allele frequency file '%s'",
453 (const char *) filename);
454 else
455 return;
456 }
457
458 LoadAlleleFrequencies(f);
459 ifclose(f);
460}
IFILE ifopen(const char *filename, const char *mode, InputFile::ifileCompression compressionMode=InputFile::DEFAULT)
Open a file with the specified name and mode, using a filename of "-" to indicate stdin/stdout.
Definition InputFile.h:562
int ifclose(IFILE &file)
Close the file.
Definition InputFile.h:580
Class for easily reading/writing files without having to worry about file type (uncompressed,...
Definition InputFile.h:37

◆ LoadAlleleFrequencies() [2/2]

void PedigreeGlobals::LoadAlleleFrequencies ( IFILE file)
static

Definition at line 462 of file PedigreeGlobals.cpp.

463{
464 int done = 0;
465 String buffer;
466 StringArray tokens;
467 MarkerInfo *info = NULL;
468
469 bool need_blank_line = false;
470 int allele_size, old_max, next_allele = 0; // Initialization avoids compiler warning
471
472 while (!ifeof(input) && !done)
473 {
474 int i, j;
475
476 buffer.ReadLine(input);
477
478 tokens.Clear();
479 tokens.AddTokens(buffer, WHITESPACE);
480
481 if (tokens.Length() < 1) continue;
482
483 switch (toupper(tokens[0][0]))
484 {
485 case 'M' :
486 if (tokens.Length() == 1)
487 error("Unnamed marker in allele frequency file");
488 if (info != NULL)
489 need_blank_line |= info->AdjustFrequencies();
490 info = GetMarkerInfo(tokens[1]);
491 info->freq.Clear();
492 info->freq.Push(0.0);
493 next_allele = 1;
494 break;
495 case 'F' :
496 if (info != NULL)
497 for (i = 1; i < tokens.Length(); i++)
498 {
499 buffer = next_allele++;
500
501 int allele = LoadAllele(info, buffer);
502
503 if (allele >= info->freq.Length())
504 {
505 old_max = info->freq.Length();
506 info->freq.Dimension(allele + 1);
507 for (j = old_max; j < allele; j++)
508 info->freq[j] = 0.0;
509 }
510
511 info->freq[allele] = tokens[i].AsDouble();
512 }
513 break;
514 case 'A' :
515 if (info == NULL) continue;
516
517 if (tokens.Length() != 3)
518 error("Error reading named allele frequencies for locus %s\n"
519 "Lines with named alleles should have the format\n"
520 " A allele_label allele_frequency\n\n"
521 "But the following line was read:\n%s\n",
522 (const char *) info->name, (const char *) buffer);
523
524 allele_size = LoadAllele(info, tokens[1]);
525 next_allele = atoi(tokens[1]) + 1;
526
527 if (allele_size < 1)
528 error("Error reading named allele frequencies for locus %s\n"
529 "An invalid allele label was encountered\n",
530 (const char *) info->name);
531
532 if (allele_size >= info->freq.Length())
533 {
534 old_max = info->freq.Length();
535 info->freq.Dimension(allele_size + 1);
536 for (i = old_max; i < allele_size; i++)
537 info->freq[i] = 0.0;
538 }
539
540 info->freq[allele_size] = tokens[2];
541 break;
542 case 'E' :
543 done = 1;
544 break;
545 default :
546 error("Problem in allele frequency file.\n"
547 "Lines in this file should be of two types:\n"
548 " -- Marker name lines begin with an M\n"
549 " -- Frequency lines begin with an F\n\n"
550 "However the following line is different:\n%s\n",
551 (const char *) buffer);
552 }
553 }
554
555 if (info != NULL)
556 need_blank_line |= info->AdjustFrequencies();
557
558 if (need_blank_line) printf("\n");
559}
int ifeof(IFILE file)
Check to see if we have reached the EOF (returns 0 if not EOF).
Definition InputFile.h:654

◆ LoadBasepairMap() [1/2]

void PedigreeGlobals::LoadBasepairMap ( const char *  filename)
static

Definition at line 656 of file PedigreeGlobals.cpp.

657{
658 IFILE f = ifopen(filename, "rb");
659 if (f == NULL)
660 error("The map file [%s] could not be opened\n\n"
661 "Please check that the filename is correct and that the file is\n"
662 "not being used by another program", filename);
663 LoadBasepairMap(f);
664 ifclose(f);
665}

◆ LoadBasepairMap() [2/2]

void PedigreeGlobals::LoadBasepairMap ( IFILE file)
static

Definition at line 667 of file PedigreeGlobals.cpp.

668{
669 String buffer;
670 StringArray tokens;
671
672 sexSpecificMap = false;
673
674 while (!ifeof(input))
675 {
676 buffer.ReadLine(input);
677
678 tokens.Clear();
679 tokens.AddTokens(buffer, WHITESPACE);
680
681 if (tokens.Length() < 1) continue;
682
683 if (tokens.Length() != 3)
684 error("Error reading map file\n"
685 "Each line in this file should include 3 fields:\n"
686 "CHROMOSOME, MARKER_NAME, and POSITION\n"
687 "However the following line has %d fields\n%s\n",
688 tokens.Length(), (const char *) buffer);
689
690 bool previous_state = String::caseSensitive;
691 String::caseSensitive = false;
692
693 if ((tokens[0] == "CHR" || tokens[0] == "CHROMOSOME") &&
694 (tokens[1] == "MARKER" || tokens[1] == "MARKER_NAME" || tokens[1] == "MRK") &&
695 (tokens[2] == "BASEPAIR" || tokens[2] == "POS" || tokens[2] == "POSITION"))
696 continue;
697
698 String::caseSensitive = previous_state;
699
700 MarkerInfo * info = GetMarkerInfo(tokens[1]);
701
702 int chr = (tokens[0][0] == 'x' || tokens[0][0] == 'X') ? 999 : (int) tokens[0];
703
704 info->chromosome = chr;
705 info->position = (double) tokens[2];
706 }
707}

◆ LoadMarkerMap() [1/2]

void PedigreeGlobals::LoadMarkerMap ( const char *  filename,
bool  filter = false 
)
static

Definition at line 561 of file PedigreeGlobals.cpp.

562{
563 IFILE f = ifopen(filename, "rb");
564 if (f == NULL) return;
565 LoadMarkerMap(f, filter);
566 ifclose(f);
567}

◆ LoadMarkerMap() [2/2]

void PedigreeGlobals::LoadMarkerMap ( IFILE file,
bool  filter = false 
)
static

Definition at line 569 of file PedigreeGlobals.cpp.

570{
571 String buffer;
572 StringArray tokens;
573 bool first_pass = true;
574
575 while (!ifeof(input))
576 {
577 buffer.ReadLine(input);
578
579 tokens.Clear();
580 tokens.AddTokens(buffer, WHITESPACE);
581
582 if (tokens.Length() < 1) continue;
583
584 if (first_pass)
585 {
586 sexSpecificMap = (tokens.Length() == 5);
587
588 // if (sexSpecificMap)
589 // printf("\n Found sex-specific map ...\n\n");
590
591 first_pass = false;
592 }
593
594 if (tokens.Length() != 3 && !sexSpecificMap)
595 error("Error reading map file\n"
596 "Each line in this file should include 3 fields:\n"
597 "CHROMOSOME, MARKER_NAME, and POSITION\n"
598 "However the following line has %d fields\n%s\n",
599 tokens.Length(), (const char *) buffer);
600
601 if (tokens.Length() != 5 && sexSpecificMap)
602 error("Error reading map file\n"
603 "Each line in this file should include 5 fields:\n\n"
604 "CHROMOSOME, MARKER_NAME, SEX_AVERAGED_POS, FEMALE_POS AND MALE_POS\n\n"
605 "However the following line has %d fields\n%s\n",
606 tokens.Length(), (const char *) buffer);
607
608 bool previous_state = String::caseSensitive;
609 String::caseSensitive = false;
610
611 if ((tokens[0] == "CHR" || tokens[0] == "CHROMOSOME") &&
612 (tokens[1] == "MARKER" || tokens[1] == "MARKER_NAME" || tokens[1] == "MRK") &&
613 (tokens[2] == "KOSAMBI" || tokens[2] == "POS" || tokens[2] == "POSITION" ||
614 tokens[2] == "SEX_AVERAGED_POS" || tokens[2] == "CM" || tokens[2] == "HALDANE"))
615 continue;
616
617 String::caseSensitive = previous_state;
618
619 if (filter)
620 if (LookupMarker(tokens[1]) < 0)
621 continue;
622
623 MarkerInfo * info = GetMarkerInfo(tokens[1]);
624
625 int chr = (tokens[0][0] == 'x' || tokens[0][0] == 'X') ? 999 : (int) tokens[0];
626
627 info->chromosome = chr;
628 info->position = (double) tokens[2] * 0.01;
629
630 if (sexSpecificMap)
631 {
632 char * flag;
633
634 double female = strtod(tokens[3], &flag);
635 if (*flag)
636 error("In the map file, the female cM position for marker\n"
637 "%s is %s. This is not a valid number.",
638 (const char *) tokens[1], (const char *) tokens[3]);
639
640 double male = strtod(tokens[4], &flag);
641 if (*flag)
642 error("In the map file, the male cM position for marker\n"
643 "%s is %s. This is not a valid number.",
644 (const char *) tokens[1], (const char *) tokens[4]);
645
646 info->positionFemale = (double) female * 0.01;
647 info->positionMale = (double) male * 0.01;
648 }
649 else
650 info->positionFemale = info->positionMale = info->position;
651 }
652
653 if (sexSpecificMap) VerifySexSpecificOrder();
654}

◆ LookupAffection()

static int PedigreeGlobals::LookupAffection ( const char *  name)
inlinestatic

Definition at line 158 of file PedigreeGlobals.h.

159 {
160 return affectionLookup.Integer(name);
161 }

◆ LookupCovariate()

static int PedigreeGlobals::LookupCovariate ( const char *  name)
inlinestatic

Definition at line 154 of file PedigreeGlobals.h.

155 {
156 return covariateLookup.Integer(name);
157 }

◆ LookupMarker()

static int PedigreeGlobals::LookupMarker ( const char *  name)
inlinestatic

Definition at line 150 of file PedigreeGlobals.h.

151 {
152 return markerLookup.Integer(name);
153 }

◆ LookupString()

static int PedigreeGlobals::LookupString ( const char *  name)
inlinestatic

Definition at line 162 of file PedigreeGlobals.h.

163 {
164 return stringLookup.Integer(name);
165 }

◆ LookupTrait()

static int PedigreeGlobals::LookupTrait ( const char *  name)
inlinestatic

Definition at line 146 of file PedigreeGlobals.h.

147 {
148 return traitLookup.Integer(name);
149 }

◆ MarkerPositionsAvailable()

bool PedigreeGlobals::MarkerPositionsAvailable ( )
static

Definition at line 797 of file PedigreeGlobals.cpp.

798{
799 for (int i = 0; i < markerInfoCount; i++)
800 if (markerInfo[i]->chromosome != -1)
801 return true;
802
803 return false;
804}

◆ SortMarkersInMapOrder()

int PedigreeGlobals::SortMarkersInMapOrder ( IntArray markers,
int  chromosome = -1 
)
static

Definition at line 331 of file PedigreeGlobals.cpp.

332{
333 if (markers.Length() == 0)
334 {
335 markers.Dimension(markerCount);
336 markers.SetSequence(0, 1);
337 }
338
339 MarkerInfo ** subset = new MarkerInfo * [markers.Length()];
340
341 int count = 0;
342 IntArray missingMarkers;
343
344 for (int i = 0; i < markers.Length(); i++)
345 {
346 MarkerInfo * info = GetMarkerInfo(markers[i]);
347
348 if (info->chromosome != -1)
349 subset[count++] = info;
350 else if (chromosome == -1)
351 missingMarkers.Push(i);
352 }
353
354 if (chromosome == -1)
355 FlagMissingMarkers(missingMarkers);
356
357 QuickSort(subset, count, sizeof(MarkerInfo *),
358 COMPAREFUNC MarkerInfo::ComparePosition);
359
360 markers.Clear();
361
362 int current_chromosome = -1, next_chromosome = 0;
363
364 for (int i = 0; i < count; i++)
365 if (subset[i]->chromosome < chromosome)
366 continue;
367 else if (current_chromosome == -1 ||
368 subset[i]->chromosome == current_chromosome)
369 {
370 markers.Push(GetMarkerID(subset[i]->name));
371 current_chromosome = subset[i]->chromosome;
372 }
373 else if (!next_chromosome)
374 {
375 next_chromosome = subset[i]->chromosome;
376 break;
377 }
378
379 delete [] subset;
380
381 return next_chromosome;
382}

◆ VerifySexSpecificOrder()

void PedigreeGlobals::VerifySexSpecificOrder ( )
static

Definition at line 384 of file PedigreeGlobals.cpp.

385{
386 if (markerCount <= 1)
387 return;
388
389 MarkerInfo ** sortedMarkers = new MarkerInfo * [markerCount];
390
391 for (int i = 0; i < markerCount; i++)
392 sortedMarkers[i] = GetMarkerInfo(i);
393
394 QuickSort(sortedMarkers, markerCount, sizeof(MarkerInfo *),
395 COMPAREFUNC MarkerInfo::ComparePosition);
396
397 double prev_female = sortedMarkers[0]->positionFemale;
398 double prev_male = sortedMarkers[0]->positionMale;
399 double curr_female, curr_male;
400
401 int prev_chromosome = sortedMarkers[0]->chromosome;
402 int curr_chromosome;
403
404 for (int i = 1; i < markerCount; i++)
405 {
406 curr_chromosome = sortedMarkers[i]->chromosome;
407 curr_female = sortedMarkers[i]->positionFemale;
408 curr_male = sortedMarkers[i]->positionMale;
409
410 if (curr_chromosome == prev_chromosome &&
411 (curr_female < prev_female || curr_male < prev_male))
412 error("Sex-specific and sex-averaged maps are inconsistent.\n\n"
413 "In the sex-averaged map, marker %s (%.2f cM) follows marker %s (%.2f cM).\n"
414 "In the %smale map, marker %s (%.2f cM) PRECEDES marker %s (%.2f cM).\n",
415 (const char *) sortedMarkers[i]->name,
416 sortedMarkers[i]->position * 100,
417 (const char *) sortedMarkers[i-1]->name,
418 sortedMarkers[i-1]->position * 100,
419 curr_female < prev_female ? "fe" : "",
420 (const char *) sortedMarkers[i]->name,
421 (curr_female < prev_female ? curr_female : curr_male) * 100,
422 (const char *) sortedMarkers[i-1]->name,
423 (curr_female < prev_female ? prev_female : prev_male) * 100);
424
425 prev_chromosome = curr_chromosome;
426 prev_female = curr_female;
427 prev_male = curr_male;
428 }
429
430 delete [] sortedMarkers;
431}

◆ WriteFreqFile() [1/2]

void PedigreeGlobals::WriteFreqFile ( const char *  filename,
bool  old_format = false 
)
static

Definition at line 763 of file PedigreeGlobals.cpp.

764{
765 FILE * output = fopen(filename, "wt");
766
767 if (output == NULL)
768 error("Creating allele frequency file \"%s\"", filename);
769
770 WriteFreqFile(output, old_format);
771 fclose(output);
772}

◆ WriteFreqFile() [2/2]

void PedigreeGlobals::WriteFreqFile ( FILE *  file,
bool  old_format = false 
)
static

Definition at line 774 of file PedigreeGlobals.cpp.

775{
776 for (int i = 0; i < markerInfoCount; i++)
777 {
778 MarkerInfo * info = markerInfo[i];
779
780 if (info->freq.Length() == 0) continue;
781
782 fprintf(output, "M %s\n", (const char *) info->name);
783
784 if (old_format && info->alleleLabels.Length() == 0)
785 for (int j = 1; j < info->freq.Length(); j++)
786 fprintf(output, "%s%.5f%s",
787 j % 7 == 1 ? "F " : "", info->freq[j],
788 j == info->freq.Length() - 1 ? "\n" : j % 7 == 0 ? "\n" : " ");
789 else
790 for (int j = 1; j < info->freq.Length(); j++)
791 if (info->freq[j] > 1e-7)
792 fprintf(output, "A %5s %.5f\n",
793 (const char *) info->GetAlleleLabel(j), info->freq[j]);
794 }
795}

◆ WriteMapFile() [1/2]

void PedigreeGlobals::WriteMapFile ( const char *  filename)
static

Definition at line 722 of file PedigreeGlobals.cpp.

723{
724 if (!MarkerPositionsAvailable())
725 return;
726
727 FILE * output = fopen(filename, "wt");
728
729 if (output == NULL)
730 error("Creating map file \"%s\"", filename);
731
732 WriteMapFile(output);
733 fclose(output);
734}

◆ WriteMapFile() [2/2]

void PedigreeGlobals::WriteMapFile ( FILE *  file)
static

Definition at line 736 of file PedigreeGlobals.cpp.

737{
738 if (!sexSpecificMap)
739 fprintf(output, "CHR MARKER POS\n");
740 else
741 fprintf(output, "CHR MARKER POS POSF POSM\n");
742
743 for (int i = 0; i < markerInfoCount; i++)
744 {
745 if (markerInfo[i]->chromosome != -1)
746 {
747 if (!sexSpecificMap)
748 fprintf(output, "%3d %-10s %g\n",
749 markerInfo[i]->chromosome,
750 (const char *) markerInfo[i]->name,
751 markerInfo[i]->position * 100.0);
752 else
753 fprintf(output, "%3d %-10s %g %g %g\n",
754 markerInfo[i]->chromosome,
755 (const char *) markerInfo[i]->name,
756 markerInfo[i]->position * 100.0,
757 markerInfo[i]->positionFemale * 100.0,
758 markerInfo[i]->positionMale * 100.0);
759 }
760 }
761}

Member Data Documentation

◆ affectionCount

int PedigreeGlobals::affectionCount = 0
static

Definition at line 112 of file PedigreeGlobals.h.

◆ affectionLookup

StringIntHash PedigreeGlobals::affectionLookup
static

Definition at line 129 of file PedigreeGlobals.h.

◆ affectionNames

StringArray PedigreeGlobals::affectionNames
static

Definition at line 124 of file PedigreeGlobals.h.

◆ chromosomeX

bool PedigreeGlobals::chromosomeX = false
static

Definition at line 117 of file PedigreeGlobals.h.

◆ covariateCount

int PedigreeGlobals::covariateCount = 0
static

Definition at line 113 of file PedigreeGlobals.h.

◆ covariateLookup

StringIntHash PedigreeGlobals::covariateLookup
static

Definition at line 130 of file PedigreeGlobals.h.

◆ covariateNames

StringArray PedigreeGlobals::covariateNames
static

Definition at line 123 of file PedigreeGlobals.h.

◆ markerCount

int PedigreeGlobals::markerCount = 0
static

Definition at line 111 of file PedigreeGlobals.h.

◆ markerInfo

MarkerInfo ** PedigreeGlobals::markerInfo = NULL
static

Definition at line 169 of file PedigreeGlobals.h.

◆ markerInfoByInteger

MarkerInfo ** PedigreeGlobals::markerInfoByInteger = NULL
static

Definition at line 171 of file PedigreeGlobals.h.

◆ markerInfoByName

StringHash PedigreeGlobals::markerInfoByName
static

Definition at line 170 of file PedigreeGlobals.h.

◆ markerInfoCount

int PedigreeGlobals::markerInfoCount = 0
static

Definition at line 167 of file PedigreeGlobals.h.

◆ markerInfoSize

int PedigreeGlobals::markerInfoSize = 0
static

Definition at line 168 of file PedigreeGlobals.h.

◆ markerLookup

StringIntHash PedigreeGlobals::markerLookup
static

Definition at line 127 of file PedigreeGlobals.h.

◆ markerNames

StringArray PedigreeGlobals::markerNames
static

Definition at line 125 of file PedigreeGlobals.h.

◆ sexSpecificMap

bool PedigreeGlobals::sexSpecificMap = false
static

Definition at line 120 of file PedigreeGlobals.h.

◆ stringCount

int PedigreeGlobals::stringCount = 0
static

Definition at line 114 of file PedigreeGlobals.h.

◆ stringLookup

StringIntHash PedigreeGlobals::stringLookup
static

Definition at line 131 of file PedigreeGlobals.h.

◆ stringNames

StringArray PedigreeGlobals::stringNames
static

Definition at line 126 of file PedigreeGlobals.h.

◆ traitCount

int PedigreeGlobals::traitCount = 0
static

Definition at line 110 of file PedigreeGlobals.h.

◆ traitLookup

StringIntHash PedigreeGlobals::traitLookup
static

Definition at line 128 of file PedigreeGlobals.h.

◆ traitNames

StringArray PedigreeGlobals::traitNames
static

Definition at line 122 of file PedigreeGlobals.h.


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