00001 00002 // 00003 // This file is part of the MADELINE 2 program 00004 // written by Edward H. Trager, Ritu Khanna and Adrian Marrs 00005 // Copyright (c) 2005 by the 00006 // Regents of the University of Michigan. 00007 // All Rights Reserved. 00008 // 00009 // The latest version of this program is available from: 00010 // 00011 // http://eyegene.ophthy.med.umich.edu/madeline/ 00012 // 00013 // Released under the GNU General Public License. 00014 // A copy of the GPL is included in the distribution 00015 // package of this software, or see: 00016 // 00017 // http://www.gnu.org/copyleft/ 00018 // 00019 // ... for licensing details. 00020 // 00022 00023 // 00024 // 2005.03.07.ET 00025 // 00026 00027 // 00028 // Genotype.h 00029 // 00030 00031 #ifndef GENOTYPE_INCLUDED 00032 #define GENOTYPE_INCLUDED 00033 00034 #include <string> 00035 #include <iostream> 00036 #include "Data.h" 00037 #include "Number.h" 00039 00042 class Genotype : public Data{ 00043 public: 00044 00045 enum { SNP_A_ORDINAL=1, SNP_C_ORDINAL=2, SNP_G_ORDINAL=3, SNP_T_ORDINAL=4 }; 00046 00047 private: 00048 static std::set<std::string> _genotypeMissingValue; 00049 bool _isMissing; 00050 bool _isSNP; 00051 std::string _genotype; 00053 unsigned int _allele1; 00054 unsigned int _allele2; 00055 00056 00057 const static char _normalDelimiter='/'; 00058 const static char _alternateDelimiter='|'; 00059 00060 // The normal convention is to have the lesser allele shown first: 00061 void _orderAlleles( void ); 00062 00063 // Store "normalized" string representation of allele: 00064 void _setNormalizedStringRepresentation( void ); 00065 00066 // Convert integer allele to (static) c-string: 00067 const char *_itoa( unsigned int i ) const; 00068 const char *_snpOrdinalToCString( unsigned int allele ); 00069 const char* _setAllele(const char* input, unsigned &value, bool &snp); 00070 00071 public: 00072 00073 // 00074 // Static methods: 00075 // 00076 static void addGenotypeMissingValue(std::string &value){ _genotypeMissingValue.insert(value); } 00077 static bool isMissingValue(std::string value); 00078 00079 // Constructors: 00080 Genotype(){ setMissing(); } 00081 Genotype(const char *g){ set(g); } 00082 Genotype(const std::string& g){ set(g.c_str()); } 00083 Genotype(const int allele1, const int allele2){ _isSNP=false;set(allele1,allele2); } 00084 00085 // Methods required by Data virtual base class: 00086 bool isMissing( void ) const { return _isMissing; } 00087 void setMissing( void ) { _isMissing=true; _isSNP=false;_genotype=".";_allele1=_allele2=0; } 00088 void set( const char *genotype ); 00089 void set( const std::string& genotype); 00090 const std::string get( void ) const; 00091 00092 // 00093 // Additional Setters not present in virtual base class: 00094 // 00095 void set(const int allele1,const int allele2); 00096 void setAllele1(const int allele1); 00097 void setAllele2(const int allele2); 00098 void setAllele1(const char* allele1); 00099 void setAllele2(const char* allele2); 00100 void setAllele1(const std::string &allele1); 00101 void setAllele2(const std::string &allele2); 00102 // 00103 // Additional Getters not present in virtual base class: 00104 // 00105 const Number getAllele1( void ) const { if(_isMissing) return Number::MISSING; return Number(_allele1); } 00106 const Number getAllele2( void ) const { if(_isMissing) return Number::MISSING; return Number(_allele2); } 00107 00108 // 00109 // Operators: 00110 // 00111 Genotype& operator+=( const int allele ); 00112 Genotype& operator-=( const int allele ); 00113 Genotype& operator+=( const Number &allele ); 00114 Genotype& operator-=( const Number &allele ); 00115 00116 // 00117 // Operators: 00118 bool operator<( const Data& b) const; 00119 bool operator==( const Data& b) const; 00120 const DATATYPE getDataType( void ) const { return GENOTYPE; } 00121 virtual Genotype* clone() const; 00122 00124 static bool isA(const std::string& s); 00125 00126 }; 00127 00128 std::ostream &operator<<(std::ostream &s,const Genotype &g); 00129 00130 #endif