/** * Returns the value of the named attribute as nucleotide identified */ unsigned char seqfeat_get_attrib_nuc(const SeqFeature *sf, const char *name) { char *str; str = seqfeat_get_attrib_str(sf, name); if(strlen(str) != 1) { g_error("%s:%d: attribute '%s' value '%s' does not look like nucleotide", __FILE__, __LINE__, name, str); } return nuc_char_to_id(str[0]); }
/** * Returns the degeneracy of the provided position in the provided * codon. The provided codon should be an array of length 3 containing * NUC identifiers representing nucleotides (defined in nuc.h) The idx * (codon position) argument must be either 0,1, or 2. The degeneracy * is how many of the 3 possible nucleotide changes at the given * position would result in a synonymous change (either 0, 1, 2, or * 3). 0 is returned if the codon contains an ambiguity nucleotide * (e.g. an N). */ int aa_codon_degeneracy(const unsigned char *codon, const int idx) { int change_count; int nuc_id, aa_id, new_aa_id, i; unsigned char new_codon[3]; if((idx < 0) || (idx > 2)) { g_error("%s:%d: codon idx must be 0, 1 or 2", __FILE__, __LINE__); } nuc_id = nuc_char_to_id(codon[idx]); aa_id = aa_codon_to_id(codon); /* this is an ambiguous amino acid, just return 0 */ if(aa_id == AA_X) { return 0; } /* Try every other nucleotide at the specified position * Count when amino acid is different. */ new_codon[0] = codon[0]; new_codon[1] = codon[1]; new_codon[2] = codon[2]; change_count = 0; for(i = 0; i < NUM_REAL_NUCS; i++) { if(i == nuc_id) { continue; } new_codon[idx] = i; new_aa_id = aa_codon_to_id(new_codon); if(new_aa_id == AA_X) { /* too complicated to handle codons with ambiguity symbols */ return 0; } if(aa_id != new_aa_id) { change_count++; } } return 3 - change_count; }