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(const String & label) const
00061 {
00062 return label == "0" ? 0 : alleleNumbers.Integer(label);
00063 }
00064
00065 int NewAllele(const String & label);
00066
00067
00068
00069 void UpdateSerial()
00070 {
00071 serial = count++;
00072 }
00073
00074 void IndexAlleles();
00075
00076 int CountAlleles()
00077 {
00078 return alleleLabels.Length() ? alleleLabels.Length() - 1 : 0;
00079 }
00080
00081 private:
00082
00083 static int count;
00084 static String label;
00085
00086
00087
00088
00089 int serial;
00090 };
00091
00092 std::ostream &operator << (std::ostream &stream, MarkerInfo &m);
00093
00094 class PedigreeGlobals
00095 {
00096 public:
00097 static int traitCount;
00098 static int markerCount;
00099 static int affectionCount;
00100 static int covariateCount;
00101 static int stringCount;
00102
00103
00104 static bool chromosomeX;
00105
00106
00107 static bool sexSpecificMap;
00108
00109 static StringArray traitNames;
00110 static StringArray covariateNames;
00111 static StringArray affectionNames;
00112 static StringArray markerNames;
00113 static StringArray stringNames;
00114 static StringIntHash markerLookup;
00115 static StringIntHash traitLookup;
00116 static StringIntHash affectionLookup;
00117 static StringIntHash covariateLookup;
00118 static StringIntHash stringLookup;
00119
00120
00121
00122
00123
00124 static int GetTraitID(const char * name);
00125 static int GetMarkerID(const char * name);
00126 static int GetCovariateID(const char * name);
00127 static int GetAffectionID(const char * name);
00128 static int GetStringID(const char * name);
00129
00130
00131
00132
00133 static int LookupTrait(const char * name)
00134 {
00135 return traitLookup.Integer(name);
00136 }
00137 static int LookupMarker(const char * name)
00138 {
00139 return markerLookup.Integer(name);
00140 }
00141 static int LookupCovariate(const char * name)
00142 {
00143 return covariateLookup.Integer(name);
00144 }
00145 static int LookupAffection(const char * name)
00146 {
00147 return affectionLookup.Integer(name);
00148 }
00149 static int LookupString(const char * name)
00150 {
00151 return stringLookup.Integer(name);
00152 }
00153
00154 static int markerInfoCount;
00155 static int markerInfoSize;
00156 static MarkerInfo ** markerInfo;
00157 static StringHash markerInfoByName;
00158 static MarkerInfo ** markerInfoByInteger;
00159
00160 static void GrowMarkerInfo();
00161 static MarkerInfo * GetMarkerInfo(String & name);
00162 static MarkerInfo * GetMarkerInfo(int marker);
00163
00164 static int SortMarkersInMapOrder(IntArray & markers, int chromosome = -1);
00165 static void GetOrderedMarkers(IntArray & markers);
00166 static void FlagMissingMarkers(IntArray & missingMarkers);
00167
00168 static bool MarkerPositionsAvailable();
00169 static bool AlleleFrequenciesAvailable();
00170
00171 static void VerifySexSpecificOrder();
00172
00173 static void LoadAlleleFrequencies(const char * filename, bool required = false);
00174 static void LoadAlleleFrequencies(IFILE & file);
00175
00176 static void LoadMarkerMap(const char * filename, bool filter = false);
00177 static void LoadMarkerMap(IFILE & file, bool filter = false);
00178
00179 static void LoadBasepairMap(const char * filename);
00180 static void LoadBasepairMap(IFILE & file);
00181
00182 static void WriteMapFile(const char * filename);
00183 static void WriteMapFile(FILE * file);
00184
00185 static void WriteFreqFile(const char * filename, bool old_format = false);
00186 static void WriteFreqFile(FILE * file, bool old_format = false);
00187
00188 static int LoadAllele(int marker, String & label);
00189 static int LoadAllele(MarkerInfo * info, String & label);
00190
00191 PedigreeGlobals()
00192 {
00193 instanceCount++;
00194 }
00195 ~PedigreeGlobals();
00196
00197 private:
00198 static int instanceCount;
00199
00200 };
00201
00202 #endif
00203