libStatGen Software  1
Pedigree.h
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _PEDIGREE_H_
19 #define _PEDIGREE_H_
20 
21 #include "Constant.h"
22 
23 #include <stdio.h>
24 
25 #include "PedigreeAlleles.h"
26 #include "PedigreePerson.h"
27 #include "PedigreeGlobals.h"
28 #include "PedigreeFamily.h"
29 #include "PedigreeDescription.h"
30 #include "PedigreeAlleleFreq.h"
31 
32 class Pedigree : public PedigreeGlobals
33 {
34 public:
35  static bool sexAsCovariate;
36  static String missing;
37 
38  int size;
39  int count;
40  Person ** persons;
41  int familyCount;
42  Family ** families;
43  int haveTwins;
44 
46  PedigreeDescription *multiPd;
47  int multiFileCount;
48 
49  Pedigree();
50  ~Pedigree();
51 
52  void Prepare(IFILE & input); // Read pedigree parameters from data file
53  void Load(IFILE & input); // Read pedigree from pedigree file
54  void LoadMendel(IFILE & input); // Read pedigree in Mendel format
55  void Prepare(const char * input); // Read pedigree parameters from named file
56 
57  // Read pedigree parameters from named file, stop program on failure
58  // depending on setting of allow failures
59  void Load(const char * input, bool allowFailures = false);
60 
61  // I/O related utility functions
62  int TranslateSexCode(const char * code, bool & failure);
63 
64  void PrepareDichotomization(); // Register dummy affections for each trait
65  int Dichotomize(int trait, double mean = _NAN_);
66  void DichotomizeAll(double mean = _NAN_);
67 
68  void WriteDataFile(FILE * output); // Write data file
69  void WritePedigreeFile(FILE * output); // Write pedigree file
70  void WriteDataFile(const char * output); // Write named data file
71  void WritePedigreeFile(const char * output); // Write named pedigree file
72  void WritePerson(FILE * output, int who, // Write a single person
73  const char * famid = NULL, // if supplied, famid, pid,
74  const char * pid = NULL, // fatid and motid allow a
75  const char * fatid = NULL, // pedigree or person to
76  const char * motid = NULL); // be renamed / restructured
77  void WriteRecodedPerson( // Like write person, but uses
78  FILE * output, int who, // user supplied markerInfo
79  MarkerInfo ** markerInfo, // array to recode marker
80  const char * famid = NULL, // alleles as they are written
81  const char * pid = NULL,
82  const char * fatid = NULL,
83  const char * motid = NULL);
84 
85  void Sort(); // Sorts the pedigree items
86  Family * FindFamily(const char * famid); // Find a family
87  Person * FindPerson(const char * famid, // Find an individual
88  const char * pid);
89 
90  // functions dealing with genetic markers
91  // Counts the alleles at a marker
92  int CountAlleles(int marker);
93 
94  // Lumps together rare alleles and, depending on reorder flag,
95  // sorts alleles so the most common allele has the lowest index
96  void LumpAlleles(double treshold, bool reorder = true);
97 
98  // Calculate allele frequencies
99  void EstimateFrequencies(int estimator, bool quiet = false);
100 
101  // shorthand operators
102  Person & operator [](int i)
103  {
104  return *(persons[i]);
105  }
106 
107  // Perform a basic inheritance check
108  bool InheritanceCheck(bool abortIfInconsistent = true);
109  bool AutosomalCheck();
110  bool SexLinkedCheck();
111  bool TwinCheck();
112 
113  // Merge twins into a single individual
114  void MergeTwins();
115 
116  // Remove individuals with no data from pedigree
117  void Trim(bool quiet = false, int * informative = NULL);
118 
119  // Add a single individual to a pedigree
120  void AddPerson(const char * famid, const char * pid,
121  const char * fatid, const char * motid,
122  int sex, bool delay_sort = false);
123 
124  // Add all individuals in family with famid = id to new_ped
125  void ExtractFamily(int id, Pedigree & new_ped);
126  // Add individuals with affection status target_status for affection a to new_ped
127  void ExtractOnAffection(int a, Pedigree & new_ped, int target_status = 2);
128 
129  // Remove all covariate, affection and genotype information from persons for which filter[i] = 0
130  void Filter(IntArray & filter);
131 
132  // Reports memory usage for storing the pedigree
133  void ShowMemoryInfo();
134 
135 private:
136  void Grow();
137  void Add(Person & rhs);
138 
139  static int ComparePersons(const Person ** p1, const Person ** p2);
140  static int CompareParents(const Person ** p1, const Person ** p2);
141 
142  void MakeSibships();
143  void MakeFamilies();
144 
145  Person * FindPerson(const char * famid, const char * pid, int universe);
146 
147  void ShowTrimHeader(bool & flag);
148 };
149 
150 #endif
151 
152 
153 
154 
Class for easily reading/writing files without having to worry about file type (uncompressed, gzip, bgzf) when reading.
Definition: InputFile.h:36