libStatGen Software  1
Pedigree.h
00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef _PEDIGREE_H_
00019 #define _PEDIGREE_H_
00020 
00021 #include "Constant.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include "PedigreeAlleles.h"
00026 #include "PedigreePerson.h"
00027 #include "PedigreeGlobals.h"
00028 #include "PedigreeFamily.h"
00029 #include "PedigreeDescription.h"
00030 #include "PedigreeAlleleFreq.h"
00031 
00032 class Pedigree : public PedigreeGlobals
00033 {
00034 public:
00035     static bool          sexAsCovariate;
00036     static String        missing;
00037 
00038     int                  size;
00039     int                  count;
00040     Person **            persons;
00041     int                  familyCount;
00042     Family **            families;
00043     int                  haveTwins;
00044 
00045     PedigreeDescription  pd;
00046     PedigreeDescription *multiPd;
00047     int                  multiFileCount;
00048 
00049     Pedigree();
00050     ~Pedigree();
00051 
00052     void Prepare(IFILE & input);       // Read pedigree parameters from data file
00053     void Load(IFILE & input);          // Read pedigree from pedigree file
00054     void LoadMendel(IFILE & input);    // Read pedigree in Mendel format
00055     void Prepare(const char * input);  // Read pedigree parameters from named file
00056 
00057     // Read pedigree parameters from named file, stop program on failure
00058     // depending on setting of allow failures
00059     void Load(const char * input, bool allowFailures = false);
00060 
00061     // I/O related utility functions
00062     int  TranslateSexCode(const char * code, bool & failure);
00063 
00064     void PrepareDichotomization();   // Register dummy affections for each trait
00065     int  Dichotomize(int trait, double mean = _NAN_);
00066     void DichotomizeAll(double mean = _NAN_);
00067 
00068     void WriteDataFile(FILE * output);           // Write data file
00069     void WritePedigreeFile(FILE * output);       // Write pedigree file
00070     void WriteDataFile(const char * output);     // Write named data file
00071     void WritePedigreeFile(const char * output); // Write named pedigree file
00072     void WritePerson(FILE * output, int who,     // Write a single person
00073                      const char * famid = NULL,              // if supplied, famid, pid,
00074                      const char * pid = NULL,                // fatid and motid allow a
00075                      const char * fatid = NULL,              // pedigree or person to
00076                      const char * motid = NULL);             // be renamed / restructured
00077     void WriteRecodedPerson(                     // Like write person, but uses
00078         FILE * output, int who,                 // user supplied markerInfo
00079         MarkerInfo ** markerInfo,               // array to recode marker
00080         const char * famid = NULL,              // alleles as they are written
00081         const char * pid = NULL,
00082         const char * fatid = NULL,
00083         const char * motid = NULL);
00084 
00085     void Sort();                              // Sorts the pedigree items
00086     Family * FindFamily(const char * famid);  // Find a family
00087     Person * FindPerson(const char * famid,   // Find an individual
00088                         const char * pid);
00089 
00090     // functions dealing with genetic markers
00091     // Counts the alleles at a marker
00092     int  CountAlleles(int marker);
00093 
00094     // Lumps together rare alleles and, depending on reorder flag,
00095     // sorts alleles so the most common allele has the lowest index
00096     void LumpAlleles(double treshold, bool reorder = true);
00097 
00098     // Calculate allele frequencies
00099     void EstimateFrequencies(int estimator, bool quiet = false);
00100 
00101     // shorthand operators
00102     Person & operator [](int i)
00103     {
00104         return *(persons[i]);
00105     }
00106 
00107     // Perform a basic inheritance check
00108     bool InheritanceCheck(bool abortIfInconsistent = true);
00109     bool AutosomalCheck();
00110     bool SexLinkedCheck();
00111     bool TwinCheck();
00112 
00113     // Merge twins into a single individual
00114     void MergeTwins();
00115 
00116     // Remove individuals with no data from pedigree
00117     void Trim(bool quiet = false, int * informative = NULL);
00118 
00119     // Add a single individual to a pedigree
00120     void AddPerson(const char * famid, const char * pid,
00121                    const char * fatid, const char * motid,
00122                    int sex, bool delay_sort = false);
00123 
00124     // Add all individuals in family with famid = id to new_ped
00125     void ExtractFamily(int id, Pedigree & new_ped);
00126     // Add individuals with affection status target_status for affection a to new_ped
00127     void ExtractOnAffection(int a, Pedigree & new_ped, int target_status = 2);
00128 
00129     // Remove all covariate, affection and genotype information from persons for which filter[i] = 0
00130     void Filter(IntArray & filter);
00131 
00132     // Reports memory usage for storing the pedigree
00133     void ShowMemoryInfo();
00134 
00135 private:
00136     void Grow();
00137     void Add(Person & rhs);
00138 
00139     static int ComparePersons(const Person ** p1, const Person ** p2);
00140     static int CompareParents(const Person ** p1, const Person ** p2);
00141 
00142     void MakeSibships();
00143     void MakeFamilies();
00144 
00145     Person * FindPerson(const char * famid, const char * pid, int universe);
00146 
00147     void ShowTrimHeader(bool & flag);
00148 };
00149 
00150 #endif
00151 
00152 
00153 
00154 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends