~ubuntu-branches/debian/jessie/arb/jessie

« back to all changes in this revision

Viewing changes to SL/HELIX/BI_helix.cxx

  • Committer: Package Import Robot
  • Author(s): Elmar Pruesse, Andreas Tille, Elmar Pruesse
  • Date: 2014-09-02 15:15:06 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140902151506-jihq58b3iz342wif
Tags: 6.0.2-1
[ Andreas Tille ]
* New upstream version
  Closes: #741890
* debian/upstream -> debian/upstream/metadata
* debian/control:
   - Build-Depends: added libglib2.0-dev
   - Depends: added mafft, mrbayes
* debian/rules
   - Add explicite --remove-section=.comment option to manual strip call
* cme fix dpkg-control
* arb-common.dirs: Do not create unneeded lintian dir
* Add turkish debconf translation (thanks for the patch to Mert Dirik
  <mertdirik@gmail.com>)
  Closes: #757497

[ Elmar Pruesse ]
* patches removed:
   - 10_config.makefiles.patch,
     80_no_GL.patch
       removed in favor of creating file from config.makefile.template via 
       sed in debian/control
   - 20_Makefile_main.patch
       merged upstream
   - 21_Makefiles.patch
       no longer needed
   - 30_tmpfile_CVE-2008-5378.patch: 
       merged upstream
   - 50_fix_gcc-4.8.patch:
       merged upstream
   - 40_add_libGLU.patch:
       libGLU not needed for arb_ntree)
   - 60_use_debian_packaged_raxml.patch:
       merged upstream
   - 70_hardening.patch
       merged upstream
   - 72_add_math_lib_to_linker.patch
       does not appear to be needed
* patches added:
   - 10_upstream_r12793__show_db_load_progress:
       backported patch showing progress while ARB is loading a database
       (needed as indicator/splash screen while ARB is launching)
   - 20_upstream_r12794__socket_permissions:
       backported security fix
   - 30_upstream_r12814__desktop_keywords:
       backported add keywords to desktop (fixes lintian warning)
   - 40_upstream_r12815__lintian_spelling:
       backported fix for lintian reported spelling errors
   - 50_private_nameservers
       change configuration to put nameservers into users home dirs
       (avoids need for shared writeable directory)
   - 60_use_debian_phyml
       use phyml from debian package for both interfaces in ARB
* debian/rules:
   - create config.makefile from override_dh_configure target
   - use "make tarfile" in override_dh_install
   - remove extra cleaning not needed for ARB 6
   - use "dh_install --list-missing" to avoid missing files
   - added override_dh_fixperms target
* debian/control:
   - added libarb-dev package
   - Depends: added phyml, xdg-utils
   - Suggests: removed phyml
   - fix lintian duplicate-short-description (new descriptions)
