19 #define pn_assert(cond) arb_assert(cond)
24 char *table =
new char[256];
26 for (i=0; i<256; i++) {
28 case 'a':
case 'A': val =
AP_A;
break;
29 case 'g':
case 'G': val =
AP_G;
break;
30 case 'c':
case 'C': val =
AP_C;
break;
32 case 'u':
case 'U': val =
AP_T;
break;
33 case '-': val =
AP_GAP;
break;
46 default: val =
AP_DOT;
break;
56 long *AWT_translator::create_pro_to_bits()
const {
57 long *table = ARB_calloc<long>(256);
58 for (
int i = 0; i < max_aa; i++) {
59 int j = index_2_spro[i];
70 void AWT_translator::build_table(
unsigned char pbase,
const char *nuc) {
77 s2str[tolower(pbase)] =
str;
79 str->
index = max_aa++;
82 index_2_spro[str->
index] = pbase;
94 for (nucs = str->
nucs; nucs; nucs = nucs->
next) {
95 if ((!(nucs->
nucbits[0] & ~n0)) &&
97 (!(nucs->
nucbits[2] & ~n2)))
break;
100 if (nucs->
nucbits[0] != n0) c++;
101 if (nucs->
nucbits[1] != n1) c++;
102 if (nucs->
nucbits[2] != n2) c++;
144 for (
int off=0; codons[off]; off+=3) {
145 if (codon[0]==codons[off] && codon[1]==codons[off+1] && codon[2]==codons[off+2]) {
156 #define T2I_ENTRIES_MAX 196 // maximum number of generated translations (by code number 11)
159 distance_meter(
NULp),
160 code_nr(arb_protein_code_nr),
165 memset(s2str, 0,
sizeof(s2str));
166 memset(index_2_spro, 0,
sizeof(index_2_spro));
182 for (protein=
'*'; protein<=
'Z'; protein = (protein==
'*' ?
'A' : protein+1)) {
183 if (protein!=
'O' && protein!=
'U') {
185 if (protein==
'D') codons = D_codons;
186 else if (protein==
'N') codons = N_codons;
187 else if (protein==
'E') codons = E_codons;
188 else if (protein==
'Q') codons = Q_codons;
189 else if (protein==
'I') codons = I_codons;
190 else if (protein==
'L') codons = L_codons;
194 for (
int off=0; codons[off]; off+=3) {
196 memcpy(codon, codons+off, 3);
201 build_table(protein, codon);
204 else if (protein==
'J') {
206 build_table(protein, codon);
209 else if (protein==
'Z') {
211 build_table(protein, codon);
215 build_table(protein, codon);
231 build_table(
'-',
"---");
232 build_table(
'.',
"...");
233 build_table(
'.',
"???");
234 build_table(
'X',
"NNN");
238 pro_2_bitset = create_pro_to_bits();
244 delete [] nuc_2_bitset;
246 for (
int i=0; i<256; i++) {
247 if (i != tolower(i))
continue;
251 delete distance_meter;
256 return distance_meter;
267 s1 = translator->
S2str(p1);
268 s2 = translator->
S2str(p2);
269 if ((!s1) || (!s2))
return -1;
273 for (n1 = s1->
nucs; n1; n1=n1->
next) {
274 for (n2 = s2->
nucs; n2; n2=n2->
next) {
277 for (i=0; i<3; i++) {
281 if (dist< mindist) mindist = dist;
289 int max_aa = translator->
MaxAA();
290 int realmax_aa = translator->
RealmaxAA();
292 for (
int s = 0;
s< max_aa;
s++) {
297 for (
int i=0; i<2; i++) {
302 printf(
"Base %c[%i]: Dist to ", translator->
index2spro(
s),
s);
303 for (
int d = 0; d< max_aa; d++) {
305 for (i=0; i<3; i++) {
306 if (dist->
patd[i] & (1<<d))
break;
308 printf (
"%c%i ", translator->
index2spro(d), i);
319 memset(dist_, 0,
sizeof(dist_));
323 int max_aa = translator->
MaxAA();
324 int realmax_aa = translator->
RealmaxAA();
326 for (s = 0; s< max_aa; s++) {
330 for (i=0; i<3; i++) {
335 for (s = 0; s< max_aa; s++) {
336 for (
int d = 0; d< realmax_aa; d++) {
339 if (dist==0) dist_[
s]->
patd[0] |= 1<<d;
340 if (dist<=1) dist_[
s]->
patd[1] |= 1<<d;
343 dist_[
s]->
patd[0] |= 1<<
s;
346 for (s = 0; s< max_aa; s++) {
348 for (
int d = 0; d< realmax_aa; d++) {
349 if ((1 << d) & dist_[
s]->
patd[1]) {
350 sum |= dist_[d]->
patd[1];
353 dist_[
s]->
patd[2] |= sum;
357 awt_pro_a_nucs_debug(translator,
this);
362 for (
int i=0; i<64; i++) {
380 #define CACHED_TRANSLATORS 4
385 if (cached[0].isNull() || cached[0]->CodeNr() != code_nr) {
390 if (cached[i].isSet() && cached[i]->CodeNr() == code_nr) {
392 translator = cached[i];
398 if (translator.
isNull()) {
403 for (i = 0; i<CACHED_TRANSLATORS && translator.
isSet(); i++) {
410 pn_assert(cached[0]->CodeNr() == code_nr);
417 if (current_user_code_nr == -1) {
444 static int test_code_nr = -1;
445 #if defined(ENABLE_CRASH_TESTS)
446 static void translator_instance() {
451 void TEST_translator_instantiation() {
static int current_user_code_nr
char * AP_create_dna_to_ap_bases()
long GB_read_int(GBDATA *gbd)
const AWT_distance_meter * getDistanceMeter() const
const char * AP_get_codons(char protein, int code_nr)
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
AWT_distance_meter(const AWT_translator *translator)
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
const char * GBS_global_string(const char *templat,...)
void GBS_free_hash(GB_HASH *hs)
bool isNull() const
test if SmartPtr is NULp
void setNull()
set SmartPtr to NULp
#define CACHED_TRANSLATORS
struct arb_r2a_pro_2_nucs * nucs
bool isSet() const
test if SmartPtr is not NULp
static void user_code_nr_changed_cb(GBDATA *gb_awar)
GBDATA * GB_get_root(GBDATA *gbd)
struct arb_r2a_pro_2_nucs * next
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
size_t GBS_hash_elements(const GB_HASH *hs)
AWT_translator * AWT_get_user_translator(GBDATA *gb_main)
TYPE * ARB_calloc(size_t nelem)
static int codon_defined_in(const char *codon, const char *codons)
#define assert_or_exit(cond)
#define TEST_EXPECT_NO_SEGFAULT(cb)
AWT_translator(int arb_protein_code_nr)
#define AWAR_PROTEIN_TYPE
int AWT_default_protein_type(GBDATA *gb_main)
static int nuc_dist(const AWT_translator *translator, unsigned char p1, unsigned char p2)
GB_transaction ta(gb_var)
void AP_initialize_codon_tables()
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
unsigned char index2spro(int index) const
long GBS_read_hash(const GB_HASH *hs, const char *key)
const AWT_PDP * getDistance(int idx) const
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
AWT_translator * AWT_get_translator(int code_nr)
const arb_r2a_pro_2_nuc * S2str(int index) const
GB_write_int const char s