// $Id: nucleotide.cpp 962 2006-11-07 15:13:34Z privmane $ #include "nucleotide.h" #include "errorMsg.h" nucleotide::nucleotide() { _relation.resize(4); for (int i=0; i < _relation.size(); ++i) { _relation[i].resize(16); } for (int s=0;s<4;++s) { for (int t=0;t<16;++t){ _relation[s][t]=relationsInternal(s,t); } } } int nucleotide::fromChar(const string& str, const int pos) const { return fromChar(str[pos]); } vector nucleotide::fromString(const string &str) const { vector vec; for (int i=0;i err; err.push_back(" The nucleotide sequences contained the character: "); err[0]+=s; err.push_back(" The nucleotide was not one of the following: "); err.push_back("A, C, G, T, X, -, ?"); err.push_back("a, c, g, t, x, _, *"); errorMsg::reportError(err); } return -99; } string nucleotide::fromInt(const int id) const { char x= fromIntInternal(id); string res; res.append(1,x); return res; } char nucleotide::fromIntInternal(const int in_id) const { switch (in_id) { case 0 : return 'A' ; break; case 1 : return 'C' ; break; case 2 : return 'G' ; break; case 3 : return 'T' ; break; case -1: return '-' ; break; case 4 : return 'U'; break; case 5 : return 'R'; break; case 6 : return 'Y'; break; case 7 : return 'K'; break; case 8 : return 'M'; break; case 9 : return 'S'; break; case 10 : return 'W'; break; case 11 : return 'B'; break; case 12 : return 'D'; break; case 13 : return 'H'; break; case 14 : return 'V'; break; case 15 : return 'N'; break; default: vector err; err.push_back(" unable to print nucleotide. nucleotide was not one of the following: "); err.push_back("A, C, G, T, -, ?"); err.push_back("a, c, g, t, _, *"); errorMsg::reportError(err); // make the program quit }//end of switch return '!' ; // for the lousy compiler } int nucleotide::relationsInternal(const int ctc,const int charInSeq ) const{ //ctc=charToCheck switch (charInSeq){ case 0 : if (ctc==0) return 1 ; break;// A = adenine case 1 : if (ctc==1) return 1 ; break;// C = cytosine case 2 : if (ctc==2) return 1 ; break;// G = guanine case 3 : if (ctc==3) return 1 ; break;// T = thymine case 4 : if (ctc==4) return 1 ; break; // U = uracil case 5 : if (ctc==2||ctc==0) return 1 ; break;// R = purine (same as [GA]) case 6 : if (ctc==3||ctc==1) return 1 ; break;// Y = pyrimidine (same as [TC]) case 7 : if (ctc==2||ctc==3) return 1 ; break;// K = keto (same as [GT]) case 8 : if (ctc==0||ctc==1) return 1 ; break;// M = amino (same as [AC]) case 9 : if (ctc==2||ctc==1) return 1 ; break;// S = (same as [GC]) case 10: if (ctc==0||ctc==3) return 1 ; break;// W = (same as [AT]) case 11: if (ctc==2||ctc==3||ctc==1) return 1 ; break;// B = (same as [GTC]) case 12: if (ctc==2||ctc==0||ctc==3) return 1 ; break;// D = (same as [GAT]) case 13: if (ctc==0||ctc==1||ctc==3) return 1 ; break;// H = (same as [ACT]) case 14: if (ctc==2||ctc==1||ctc==0) return 1 ; break;// V = (same as [GCA]) case 15: if (ctc==0||ctc==1||ctc==2||ctc==3) return 1 ; break;// N = any (same as [ACGT]) }; return 0; };