* debian/*.install:
   - "unrolled" confusing globbing to select files
   - pick files from debian/tmp
   - moved all config files to /etc/arb
* debian/arb-common.templates: updated
* scripts:
   - removed arb-add-pt-server
   - launch-wrapper: 
     - only add demo.arb to newly created $ARBUSERDATA
     - pass commandline arguments through bin/arb wrapper
   - preinst: removing old PT server index files on upgrade from 5.5*
   - postinst: set setgid on shared PT dir
* rewrote arb.1 manfile
* added file icon for ARB databases
* using upstream arb_tcp.dat

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
#include <ctype.h>
5
 
// #include <malloc.h>
6
 
#include <arbdb.h>
 
1
// =============================================================== //
 
2
//                                                                 //
 
3
//   File      : BI_helix.cxx                                      //
 
4
//   Purpose   :                                                   //
 
5
//                                                                 //
 
6
//   Institute of Microbiology (Technical University Munich)       //
 
7
//   http://www.arb-home.de/                                       //
 
8
//                                                                 //
 
9
// =============================================================== //
 
10
 
 
11
#include "BI_helix.hxx"
 
12
 
7
13
#include <arbdbt.h>
8
14
 
9
 
#include "BI_helix.hxx"
 
15
#include <cctype>
10
16
 
11
17
#define LEFT_HELIX "{[<("
12
18
#define RIGHT_HELIX "}]>)"
22
28
    char    c;
23
29
};
24
30
 
25
 
void BI_helix::_init(void)
 
31
void BI_helix::_init()
26
32
{
27
33
    int i;
28
 
    for (i=0;i<HELIX_MAX; i++) pairs[i] = 0;
29
 
    for (i=0;i<HELIX_MAX; i++) char_bind[i] = 0;
 
34
    for (i=0; i<HELIX_MAX; i++) pairs[i] = 0;
 
35
    for (i=0; i<HELIX_MAX; i++) char_bind[i] = 0;
30
36
 
31
37
    entries = 0;
32
38
    Size = 0;
34
40
    pairs[HELIX_NONE]=strdup("");
35
41
    char_bind[HELIX_NONE] = strdup(" ");
36
42
 
37
 
    pairs[HELIX_STRONG_PAIR]=strdup("CG");
38
 
    char_bind[HELIX_STRONG_PAIR] = strdup("-");
 
43
    pairs[HELIX_STRONG_PAIR]=strdup("CG AT AU");
 
44
    char_bind[HELIX_STRONG_PAIR] = strdup("~");
39
45
 
40
 
    pairs[HELIX_PAIR]=strdup("AU GU");
 
46
    pairs[HELIX_PAIR]=strdup("GT GU");
41
47
    char_bind[HELIX_PAIR] = strdup("-");
42
48
 
43
 
    pairs[HELIX_WEAK_PAIR]=strdup("GA GT");
44
 
    char_bind[HELIX_WEAK_PAIR] = strdup(".");
 
49
    pairs[HELIX_WEAK_PAIR]=strdup("GA");
 
50
    char_bind[HELIX_WEAK_PAIR] = strdup("=");
45
51
 
46
 
    pairs[HELIX_NO_PAIR]=strdup("AA AC CC CT CU TU");
 
52
    pairs[HELIX_NO_PAIR]=strdup("AA AC CC CT CU GG TU");
47
53
    char_bind[HELIX_NO_PAIR] = strdup("#");
48
54
 
49
55
    pairs[HELIX_USER0]=strdup(".A .C .G .T .U");
50
 
    char_bind[HELIX_USER0] = strdup("?");
 
56
    char_bind[HELIX_USER0] = strdup("*");
51
57
 
52
58
    pairs[HELIX_USER1]=strdup("-A -C -G -T -U");
53
59
    char_bind[HELIX_USER1] = strdup("#");
54
60
 
55
 
    pairs[HELIX_USER2]=strdup(".. --");
56
 
    char_bind[HELIX_USER2] = strdup(" ");
 
61
    pairs[HELIX_USER2]=strdup("UU TT");
 
62
    char_bind[HELIX_USER2] = strdup("+");
57
63
 
58
 
    pairs[HELIX_USER3]=strdup(".-");
59
 
    char_bind[HELIX_USER3] = strdup(" ");
 
64
    pairs[HELIX_USER3]=strdup("");
 
65
    char_bind[HELIX_USER3] = strdup("");
60
66
 
61
67
    pairs[HELIX_DEFAULT]=strdup("");
62
 
    char_bind[HELIX_DEFAULT] = strdup("?");
 
68
    char_bind[HELIX_DEFAULT] = strdup("");
63
69
 
64
 
    for (i=HELIX_NON_STANDARD0;i<=HELIX_NON_STANDARD9;i++){
 
70
    for (i=HELIX_NON_STANDARD0; i<=HELIX_NON_STANDARD9; i++) {
65
71
        pairs[i] = strdup("");
66
72
        char_bind[i] = strdup("");
67
73
    }
70
76
    char_bind[HELIX_NO_MATCH] = strdup("|");
71
77
}
72
78
 
73
 
BI_helix::BI_helix(void) {
 
79
BI_helix::BI_helix() {
74
80
    _init();
75
81
}
76
82
 
77
 
BI_helix::~BI_helix(void){
 
83
BI_helix::~BI_helix() {
78
84
    unsigned i;
79
 
    for (i=0;i<HELIX_MAX; i++)  free(pairs[i]);
80
 
    for (i=0;i<HELIX_MAX; i++)  free(char_bind[i]);
 
85
    for (i=0; i<HELIX_MAX; i++) free(pairs[i]);
 
86
    for (i=0; i<HELIX_MAX; i++) free(char_bind[i]);
81
87
 
82
88
    if (entries) {
83
89
        for (i = 0; i<Size; ++i) {
89
95
    }
90
96
}
91
97
 
92
 
long BI_helix_check_error(const char *key, long val, void *) {
 
98
static long BI_helix_check_error(const char *key, long val, void *) {
93
99
    struct helix_stack *stack = (struct helix_stack *)val;
94
100
    if (!BI_helix::get_error() && stack) { // don't overwrite existing error
95
101
        BI_helix::set_error(GBS_global_string("Too many '%c' in Helix '%s' pos %li", stack->c, key, stack->pos));
98
104
}
99
105
 
100
106
 
101
 
long BI_helix_free_hash(const char *, long val, void *) {
 
107
static long BI_helix_free_hash(const char *, long val, void *) {
102
108
    struct helix_stack *stack = (struct helix_stack *)val;
103
109
    struct helix_stack *next;
104
 
    for ( ; stack; stack = next) {
 
110
    for (; stack; stack = next) {
105
111
        next = stack->next;
106
112
        delete stack;
107
113
    }
115
121
*/
116
122
{
117
123
    clear_error();
118
 
    
 
124
 
119
125
    GB_HASH *hash = GBS_create_hash(256, GB_IGNORE_CASE);
120
 
    size_t pos;
121
 
    char c;
122
 
    char ident[256];
123
 
    char *sident;
124
 
    struct helix_stack *laststack = 0,*stack;
 
126
    size_t   pos;
 
127
    char     c;
 
128
    char     ident[256];
 
129
    char    *sident;
 
130
    
 
131
    struct helix_stack *laststack = 0, *stack;
125
132
 
126
133
    Size = sizei;
127
134
 
132
139
 
133
140
        char *h = (char *)malloc(Size+1);
134
141
        h[Size] = 0;
135
 
        
136
 
        if (len<Size) memset(h+len,'.', Size-len);
 
142
 
 
143
        if (len<Size) memset(h+len, '.', Size-len);
137
144
        memcpy(h, helix_in, len);
138
145
        helix = h;
139
146
    }
