PedigreeGlobals.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __PEDGLOBALS_H__
00019 #define __PEDGLOBALS_H__
00020
00021 #include "Constant.h"
00022 #include "StringArray.h"
00023 #include "StringHash.h"
00024 #include "IntArray.h"
00025 #include "MathVector.h"
00026
00027 #include <iostream>
00028
00029 class MarkerInfo
00030 {
00031 public:
00032
00033 int chromosome;
00034
00035
00036 double position;
00037 double positionMale;
00038 double positionFemale;
00039
00040 Vector freq;
00041 String name;
00042 StringArray alleleLabels;
00043 StringIntHash alleleNumbers;
00044
00045 MarkerInfo(String & string)
00046 {
00047 serial = count++;
00048 name = string;
00049 chromosome = -1;
00050 position = 0.0;
00051 positionMale = 0.0;
00052 positionFemale = 0.0;
00053 }
00054
00055 bool AdjustFrequencies();
00056
00057 static int ComparePosition(MarkerInfo ** left, MarkerInfo ** right);
00058
00059 String GetAlleleLabel(int allele);
00060 int GetAlleleNumber(char label) const
00061 {
00062 String labelString;
00063 labelString = label;
00064 return(GetAlleleNumber(labelString));
00065 }
00066 int GetAlleleNumber(const String & label) const
00067 {
00068 return label == "0" ? 0 : alleleNumbers.Integer(label);
00069 }
00070
00071 int NewAllele(char label)
00072 {
00073 String labelString;
00074 labelString = label;
00075 return(NewAllele(labelString));
00076 }
00077
00078 int NewAllele(const String & label);
00079
00080
00081
00082 void UpdateSerial()
00083 {
00084 serial = count++;
00085 }
00086
00087 void IndexAlleles();
00088
00089 int CountAlleles()
00090 {
00091 return alleleLabels.Length() ? alleleLabels.Length() - 1 : 0;
00092 }
00093
00094 private:
00095
00096 static int count;
00097 static String label;
00098
00099
00100
00101
00102 int serial;
00103 };
00104
00105 std::ostream &operator << (std::ostream &stream, MarkerInfo &m);
00106
00107 class PedigreeGlobals
00108 {
00109 public:
00110 static int traitCount;
00111 static int markerCount;
00112 static int affectionCount;
00113 static int covariateCount;
00114 static int stringCount;
00115
00116
00117 static bool chromosomeX;
00118
00119
00120 static bool sexSpecificMap;
00121
00122 static StringArray traitNames;
00123 static StringArray covariateNames;
00124 static StringArray affectionNames;
00125 static StringArray markerNames;
00126 static StringArray stringNames;
00127 static StringIntHash markerLookup;
00128 static StringIntHash traitLookup;
00129 static StringIntHash affectionLookup;
00130 static StringIntHash covariateLookup;
00131 static StringIntHash stringLookup;
00132
00133
00134
00135
00136
00137 static int GetTraitID(const char * name);
00138 static int GetMarkerID(const char * name);
00139 static int GetCovariateID(const char * name);
00140 static int GetAffectionID(const char * name);
00141 static int GetStringID(const char * name);
00142
00143
00144
00145
00146 static int LookupTrait(const char * name)
00147 {
00148 return traitLookup.Integer(name);
00149 }
00150 static int LookupMarker(const char * name)
00151 {
00152 return markerLookup.Integer(name);
00153 }
00154 static int LookupCovariate(const char * name)
00155 {
00156 return covariateLookup.Integer(name);
00157 }
00158 static int LookupAffection(const char * name)
00159 {
00160 return affectionLookup.Integer(name);
00161 }
00162 static int LookupString(const char * name)
00163 {
00164 return stringLookup.Integer(name);
00165 }
00166
00167 static int markerInfoCount;
00168 static int markerInfoSize;
00169 static MarkerInfo ** markerInfo;
00170 static StringHash markerInfoByName;
00171 static MarkerInfo ** markerInfoByInteger;
00172
00173 static void GrowMarkerInfo();
00174 static MarkerInfo * GetMarkerInfo(String & name);
00175 static MarkerInfo * GetMarkerInfo(int marker);
00176
00177 static int SortMarkersInMapOrder(IntArray & markers, int chromosome = -1);
00178 static void GetOrderedMarkers(IntArray & markers);
00179 static void FlagMissingMarkers(IntArray & missingMarkers);
00180
00181 static bool MarkerPositionsAvailable();
00182 static bool AlleleFrequenciesAvailable();
00183
00184 static void VerifySexSpecificOrder();
00185
00186 static void LoadAlleleFrequencies(const char * filename, bool required = false);
00187 static void LoadAlleleFrequencies(IFILE & file);
00188
00189 static void LoadMarkerMap(const char * filename, bool filter = false);
00190 static void LoadMarkerMap(IFILE & file, bool filter = false);
00191
00192 static void LoadBasepairMap(const char * filename);
00193 static void LoadBasepairMap(IFILE & file);
00194
00195 static void WriteMapFile(const char * filename);
00196 static void WriteMapFile(FILE * file);
00197
00198 static void WriteFreqFile(const char * filename, bool old_format = false);
00199 static void WriteFreqFile(FILE * file, bool old_format = false);
00200
00201 static int LoadAllele(int marker, String & label);
00202 static int LoadAllele(MarkerInfo * info, String & label);
00203
00204 PedigreeGlobals()
00205 {
00206 instanceCount++;
00207 }
00208 ~PedigreeGlobals();
00209
00210 private:
00211 static int instanceCount;
00212
00213 };
00214
00215 #endif
00216