00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GeneticDist_H
00023 #define GeneticDist_H
00024
00025 #include <iostream>
00026 #include <string>
00027 #include "util.h"
00028 #include "doublematrix.h"
00029 #include "safe_vectors.h"
00030
00031 namespace matvec {
00032 extern int DISCRETE_TRAIT;
00033 extern doubleMatrix PENETRANCE_MATRIX;
00034
00035
00036
00037 class ChromStruct;
00038 class GeneticDist;
00039
00040
00041
00042
00043
00044
00045
00046 class LocusStruct {
00047
00048 protected:
00049 unsigned numallele;
00050 void copyfrom(const LocusStruct& A);
00051
00052 public:
00053 char qtl_ml;
00054 Vector<double> allele_freq;
00055 doubleMatrix genotypic_val_mat;
00056
00057 double distance;
00058
00059
00060 std::string nameOfcol1, nameOfcol2;
00061
00062
00063 unsigned nextMarker;
00064 unsigned nHaplotypes ;
00065 Vector<unsigned> listOfAllele;
00066 Vector<unsigned> al1Haplo, al2Haplo;
00067
00068 LocusStruct(void) {numallele = 0;}
00069 LocusStruct(const unsigned na) {numallele = 0; resize(na);}
00070
00071
00072 const LocusStruct& operator=(const LocusStruct& A)
00073 {numallele=0; copyfrom(A); return *this;}
00074
00075 void resize(const unsigned na);
00076 void nallele(const unsigned na) {numallele = na;}
00077 unsigned nallele(void) const {return numallele;}
00078
00079 SafeSTLVector<int> peelOrder;
00080 bool cutLoops;
00081 };
00082
00083
00084
00085
00086
00087
00088
00089
00090 class ChromStruct {
00091 protected:
00092 unsigned numloci;
00093 void copyfrom(const ChromStruct& A);
00094
00095 public:
00096 SafeSTLVector<LocusStruct> locus;
00097 doubleMatrix recomb_rate_mat;
00098
00099 ChromStruct(void) {numloci=0;}
00100 ChromStruct(const unsigned nl) {numloci=0; resize(nl);}
00101 ~ChromStruct(void) {release();}
00102
00103 const ChromStruct& operator=(const ChromStruct& A)
00104 {numloci=0; copyfrom(A); return *this;}
00105
00106 void resize(const unsigned nl);
00107 unsigned nloci(void) const {return numloci;}
00108
00109 void release(void);
00110
00111 SafeSTLVector<int> peelOrder;
00112 };
00113
00114 class MaternalPaternalRQTLAlleles {
00115 public:
00116 unsigned maternal;
00117 unsigned paternal;
00118 };
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 class GeneticDist {
00136 protected:
00137 char distname[25];
00138 unsigned numchrom, numtrait;
00139
00140 public:
00141
00142 ChromStruct *chromosome;
00143 unsigned numMarkerLoci;
00144 GeneticDist(void);
00145 GeneticDist(const unsigned nc,...);
00146 GeneticDist(GeneticDist& G ){copyfrom(G);}
00147 virtual ~GeneticDist(void) {release();}
00148
00149 const GeneticDist& operator=(const GeneticDist& A) {numchrom=0;
00150 chromosome=0; copyfrom(A); return *this;}
00151
00152
00153 virtual void resize(const unsigned nc) {nchrom(nc); }
00154 virtual unsigned ntrait(void) const {return numtrait;}
00155 virtual doubleMatrix* var_matrix(void) { return 0;}
00156
00157 const char* name(void) const {return distname;}
00158 ChromStruct *chrom(void) {return chromosome;}
00159 double recomb_rate(const unsigned c,const unsigned li,const unsigned lj);
00160 unsigned nchrom(void) const {return numchrom;}
00161 unsigned nloci_chrom(const unsigned c) const;
00162 unsigned nallele(const unsigned c,const unsigned l) const
00163 {return chromosome[c].locus[l].nallele();}
00164
00165
00166 int display(void);
00167
00168 void copyfrom(const GeneticDist& A);
00169 void nchrom(const unsigned nc);
00170 void nloci(const unsigned nl0,...);
00171 void release(void);
00172 void locus(const unsigned c,const unsigned l,const char qm[],
00173 const unsigned na, ...);
00174
00175 void putColmNames(const unsigned c,const unsigned l,
00176 char nm1[],char nm2[]);
00177
00178 void recomb_rate(const unsigned c,const unsigned li,const unsigned lj,
00179 const double r);
00180 void genotypic_val(const unsigned c,const unsigned l,const double* v);
00181 void genotypic_val(const unsigned c,const unsigned l,
00182 const double v0,...);
00183 double sample(void) const {return 0.0;}
00184 const double** genotypic_val(const unsigned c,const unsigned l) const;
00185
00186 void multi_loci(int num_loci);
00187 void put_distance(const unsigned c,const unsigned l, double distance);
00188 double get_distance(const unsigned c,const unsigned l);
00189 void locus(const unsigned c,const unsigned l,const char qm[], const unsigned na, Vector<double> allele_freq);
00190
00191 SafeSTLVector<MaternalPaternalRQTLAlleles> rqtlVector;
00192 };
00193
00194 inline const double** GeneticDist::genotypic_val(const unsigned c,
00195 const unsigned l) const
00196 {
00197 return (const double**)chromosome[c].locus[l].genotypic_val_mat.begin();
00198 }
00199
00200 inline GeneticDist::GeneticDist(void)
00201 {
00202 numchrom = 0; chromosome = 0; numtrait = 1;
00203 strcpy(distname,"GeneticDist");
00204
00205 }
00206
00207 inline unsigned GeneticDist::nloci_chrom(const unsigned c) const
00208 {
00209 if (c > 0) {
00210 return chromosome[c-1].nloci();
00211 }
00212 else {
00213 std::cerr << "GeneticDist::nloci(c): arg value out of range";
00214 exit(1);
00215 }
00216 }
00217
00218
00219
00220
00221
00222
00223
00224 class UnknownDist: public GeneticDist {
00225 protected:
00226 unsigned dim;
00227 Vector<double> mu_vec;
00228 doubleMatrix var_mat;
00229
00230 public:
00231 UnknownDist(void) {strcpy(distname,"UnknownDist"); dim=0;}
00232 UnknownDist(const UnknownDist& u):GeneticDist() {copyfrom(u);}
00233 UnknownDist(const Vector<double> mu, const doubleMatrix sigma);
00234 UnknownDist(const double mu, const double sigma);
00235 ~UnknownDist(void) {;}
00236
00237 void copyfrom(const UnknownDist& A);
00238 void resize(const unsigned n);
00239 unsigned ntrait(void) const {return dim;}
00240
00241 Vector<double>* mean_vector(void) {return &mu_vec;}
00242 doubleMatrix* var_matrix(void) {return &var_mat;}
00243 };
00244 }
00245 #endif
00246
00247