146
153
        char *h = (char *)malloc((int)Size+1);
147
154
        h[Size] = 0;
148
155
 
149
 
        if (len<Size) memset(h+len,'.',(int)(Size-len));
 
156
        if (len<Size) memset(h+len, '.', (int)(Size-len));
150
157
        memcpy(h, helix_nr_in, len);
151
158
        helix_nr = h;
152
159
    }
153
160
 
154
 
    strcpy(ident,"0");
 
161
    strcpy(ident, "0");
155
162
    long pos_scanned_till = -1;
156
163
 
157
 
    entries = (struct BI_helix_entry *)GB_calloc(sizeof(struct BI_helix_entry),(size_t)Size);
 
164
    entries = (BI_helix_entry *)GB_calloc(sizeof(BI_helix_entry), (size_t)Size);
158
165
    sident  = 0;
159
 
    
160
 
    for (pos = 0; pos < Size; pos ++ ) {
 
166
 
 
167
    for (pos = 0; pos < Size; pos ++) {
161
168
        if (helix_nr) {
162
169
            if (long(pos)>pos_scanned_till && isalnum(helix_nr[pos])) {
163
170
                for (int j=0; (pos+j)<Size; j++) {
174
181
            }
175
182
        }
176
183
        c = helix[pos];
177
 
        if (strchr(LEFT_HELIX,c) || strchr(LEFT_NONS,c)  ){ // push
178
 
            laststack = (struct helix_stack *)GBS_read_hash(hash,ident);
 
184
        if (strchr(LEFT_HELIX, c) || strchr(LEFT_NONS, c)) { // push
 
185
            laststack = (struct helix_stack *)GBS_read_hash(hash, ident);
179
186
            stack = new helix_stack;
180
187
            stack->next = laststack;
181
188
            stack->pos = pos;
182
189
            stack->c = c;
183
 
            GBS_write_hash(hash,ident,(long)stack);
 
190
            GBS_write_hash(hash, ident, (long)stack);
184
191
        }
185
 
        else if (strchr(RIGHT_HELIX,c) || strchr(RIGHT_NONS,c) ){   // pop
186
 
            stack = (struct helix_stack *)GBS_read_hash(hash,ident);
 
192
        else if (strchr(RIGHT_HELIX, c) || strchr(RIGHT_NONS, c)) { // pop
 
193
            stack = (struct helix_stack *)GBS_read_hash(hash, ident);
187
194
            if (!stack) {
188
195
                bi_assert(!helix_error); // already have an error
189
196
                helix_error = GBS_global_string_copy("Too many '%c' in Helix '%s' pos %zu", c, ident, pos);
190
197
                goto helix_end;
191
198
            }
192
 
            if (strchr(RIGHT_HELIX,c)) {
 
199
            if (strchr(RIGHT_HELIX, c)) {
193
200
                entries[pos].pair_type = HELIX_PAIR;
194
201
                entries[stack->pos].pair_type = HELIX_PAIR;
195
 
            }else{
 
202
            }
 
203
            else {
196
204
                c = tolower(c);
197
205
                if (stack->c != c) {
198
206
                    bi_assert(!helix_error); // already have an error
203
211
                if (isalpha(c)) {
204
212
                    entries[pos].pair_type = (BI_PAIR_TYPE)(HELIX_NON_STANDARD0+c-'a');
205
213
                    entries[stack->pos].pair_type = (BI_PAIR_TYPE)(HELIX_NON_STANDARD0+c-'a');
206
 
                }else{
 
214
                }
 
215
                else {
207
216
                    entries[pos].pair_type = HELIX_NO_PAIR;
208
217
                    entries[stack->pos].pair_type = HELIX_NO_PAIR;
209
218
                }
210
219
            }
211
220
            entries[pos].pair_pos = stack->pos;
212
221
            entries[stack->pos].pair_pos = pos;
213
 
            GBS_write_hash(hash,ident,(long)stack->next);
 
222
            GBS_write_hash(hash, ident, (long)stack->next);
214
223
 
215
 
            if (sident == 0 || strcmp(sident+1,ident) != 0) {
 
224
            if (sident == 0 || strcmp(sident+1, ident) != 0) {
216
225
                sident = (char*)malloc(strlen(ident)+2);
217
 
                sprintf(sident,"-%s",ident);
218
 
                
 
226
                sprintf(sident, "-%s", ident);
 
227
 
219
228
                entries[stack->pos].allocated = true;
220
229
            }
221
230
            entries[pos].helix_nr        = sident+1;
228
237
 
229
238
    GBS_hash_do_loop(hash, BI_helix_check_error, NULL);
230
239
 
231
 
 helix_end:
 
240
 helix_end :
232
241
    GBS_hash_do_loop(hash, BI_helix_free_hash, NULL);
233
242
    GBS_free_hash(hash);
234
243
 
241
250
 
242
251
const char *BI_helix::init(GBDATA *gb_helix_nr, GBDATA *gb_helix, size_t sizei) {
243
252
    clear_error();
244
 
    
 
253
 
245
254
    if (!gb_helix) set_error("Can't find SAI:HELIX");
246
255
    else if (!gb_helix_nr) set_error("Can't find SAI:HELIX_NR");
247
256
    else {
248
257
        GB_transaction ta(gb_helix);
249
258
        initFromData(GB_read_char_pntr(gb_helix_nr), GB_read_char_pntr(gb_helix), sizei);
250
259
    }
251
 
    
 
260
 
252
261
    return get_error();
253
262
}
254
263
 
258
267
    clear_error();
259
268
 
260
269
    GBDATA *gb_sai_data = GBT_get_SAI_data(gb_main);
261
 
    long    size2       = GBT_get_alignment_len(gb_main,alignment_name);
 
270
    long    size2       = GBT_get_alignment_len(gb_main, alignment_name);
262
271
 
263
272
    if (size2<=0) set_error(GB_await_error());
264
273
    else {
267
276
        GBDATA *gb_helix        = 0;
268
277
        GBDATA *gb_helix_nr     = 0;
269
278
 
270
 
        if (gb_helix_nr_con)    gb_helix_nr = GBT_read_sequence(gb_helix_nr_con,alignment_name);
271
 
        if (gb_helix_con)       gb_helix = GBT_read_sequence(gb_helix_con,alignment_name);
 
279
        if (gb_helix_nr_con)    gb_helix_nr = GBT_read_sequence(gb_helix_nr_con, alignment_name);
 
280
        if (gb_helix_con)       gb_helix = GBT_read_sequence(gb_helix_con, alignment_name);
272
281
 
273
282
        init(gb_helix_nr, gb_helix, size2);
274
283
    }
293
302
 
294
303
const char *BI_helix::init(GBDATA *gb_main) {
295
304
    GB_transaction ta(gb_main);
296
 
    
 
305
 
297
306
    char       *alignment_name = GBT_get_default_alignment(gb_main);
298
307
    const char *err            = init(gb_main, alignment_name);
299
308
 
305
314
    int   len = strlen(pairs[pair_type])-1;
306
315
    char *pai = pairs[pair_type];
307
316
 
308
 
    for (int i=0; i<len;i+=3){
 
317
    for (int i=0; i<len; i+=3) {
309
318
        if ((pai[i] == left && pai[i+1] == right) ||
310
319
            (pai[i] == right && pai[i+1] == left)) return true;
311
320
    }
321
330
 
322
331
    left  = toupper(left);
323
332
    right = toupper(right);
324
 
    switch(pair_type) {
 
333
    switch (pair_type) {
325
334
        case HELIX_PAIR:
326
 
            if (is_pairtype(left,right,HELIX_STRONG_PAIR) ||
327
 
                is_pairtype(left,right,HELIX_PAIR)) return 2;
328
 
            if (is_pairtype(left,right,HELIX_WEAK_PAIR) ) return 1;
 
335
            if (is_pairtype(left, right, HELIX_STRONG_PAIR) ||
 
336
                is_pairtype(left, right, HELIX_PAIR)) return 2;
 
337
            if (is_pairtype(left, right, HELIX_WEAK_PAIR)) return 1;
329
338
            return 0;
330
339
 
331
340
        case HELIX_NO_PAIR:
332
 
            if (is_pairtype(left,right,HELIX_STRONG_PAIR) ||
333
 
                is_pairtype(left,right,HELIX_PAIR) ) return 0;
 
341
            if (is_pairtype(left, right, HELIX_STRONG_PAIR) ||
 
342
                is_pairtype(left, right, HELIX_PAIR)) return 0;
334
343
            return 1;
335
 
            
 
344
 
336
345
        default:
337
 
            return is_pairtype(left,right,pair_type) ? 1 : 0;
 
346
            return is_pairtype(left, right, pair_type) ? 1 : 0;
338
347
    }
339
348
}
340
349
 
355
364
            }
356
365
        }
357
366
 
358
 
        size_t q = p<Size ? p-2: Size-1;
 
367
        size_t q = p<Size ? p-2 : Size-1;
359
368
 
360
369
        for (p = pos; p <= q; ++p) {
361
370
            bi_assert(entries[p].next_pair_pos == 0);
385
394
    return pos;
386
395
}
387
396
 
388
 
 
389
 
 
390
 
 
391
 
/***************************************************************************************
392
 
*******         Reference to abs pos                    ********
393
 
****************************************************************************************/
394
 
void BI_ecoli_ref::bi_exit(void){
395
 
    delete [] abs2rel;
396
 
    delete [] rel2abs;
397
 
    abs2rel = 0;
398
 
    rel2abs = 0;
399
 
}
400
 
 
401
 
BI_ecoli_ref::BI_ecoli_ref(void) {
402
 
    memset((char *)this,0,sizeof(BI_ecoli_ref));
403
 
}
404
 
 
405
 
BI_ecoli_ref::~BI_ecoli_ref(void){
406
 
    bi_exit();
407
 
}
408
 
 
409
 
inline bool isGap(char c) { return c == '-' || c == '.'; }
410
 
 
411
 
const char *BI_ecoli_ref::init(const char *seq, size_t size) {
412
 
    bi_exit();
413
 
 
414
 
    abs2rel = new size_t[size];
415
 
    rel2abs = new size_t[size];
416
 
    memset((char *)rel2abs,0,(size_t)(sizeof(*rel2abs)*size));
417
 
 
418
 
    relLen = 0;
419
 
    absLen = size;
420
 
    size_t i;
421
 
    size_t sl = strlen(seq);
422
 
    for (i=0; i<size; i++) {
423
 
        abs2rel[i]      = relLen;
424
 
        rel2abs[relLen] = i;
425
 
        if (i<sl && !isGap(seq[i])) ++relLen;
426
 
    }
427
 
    return 0;
428
 
}
429
 
 
430
 
const char *BI_ecoli_ref::init(GBDATA *gb_main,char *alignment_name, char *ref_name) {
431
 
    GB_transaction ta(gb_main);
432
 
 
433
 
    GB_ERROR err  = 0;
434
 
    long     size = GBT_get_alignment_len(gb_main,alignment_name);
435
 
    
436
 
    if (size<=0) err = GB_await_error();
437
 
    else {
438
 
        GBDATA *gb_ref_con   = GBT_find_SAI(gb_main, ref_name);
439
 
        if (!gb_ref_con) err = GBS_global_string("I cannot find the SAI '%s'",ref_name);
440
 
        else {
441
 
            GBDATA *gb_ref   = GBT_read_sequence(gb_ref_con,alignment_name);
442
 
            if (!gb_ref) err = GBS_global_string("Your SAI '%s' has no sequence '%s/data'", ref_name, alignment_name);
443
 
            else {
444
 
                err = init(GB_read_char_pntr(gb_ref), size);
445
 
            }
446
 
        }
447
 
    }
448
 
    return err;
449
 
}
450
 
 
451
 
const char *BI_ecoli_ref::init(GBDATA *gb_main) {
452
 
    GB_transaction ta(gb_main);
453
 
 
454
 
    char     *ref = GBT_get_default_ref(gb_main);
455
 
    char     *use = GBT_get_default_alignment(gb_main);
456
 
    GB_ERROR  err = init(gb_main,use,ref);
457
 
 
458
 
    free(ref);
459
 
    free(use);
460
 
 
461
 
    return err;
462
 
}