1 #ifndef DYNAMITEcodonHEADERFILE 2 #define DYNAMITEcodonHEADERFILE 3 #ifdef _cplusplus 4 extern "C" { 5 #endif 6 #include "wisebase.h" 7 8 9 #define BASE_A 0 10 #define BASE_G 1 11 #define BASE_C 2 12 #define BASE_T 3 13 #define BASE_N 4 14 15 typedef short int base; 16 typedef short int codon; 17 typedef char aa; 18 19 #define aminoacid_number(c) (c-'A') 20 21 #define is_base(a) (a == 'A' || a == 'T' || a == 'C' || a == 'G' || a== 'N' || a == 'a' || a == 't' || a == 'c' || a == 'g' || a == 'n' ? 1 : 0) 22 23 /* Object CodonTable 24 * 25 * Descrip: The codon table provides a mapping from the 64 codons to the 20 amino 26 * acids. The rest of the modules provides assorted codon<->base<->amino 27 * acid mappings. 28 * 29 * Probably the trickiest thing is that there are two different types of 30 * representations of codons. One in base 5 (N being the 5th base), 31 * providing 0-124 inclusive codon numbers. These numbers are the ones 32 * going to be principly used in most calculations. 33 * 34 * However, it is often very useful to use 0-63 numbers, for example 35 * in the precise definition of the codon table. 36 * 37 * 38 */ 39 struct Wise2_CodonTable { 40 int dynamite_hard_link; 41 #ifdef PTHREAD 42 pthread_mutex_t dynamite_mutex; 43 #endif 44 aa codon_str[125]; 45 char * name; 46 } ; 47 /* CodonTable defined */ 48 #ifndef DYNAMITE_DEFINED_CodonTable 49 typedef struct Wise2_CodonTable Wise2_CodonTable; 50 #define CodonTable Wise2_CodonTable 51 #define DYNAMITE_DEFINED_CodonTable 52 #endif 53 54 55 56 57 /***************************************************/ 58 /* Callable functions */ 59 /* These are the functions you are expected to use */ 60 /***************************************************/ 61 62 63 64 /* Function: read_CodonTable_file(file) 65 * 66 * Descrip: Opens filename, reads it as if a Ewan style 67 * codon table and closes. 68 * 69 * 70 * Arg: file [READ ] filename to open [char *] 71 * 72 * Return [OWNER] A codon-table, NULL if error [CodonTable *] 73 * 74 */ 75 CodonTable * Wise2_read_CodonTable_file(char * file); 76 #define read_CodonTable_file Wise2_read_CodonTable_file 77 78 79 /* Function: read_CodonTable(ifp) 80 * 81 * Descrip: reads a codon table from a filestream in Ewan 82 * format. 83 * 84 * As Ewan format is really bad and has no start/stop 85 * this will effectively read to the end of the file. 86 * Ooops. 87 * 88 * 89 * Arg: ifp [READ ] file input [FILE *] 90 * 91 * Return [UNKN ] Undocumented return value [CodonTable *] 92 * 93 */ 94 CodonTable * Wise2_read_CodonTable(FILE * ifp); 95 #define read_CodonTable Wise2_read_CodonTable 96 97 98 /* Function: aminoacid_from_seq(ct,seq) 99 * 100 * Descrip: Returns the amino acid for this position in the DNA sequence 101 * Takes the pointer +1 and +2 points. 102 * 103 * No error checks implemented. Probably a mistake ;) 104 * 105 * 106 * Arg: ct [READ ] codon table [CodonTable *] 107 * Arg: seq [READ ] pointer to DNA chars [char *] 108 * 109 * Return [UNKN ] an amino acid char (A-Z) [aa] 110 * 111 */ 112 aa Wise2_aminoacid_from_seq(CodonTable * ct,char * seq); 113 #define aminoacid_from_seq Wise2_aminoacid_from_seq 114 115 116 /* Function: aminoacid_from_codon(ct,c) 117 * 118 * Descrip: returns amino acid for this codon number (NB codon numbers 0-125) 119 * 120 * 121 * Arg: ct [READ ] codon table [CodonTable *] 122 * Arg: c [READ ] codon number [codon] 123 * 124 * Return [READ ] aminoacid that is this codon (X for ambiguous, * for stop) [aa] 125 * 126 */ 127 aa Wise2_aminoacid_from_codon(CodonTable * ct,codon c); 128 #define aminoacid_from_codon Wise2_aminoacid_from_codon 129 130 131 /* Function: aminoacid_no_from_codon(ct,c) 132 * 133 * Descrip: a sister function to aminoacid_from_codon: 134 * returns amino acid number (0-26) for this codon number (0-125) 135 * 136 * 137 * Arg: ct [READ ] codon table [CodonTable *] 138 * Arg: c [READ ] codon number [codon] 139 * 140 * Return [READ ] aminoacid number [0-26] for this codon [int] 141 * 142 */ 143 int Wise2_aminoacid_no_from_codon(CodonTable * ct,codon c); 144 #define aminoacid_no_from_codon Wise2_aminoacid_no_from_codon 145 146 147 /* Function: is_stop_codon(c,ct) 148 * 149 * Descrip: tells you whether this codon number is really a stop 150 * in this translation table 151 * 152 * 153 * Arg: c [READ ] codon number [codon] 154 * Arg: ct [READ ] codon table [CodonTable *] 155 * 156 * Return [UNKN ] TRUE if is stop, FALSE otherwise [boolean] 157 * 158 */ 159 boolean Wise2_is_stop_codon(codon c,CodonTable * ct); 160 #define is_stop_codon Wise2_is_stop_codon 161 162 163 /* Function: is_non_ambiguous_codon_seq(seq) 164 * 165 * Descrip: Tells you if this codon is a real codon 166 * 167 * 168 * Arg: seq [READ ] pointer to DNA sequence [char *] 169 * 170 * Return [UNKN ] TRUE if real codon, FALSE if contains N's [boolean] 171 * 172 */ 173 boolean Wise2_is_non_ambiguous_codon_seq(char * seq); 174 #define is_non_ambiguous_codon_seq Wise2_is_non_ambiguous_codon_seq 175 176 177 /* Function: is_valid_aminoacid(ct,c) 178 * 179 * Descrip: Tells you if this letter (c) is recognised as a valid amino acid 180 * in this codon table 181 * 182 * 183 * Arg: ct [READ ] Codon Table [CodonTable *] 184 * Arg: c [UNKN ] aminoacid [char] 185 * 186 * Return [UNKN ] TRUE if valid, FALSE if not. [boolean] 187 * 188 */ 189 boolean Wise2_is_valid_aminoacid(CodonTable * ct,char c); 190 #define is_valid_aminoacid Wise2_is_valid_aminoacid 191 192 193 /* Function: is_valid_base_char(c) 194 * 195 * Descrip: Tells you if the letter is A,T,C,G,N (NB, N is ok). 196 * 197 * 198 * Arg: c [READ ] base [char] 199 * 200 * Return [UNKN ] TRUE if (ATGCN) FALSE otherwise [boolean] 201 * 202 */ 203 boolean Wise2_is_valid_base_char(char c); 204 #define is_valid_base_char Wise2_is_valid_base_char 205 206 207 /* Function: codon_from_base4_codon(c) 208 * 209 * Descrip: maps a 0-63 codon to a 0-123 codon. Suprisingly useful. 210 * 211 * 212 * Arg: c [UNKN ] Undocumented argument [int] 213 * 214 * Return [UNKN ] Undocumented return value [codon] 215 * 216 */ 217 codon Wise2_codon_from_base4_codon(int c); 218 #define codon_from_base4_codon Wise2_codon_from_base4_codon 219 220 221 /* Function: base4_codon_from_codon(c) 222 * 223 * Descrip: maps a 0-125 codon to a 0-63 codon. 224 * 225 * If ambiguous then returns 64 having issued a warning. 226 * 227 * 228 * Arg: c [READ ] codon 0-125 [codon] 229 * 230 * Return [UNKN ] base 4 codon (0-63) [int] 231 * 232 */ 233 int Wise2_base4_codon_from_codon(codon c); 234 #define base4_codon_from_codon Wise2_base4_codon_from_codon 235 236 237 /* Function: has_random_bases(c) 238 * 239 * Descrip: Tests to see if this codon number has any N's in it 240 * 241 * 242 * Arg: c [READ ] codon number 0-124 [codon] 243 * 244 * Return [UNKN ] TRUE if has N's , FALSE otherwise [boolean] 245 * 246 */ 247 boolean Wise2_has_random_bases(codon c); 248 #define has_random_bases Wise2_has_random_bases 249 250 251 /* Function: permute_possible_random_bases(c,one,two,three) 252 * 253 * Descrip: Bizarely useful function for calculating ambiguity scores. 254 * 255 * This takes the codon c, and for each possible base, 256 * if it is N, replaces it with one, two or three. 257 * 258 * If the base is not N, it remains the same 259 * 260 * 261 * Arg: c [READ ] codon number [codon] 262 * Arg: one [READ ] base to replace first position if N [base] 263 * Arg: two [READ ] base to replace second position if N [base] 264 * Arg: three [READ ] base to replace third position if N [base] 265 * 266 * Return [UNKN ] codon number [codon] 267 * 268 */ 269 codon Wise2_permute_possible_random_bases(codon c,base one,base two,base three); 270 #define permute_possible_random_bases Wise2_permute_possible_random_bases 271 272 273 /* Function: all_bases_from_codon(c,one,two,three) 274 * 275 * Descrip: Really an internal function, by useful enough to 276 * encourage outside use. 277 * 278 * Takes codon c and breaks it into 3 base-numbers 279 * 280 * 281 * Arg: c [UNKN ] Undocumented argument [codon] 282 * Arg: one [UNKN ] Undocumented argument [base *] 283 * Arg: two [UNKN ] Undocumented argument [base *] 284 * Arg: three [UNKN ] Undocumented argument [base *] 285 * 286 */ 287 void Wise2_all_bases_from_codon(codon c,base * one,base * two,base * three); 288 #define all_bases_from_codon Wise2_all_bases_from_codon 289 290 291 /* Function: reverse_codon(c) 292 * 293 * Descrip: Reverses codon. Takes a forward codon number and 294 * builds the inverted codon number 295 * 296 * 297 * Arg: c [UNKN ] Undocumented argument [codon] 298 * 299 * Return [UNKN ] Undocumented return value [codon] 300 * 301 */ 302 codon Wise2_reverse_codon(codon c); 303 #define reverse_codon Wise2_reverse_codon 304 305 306 /* Function: base_from_codon(c,pos) 307 * 308 * Descrip: Probably not the best function to use for this, but 309 * useful. Takes a codon and with pos being 1,2,3 gives 310 * you the firt,second of third base 311 * 312 * 313 * Arg: c [UNKN ] Undocumented argument [codon] 314 * Arg: pos [UNKN ] Undocumented argument [int] 315 * 316 * Return [UNKN ] Undocumented return value [base] 317 * 318 */ 319 base Wise2_base_from_codon(codon c,int pos); 320 #define base_from_codon Wise2_base_from_codon 321 322 323 /* Function: codon_from_seq(seq) 324 * 325 * Descrip: takes an ASCII coded pointer to a 3 base pair 326 * sequence (it could be the part of a sequence: it only 327 * assummes that the seq points with 3 chars at pos 0,1,2 328 * in C coordinates from seq. No NULL is required). It 329 * ives back the codon as made from standard mapping, ie, 330 * 25*base_1+5*base_2 + base3 being a number from 0-124 inc. 331 * 332 * 333 * Arg: seq [UNKN ] pointer to sequence of at least 3 chrs long. [char *] 334 * 335 * Return [UNKN ] Undocumented return value [codon] 336 * 337 */ 338 codon Wise2_codon_from_seq(char * seq); 339 #define codon_from_seq Wise2_codon_from_seq 340 341 342 /* Function: base4_codon_from_seq(seq) 343 * 344 * Descrip: Sometimes it is more useful to work in base64, ie, 345 * non N. this functions does the same thing as 346 * /codon_from_seq but produces a seq being 347 * 16*base1 + 4 *base2 + base3 348 * 349 * 350 * Arg: seq [UNKN ] pointer to sequence of at least 3 chrs long [char *] 351 * 352 * Return [UNKN ] Undocumented return value [int] 353 * 354 */ 355 int Wise2_base4_codon_from_seq(char * seq); 356 #define base4_codon_from_seq Wise2_base4_codon_from_seq 357 358 359 /* Function: char_from_base(b) 360 * 361 * Descrip: maps a base number (-04 inc) to A,T,G,C,N 362 * 363 * 364 * Arg: b [UNKN ] Undocumented argument [base] 365 * 366 * Return [UNKN ] Undocumented return value [char] 367 * 368 */ 369 char Wise2_char_from_base(base b); 370 #define char_from_base Wise2_char_from_base 371 372 373 /* Function: base_from_char(c) 374 * 375 * Descrip: maps a char (atcgn) to number, 376 * case insensitive, returns BASE_N 377 * if not atcgn 378 * 379 * 380 * Arg: c [UNKN ] Undocumented argument [char] 381 * 382 * Return [UNKN ] Undocumented return value [base] 383 * 384 */ 385 base Wise2_base_from_char(char c); 386 #define base_from_char Wise2_base_from_char 387 388 389 /* Function: char_complement_base(c) 390 * 391 * Descrip: the char equivalent of /complement_base. 392 * this gives the complement in char of a base 393 * in char. Does not check for non ATGCN 394 * 395 * 396 * Arg: c [UNKN ] Undocumented argument [char] 397 * 398 * Return [UNKN ] Undocumented return value [char] 399 * 400 */ 401 char Wise2_char_complement_base(char c); 402 #define char_complement_base Wise2_char_complement_base 403 404 405 /* Function: complement_base(b) 406 * 407 * Descrip: gives back the complement as a number 408 * ofthe base (given as a number) 409 * 410 * 411 * Arg: b [UNKN ] Undocumented argument [base] 412 * 413 * Return [UNKN ] Undocumented return value [base] 414 * 415 */ 416 base Wise2_complement_base(base b); 417 #define complement_base Wise2_complement_base 418 419 420 /* Function: four_fold_sites_CodonTable(*ct,seq) 421 * 422 * Descrip: returns the number of four fold degenerate 423 * sites in this codon 424 * 425 * 426 * Arg: *ct [UNKN ] Undocumented argument [CodonTable] 427 * Arg: seq [UNKN ] Undocumented argument [char *] 428 * 429 * Return [UNKN ] Undocumented return value [int] 430 * 431 */ 432 int Wise2_four_fold_sites_CodonTable(CodonTable *ct,char * seq); 433 #define four_fold_sites_CodonTable Wise2_four_fold_sites_CodonTable 434 435 436 /* Function: hard_link_CodonTable(obj) 437 * 438 * Descrip: Bumps up the reference count of the object 439 * Meaning that multiple pointers can 'own' it 440 * 441 * 442 * Arg: obj [UNKN ] Object to be hard linked [CodonTable *] 443 * 444 * Return [UNKN ] Undocumented return value [CodonTable *] 445 * 446 */ 447 CodonTable * Wise2_hard_link_CodonTable(CodonTable * obj); 448 #define hard_link_CodonTable Wise2_hard_link_CodonTable 449 450 451 /* Function: CodonTable_alloc(void) 452 * 453 * Descrip: Allocates structure: assigns defaults if given 454 * 455 * 456 * 457 * Return [UNKN ] Undocumented return value [CodonTable *] 458 * 459 */ 460 CodonTable * Wise2_CodonTable_alloc(void); 461 #define CodonTable_alloc Wise2_CodonTable_alloc 462 463 464 /* Function: free_CodonTable(obj) 465 * 466 * Descrip: Free Function: removes the memory held by obj 467 * Will chain up to owned members and clear all lists 468 * 469 * 470 * Arg: obj [UNKN ] Object that is free'd [CodonTable *] 471 * 472 * Return [UNKN ] Undocumented return value [CodonTable *] 473 * 474 */ 475 CodonTable * Wise2_free_CodonTable(CodonTable * obj); 476 #define free_CodonTable Wise2_free_CodonTable 477 478 479 /* Unplaced functions */ 480 /* There has been no indication of the use of these functions */ 481 482 483 /***************************************************/ 484 /* Internal functions */ 485 /* you are not expected to have to call these */ 486 /***************************************************/ 487 boolean Wise2_replace_name_CodonTable(CodonTable * obj,char * name); 488 #define replace_name_CodonTable Wise2_replace_name_CodonTable 489 char * Wise2_access_name_CodonTable(CodonTable * obj); 490 #define access_name_CodonTable Wise2_access_name_CodonTable 491 char * Wise2_alloc_aminoacid_from_seq(CodonTable * ct,char * seq); 492 #define alloc_aminoacid_from_seq Wise2_alloc_aminoacid_from_seq 493 494 #ifdef _cplusplus 495 } 496 #endif 497 498 #endif 499