Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

geneticdist.h

Go to the documentation of this file.
00001 //****************************************************
00002 //  April, 1993, University of Illinois
00003 // Copyright (C) 1993, 1994 Tianlin Wang
00004 /* Copyright (C) 1994-2003 Matvec Development Team. 
00005 
00006   This program is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010   
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015     
00016   You should have received a copy of the GNU Library General Public
00017   License along with this library; if not, write to the Free
00018   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019   MA 02111-1307, USA 
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;  // was called  DISCRETE_TRAIT;
00033 extern doubleMatrix PENETRANCE_MATRIX;
00034 
00035 /////////////////////////// LocusStruct class ///////////////////////
00036 
00037 class ChromStruct;
00038 class GeneticDist;
00039 
00040 /*!
00041    \class LocusStruct GeneticDist.h
00042    \brief a structure for a locus
00043 
00044    \sa Locus
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 //BRS
00057       double     distance; // distance from origin to this locus in Morgans
00058 //BRS
00059 //RLF
00060       std::string   nameOfcol1, nameOfcol2;              // for marker data
00061 //RLF
00062 // newHG
00063       unsigned nextMarker;
00064       unsigned nHaplotypes ;
00065       Vector<unsigned> listOfAllele;            // setup in population::ListAlleleFounders
00066       Vector<unsigned> al1Haplo, al2Haplo;      // setup in population::SetPossibleHaplotypes : related to the next marker on the right
00067 // newHG
00068       LocusStruct(void) {numallele = 0;}
00069       LocusStruct(const unsigned na) {numallele = 0; resize(na);}
00070 //      ~LocusStruct(void) {numallele =0;}
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       // LRT for the RSampler
00079       SafeSTLVector<int> peelOrder;
00080           bool cutLoops;
00081 };
00082 
00083 /////////////////////////// ChromStruct class ///////////////////////
00084 /*!
00085    \class ChromStruct  GeneticDist.h
00086    \brief chromosome structure
00087 
00088    \sa Chromosome
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       // LRT for the RSampler
00111       SafeSTLVector<int> peelOrder;
00112 };
00113 
00114 class MaternalPaternalRQTLAlleles {
00115  public:
00116   unsigned maternal;
00117   unsigned paternal;
00118 };
00119 /*! \class MaternalPaternalRQTLAlleles geneticdist.h inc/geneticdist.h
00120  * \brief This is the building block class for dealing with RQTL.
00121  *
00122  * MaternalPaternalRQTLAlleles class defines the maternal and paternal 
00123  * alleles of a RQTL genotype.
00124  */ 
00125 
00126 /////////////////////////// GeneticDist class ///////////////////////
00127 
00128 /*!
00129    \class GeneticDist  GeneticDist.h
00130    \brief  a base for Genetic distributions
00131 
00132    \sa StatDist
00133 */
00134 
00135 class GeneticDist  {
00136    protected:
00137       char         distname[25];
00138       unsigned     numchrom, numtrait;     // default numtrait = 1
00139 
00140    public:      
00141                   
00142           ChromStruct  *chromosome;
00143       unsigned numMarkerLoci; //LRT 
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       //int     display(void)const{cout<<"  "<<distname<<"\n"; return 1;}
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 //RLF
00175      void putColmNames(const unsigned c,const unsigned l,
00176                                 char nm1[],char nm2[]);
00177 //RLF
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 //BRS
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 //BRS
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 //   cout << "GeneticDist::GeneticDist(void): numtrait = " << numtrait << endl;
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 ///////////////////  UnknownDist  class /////////////////////////////
00220 /*!
00221    \class UnknownDist
00222    \brief a dummy genetic distribution
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 

Generated on Thu Jun 16 17:13:41 2005 for Matvec by doxygen1.2.16