20 #define tl_assert(cond) arb_assert(cond)
25 tl_assert(codon_start >= 0 && codon_start<3);
38 if (gb_transl_table) error =
GB_delete(gb_transl_table);
42 if (gb_codon_start) error =
GB_delete(gb_codon_start);
57 arb_transl_table = -1;
63 if (gb_transl_table) {
66 if (arb_transl_table == -1) {
67 error =
GBS_global_string(
"Illegal (or unsupported) value (%i) in 'transl_table'", embl_table);
76 if (codon_start_value<1 || codon_start_value>3) {
77 error =
GBS_global_string(
"Illegal value (%i) in 'codon_start' (allowed: 1..3)", codon_start_value);
80 codon_start = codon_start_value-1;
83 else if (arb_transl_table != -1) {
86 if (!error) codon_start = 0;
90 if (!error && arb_transl_table != codon_start) {
91 if (arb_transl_table == -1) error =
"Found 'codon_start', but 'transl_table' is missing";
92 else if (codon_start == -1) error =
"Found 'transl_table', but 'codon_start' is missing";
102 inline void memcpy3(
char *dest,
const char *source) {
108 int translate_nuc2aa(
int arb_code_nr,
char *data,
size_t size,
size_t pos,
bool translate_all,
bool create_start_codon,
bool append_stop_codon,
int *translatedSize) {
122 bool create_stop_codon =
true;
126 for (
char *p = data; *p; p++) {
128 if ((c>=
'a') && (c<=
'z')) c = c+
'A'-
'a';
138 if (pos && translate_all) {
139 for (
char *p = data; p<data+pos; ++p) {
154 if (create_start_codon) {
159 for (
char *p = data+pos; i+2<size; p+=3, i+=3) {
162 char aa = translator.
codon2aa(codonBuf);
163 if (aa ==
'*') ++stops;
170 if (create_start_codon && startCodon) {
172 data[0] = startCodon;
175 bool last_is_stop = dest[-1] ==
'*';
177 if (create_stop_codon && translator.
isStopCodon(codonBuf)) {
182 else if (append_stop_codon) {
190 if (translatedSize) *translatedSize = dest-data;
202 static arb_test::match_expectation translates_into(
int arb_code_nr,
const char *dna,
const char *exp_transl,
int exp_stops,
int exp_size) {
205 size_t dna_len = strlen(dna);
209 int stops =
translate_nuc2aa(arb_code_nr, data, dna_len, 0,
false,
true,
true, &size);
212 const char *translated = data;
220 return all().ofgroup(expected);
223 #define TEST_TRANSLATION(nr,dna,aa,stp,siz) TEST_EXPECTATION(translates_into(nr,dna,aa,stp,siz))
224 #define TEST_TRANSLATION__WANTED(nr,dna,aa,stp,siz) TEST_EXPECTATION__WANTED(translates_into(nr,dna,aa,stp,siz))
225 #define e2a(ec) TTIT_embl2arb(ec)
227 void TEST_translate() {
228 TEST_TRANSLATION(e2a(1),
"TTYTCN",
"FS*", 1, 3);
231 TEST_TRANSLATION(e2a(2),
"ATCATCTTTTAR",
"MIF*", 1, 4);
232 TEST_TRANSLATION(e2a(2),
"ATYATYTTTTAR",
"MIF*", 1, 4);
233 TEST_TRANSLATION(e2a(2),
"ATAATATARTAR",
"MM**", 2, 4);
236 TEST_TRANSLATION(e2a(27),
"TGATGA",
"W*", 1, 2);
237 TEST_TRANSLATION(e2a(28),
"TGATGA",
"W*", 1, 2);
238 TEST_TRANSLATION(e2a(28),
"TAGTAG",
"Q*", 1, 2);
239 TEST_TRANSLATION(e2a(28),
"TAATAA",
"Q*", 1, 2);
240 TEST_TRANSLATION(e2a(28),
"TARTAR",
"Q*", 1, 2);
242 TEST_TRANSLATION(e2a(31),
"TAGTAG",
"E*", 1, 2);
243 TEST_TRANSLATION(e2a(31),
"TAATAA",
"E*", 1, 2);
244 TEST_TRANSLATION(e2a(31),
"TARTAR",
"E*", 1, 2);
char isStartCodon(const char *codon) const
GB_ERROR translate_removeInfo(GBDATA *gb_species)
char codon2aa(const char *codon) const
const char * GBS_global_string(const char *templat,...)
GB_ERROR GB_delete(GBDATA *&source)
int TTIT_embl2arb(int embl_code_nr)
void memcpy3(char *dest, const char *source)
char * ARB_strduplen(const char *p, unsigned len)
int translate_nuc2aa(int arb_code_nr, char *data, size_t size, size_t pos, bool translate_all, bool create_start_codon, bool append_stop_codon, int *translatedSize)
GB_ERROR translate_saveInfo(GBDATA *gb_species, int arb_transl_table, int codon_start)
int TTIT_arb2embl(int arb_code_nr)
static void error(const char *msg)
GB_ERROR translate_getInfo(GBDATA *gb_item, int &arb_transl_table, int &codon_start)
char isStopCodon(const char *codon) const
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
bool is_std_gap(const char c)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
GBDATA * GB_entry(GBDATA *father, const char *key)