📄 genetic_code_table.cpp
字号:
int weight = 0; int index = 0; int mul = 16; for ( int i = 0; i < 3; ++i ) { switch ( toupper(codon[i]) ) { case 'A' : weight = 2; break; case 'C' : weight = 1; break; case 'G' : weight = 3; break; case 'T' : case 'U' : weight = 0; break; } index += mul * weight; mul /= 4; } return index;}// constructorCGen_code_table_imp::CGen_code_table_imp(void){ // initialize common CTrans_table tables CTrans_table::x_InitFsaTable (); // Compose a long-long string string str; for (size_t i = 0; sm_GenCodeTblMemStr [i]; i++) { str += sm_GenCodeTblMemStr [i]; } // create an in memory stream on sm_GenCodeTblMemStr CNcbiIstrstream is(str.c_str(), str.length()); auto_ptr<CObjectIStream> asn_codes_in(CObjectIStream::Open(eSerial_AsnText, is)); // read single copy of genetic-code table m_GcTable = new CGenetic_code_table; *asn_codes_in >> *m_GcTable;}// destructorCGen_code_table_imp::~CGen_code_table_imp(void){}// constructorCTrans_table::CTrans_table(const CGenetic_code& gc){ const string * ncbieaa = 0; const string * sncbieaa = 0; // find amino acid and orf start strings given genetic code instance ITERATE (CGenetic_code::Tdata, gcd, gc.Get ()) { switch ((*gcd)->Which ()) { case CGenetic_code::C_E::e_Ncbieaa : ncbieaa = & (*gcd)->GetNcbieaa (); break; case CGenetic_code::C_E::e_Sncbieaa : sncbieaa = & (*gcd)->GetSncbieaa (); break; default: break; } } // throw exception if unable to find ncbieaa and sncbieaa strings if (ncbieaa == 0 || sncbieaa == 0) { NCBI_THROW (CException, eUnknown, "Could not find ncbieaa and sncbieaa"); } // initialize translation table for this genetic code instance x_InitFsaTransl (ncbieaa, sncbieaa);}const CTrans_table& CGen_code_table_imp::GetTransTable (int id){ _ASSERT(id >= 0); // look for already created translation table if ( size_t(id) < m_TransTablesById.size ()) { CRef< CTrans_table> tbl = m_TransTablesById [id]; if (tbl != 0) { // already in list, already initialized, so return return *tbl; } } // this mutex is automatically freed when the function exits DEFINE_STATIC_FAST_MUTEX(mtx); CFastMutexGuard LOCK (mtx); // test again within mutex lock to see if another thread was just adding it if ( size_t(id) < m_TransTablesById.size ()) { CRef< CTrans_table> tbl = m_TransTablesById [id]; if (tbl != 0) { // already in list, already initialized, so return return *tbl; } } // now look for the genetic code and initialize the translation table ITERATE (CGenetic_code_table::Tdata, gcl, m_GcTable->Get ()) { ITERATE (CGenetic_code::Tdata, gcd, (*gcl)->Get ()) { if ((*gcd)->IsId () && (*gcd)->GetId () == id) { // found proper genetic code, so create new trans table CRef< CTrans_table> tbl(new CTrans_table (**gcl)); // extend size of translation table list, if necessary if ( size_t(id) >= m_TransTablesById.size ()) { m_TransTablesById.resize (id + 1); } // add new table to list of translation tables m_TransTablesById [id] = tbl; return *tbl; } } } // throw exception if failure NCBI_THROW (CException, eUnknown, "Unable to find genetic code number " + NStr::IntToString (id));}const CTrans_table& CGen_code_table_imp::GetTransTable (const CGenetic_code& gc){ const string * ncbieaa = 0; const string * sncbieaa = 0; ITERATE (CGenetic_code::Tdata, gcd, gc.Get ()) { switch ((*gcd)->Which ()) { case CGenetic_code::C_E::e_Id : { // lookup table by ID int id = (*gcd)->GetId (); return GetTransTable (id); } case CGenetic_code::C_E::e_Ncbieaa : ncbieaa = & (*gcd)->GetNcbieaa (); break; case CGenetic_code::C_E::e_Sncbieaa : sncbieaa = & (*gcd)->GetSncbieaa (); break; default: break; } } if (ncbieaa != 0 && sncbieaa != 0) { // return * new CTrans_table (gc); NCBI_THROW (CException, eUnknown, "GetTransTable without ID not yet supported"); } NCBI_THROW (CException, eUnknown, "GetTransTable does not have sufficient information");}const CGenetic_code_table & CGen_code_table_imp::GetCodeTable (void){ return *m_GcTable;}const string& CGen_code_table_imp::GetNcbieaa(int id) const{ ITERATE (CGenetic_code_table::Tdata, gcl, m_GcTable->Get ()) { if ( (*gcl)->GetId() == id ) { return (*gcl)->GetNcbieaa(); } } return CNcbiEmptyString::Get();}const string& CGen_code_table_imp::GetNcbieaa(const CGenetic_code& gc) const{ return gc.GetNcbieaa();}const string& CGen_code_table_imp::GetSncbieaa(int id) const{ ITERATE (CGenetic_code_table::Tdata, gcl, m_GcTable->Get ()) { if ( (*gcl)->GetId() == id ) { return (*gcl)->GetSncbieaa(); } } return CNcbiEmptyString::Get();}const string& CGen_code_table_imp::GetSncbieaa(const CGenetic_code& gc) const{ return gc.GetSncbieaa();}// standard genetic code//// ncbieaa "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG"// sncbieaa "---M---------------M---------------M----------------------------"//// -- Base1 TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG// -- Base2 TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG// -- Base3 TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG/* Second PositionFirst T C A G Third----------------------------------------------------------------- T TTT Phe [F] TCT Ser [S] TAT Tyr [Y] TGT Cys [C] T TTC Phe [F] TCC Ser [S] TAC Tyr [Y] TGC Cys [C] C TTA Leu [L] TCA Ser [S] TAA Ter [*] TGA Ter [*] A TTG Leu [L] TCG Ser [S] TAG Ter [*] TGG Trp [W] G----------------------------------------------------------------- C CTT Leu [L] CCT Pro [P] CAT His [H] CGT Arg [R] T CTC Leu [L] CCC Pro [P] CAC His [H] CGC Arg [R] C CTA Leu [L] CCA Pro [P] CAA Gln [Q] CGA Arg [R] A CTG Leu [L] CCG Pro [P] CAG Gln [Q] CGG Arg [R] G----------------------------------------------------------------- A ATT Ile [I] ACT Thr [T] AAT Asn [N] AGT Ser [S] T ATC Ile [I] ACC Thr [T] AAC Asn [N] AGC Ser [S] C ATA Ile [I] ACA Thr [T] AAA Lys [K] AGA Arg [R] A ATG Met [M] ACG Thr [T] AAG Lys [K] AGG Arg [R] G----------------------------------------------------------------- G GTT Val [V] GCT Ala [A] GAT Asp [D] GGT Gly [G] T GTC Val [V] GCC Ala [A] GAC Asp [D] GGC Gly [G] C GTA Val [V] GCA Ala [A] GAA Glu [E] GGA Gly [G] A GTG Val [V] GCG Ala [A] GAG Glu [E] GGG Gly [G] G-----------------------------------------------------------------*/// local copy of gc.prt genetic code table ASN.1const char * CGen_code_table_imp::sm_GenCodeTblMemStr [] ={ "Genetic-code-table ::= {\n", "{ name \"Standard\" , name \"SGC0\" , id 1 ,\n", "ncbieaa \"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"---M---------------M---------------M----------------------------\" } ,\n", "{ name \"Vertebrate Mitochondrial\" , name \"SGC1\" , id 2 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG\",\n", "sncbieaa \"--------------------------------MMMM---------------M------------\" } ,\n", "{ name \"Yeast Mitochondrial\" , name \"SGC2\" , id 3 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"----------------------------------MM----------------------------\" } ,\n", "{ name \"Mold Mitochondrial; Protozoan Mitochondrial; Coelenterate\n", "Mitochondrial; Mycoplasma; Spiroplasma\" ,\n", "name \"SGC3\" , id 4 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"--MM---------------M------------MMMM---------------M------------\" } ,\n", "{ name \"Invertebrate Mitochondrial\" , name \"SGC4\" , id 5 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG\",\n", "sncbieaa \"---M----------------------------MMMM---------------M------------\" } ,\n", "{ name \"Ciliate Nuclear; Dasycladacean Nuclear; Hexamita Nuclear\" ,\n", "name \"SGC5\" , id 6 ,\n", "ncbieaa \"FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Echinoderm Mitochondrial; Flatworm Mitochondrial\" , name \"SGC8\" , id 9 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M---------------M------------\" } ,\n", "{ name \"Euplotid Nuclear\" , name \"SGC9\" , id 10 ,\n", "ncbieaa \"FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Bacterial and Plant Plastid\" , id 11 ,\n", "ncbieaa \"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"---M---------------M------------MMMM---------------M------------\" } ,\n", "{ name \"Alternative Yeast Nuclear\" , id 12 ,\n", "ncbieaa \"FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-------------------M---------------M----------------------------\" } ,\n", "{ name \"Ascidian Mitochondrial\" , id 13 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Alternative Flatworm Mitochondrial\" , id 14 ,\n", "ncbieaa \"FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Blepharisma Macronuclear\" , id 15 ,\n", "ncbieaa \"FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Chlorophycean Mitochondrial\" , id 16 ,\n", "ncbieaa \"FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Trematode Mitochondrial\" , id 21 ,\n", "ncbieaa \"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M---------------M------------\" } ,\n", "{ name \"Scenedesmus obliquus mitochondrial\" , id 22 ,\n", "ncbieaa \"FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"-----------------------------------M----------------------------\" } ,\n", "{ name \"Thraustochytrium mitochondrial code\" , id 23 ,\n", "ncbieaa \"FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG\",\n", "sncbieaa \"--------------------------------M--M---------------M------------\" } };\n", 0 // to indicate that there is no more data};END_objects_SCOPE // namespace ncbi::objects::END_NCBI_SCOPE/** ===========================================================================** $Log: Genetic_code_table.cpp,v $* Revision 1000.2 2004/06/01 19:33:54 gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R6.17** Revision 6.17 2004/05/19 17:26:04 gorelenk* Added include of PCH - ncbi_pch.hpp** Revision 6.16 2004/03/24 13:58:59 friedman* Fixed mutex comments** Revision 6.15 2004/03/23 20:08:10 friedman* Replaced 'static CFastMutex' with DEFINE_STATIC_FAST_MUTEX** Revision 6.14 2003/08/19 19:23:00 kans* s_ValidCodon test should use && instead of || (AU)** Revision 6.13 2003/04/29 22:12:35 tolstoy* Comments for two previous commit from Tolstoy : 2 bugs fixed in function IndexToCodon* 1) incorrect order of letters in the table na - was TCGA* 2) incorrect operation for bit counting - was total % div* cofirmation from Johnatan Kans** Revision 6.12 2003/04/29 14:35:16 tolstoy* *** empty log message ***** Revision 6.11 2003/04/28 20:05:22 tolstoy* *** empty log message ***** Revision 6.10 2003/04/18 19:40:38 kans* changed iterate to ITERATE** Revision 6.9 2003/02/24 18:52:57 vasilche* Added optional mapped locations arguments to feature comparison.** Revision 6.8 2002/11/26 18:50:31 shomrat* Add GetGenCode** Revision 6.7 2002/11/04 21:29:16 grichenk* Fixed usage of const CRef<> and CRef<> constructor** Revision 6.6 2002/09/19 18:07:05 kans* code 9 is echinoderm and flatworm mito, code 14 is alternative flatworm mito** Revision 6.5 2002/09/13 18:33:57 kans* sm_GenCodeTblMemStr returned to an array of strings for consistency with sm_StrAsnData in sequence.cpp** Revision 6.4 2002/09/12 19:59:12 kans* CGen_code_table_imp instantiated after type info system (diccucio)** Revision 6.3 2002/09/10 15:19:55 kans* added GetCodeTable method, moved sm_GenCodeTblMemStr into implementation class** Revision 6.2 2002/09/09 21:12:05 ucko* Add braces around e_Id case to avoid scoping error.* Add default cases to make GCC happy.* Make sure id >= 0.** Revision 6.1 2002/09/09 20:58:21 kans* added CTrans_table and CGen_code_table classes*** ===========================================================================*//* Original file checksum: lines: 64, chars: 1914, CRC32: 6d579336 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -