File: ali_sequence.cxx

package info (click to toggle)
arb 6.0.6-8
  • links: PTS, VCS
  • area: non-free
  • in suites: sid, trixie
  • size: 66,204 kB
  • sloc: ansic: 394,911; cpp: 250,290; makefile: 19,644; sh: 15,879; perl: 10,473; fortran: 6,019; ruby: 683; xml: 503; python: 53; awk: 32
file content (146 lines) | stat: -rw-r--r-- 4,049 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// =============================================================== //
//                                                                 //
//   File      : ali_sequence.cxx                                  //
//   Purpose   :                                                   //
//                                                                 //
//   Institute of Microbiology (Technical University Munich)       //
//   http://www.arb-home.de/                                       //
//                                                                 //
// =============================================================== //

#include "ali_sequence.hxx"

// ---------------------
//      ALI_SEQUENCE

int ALI_SEQUENCE::check()
{
    unsigned char *seq_buf;
    unsigned long i;

    seq_buf = seq;
    for (i = 0; i < seq_len; i++, seq_buf++)
        if (*seq_buf > 6)
            ali_fatal_error("STOP");

    return 1;
}

char *ALI_SEQUENCE::string()
{
    char *str, *str_buf;
    unsigned char *seq_buf;
    unsigned long i;

    str = (char *) CALLOC((unsigned int) seq_len + 1, sizeof(char));

    str_buf = str;
    seq_buf = seq;
    for (i = 0; i < seq_len; i++) {
        *(str_buf++) = *(seq_buf++);
    }
    *str_buf = '\0';
    ali_sequence_to_string((unsigned char*) str, seq_len);

    return str;
}

// --------------------------
//      ALI_NORM_SEQUENCE

ALI_NORM_SEQUENCE::ALI_NORM_SEQUENCE(char *Name, char *String)
{
    unsigned long counter;
    unsigned char *s;
    int dot_flag;
    char *str;

    // Count only _BASES_
    for (counter = 0, str = String; *str != '\0'; str++)
        if (ali_is_base(*str))
            counter++;
    seq_len = counter;

    seq      = (unsigned char*) CALLOC((unsigned int) seq_len, sizeof(unsigned char));
    dots     = (unsigned char **) CALLOC((unsigned int) (seq_len/8)+1, sizeof(unsigned char));
    seq_name = strdup(Name);

    if (seq == 0 || dots == 0 || seq_name == 0) {
        ali_fatal_error("Out of memory");
    }

    dot_flag = 0;
    (*dots)[0] |= (unsigned char) (1<<7);
    for (counter = 0, str = String, s = seq; *str != '\0'; str++) {
        if (ali_is_base(*str)) {
            *s++ = ali_base_to_number(*str);
            dot_flag = 0;
            counter++;
        }
        else {
            if (dot_flag == 0 && ali_is_dot(*str)) {
                (*dots)[(counter/8)] |= (unsigned char) (1<<(7-(counter%8)));
                dot_flag = 1;
            }
        }
    }
}

ALI_NORM_SEQUENCE::ALI_NORM_SEQUENCE(ALI_SEQUENCE *SEQ)
{
    unsigned long counter, pos;
    unsigned char *s;
    int dot_flag;
    unsigned char *str;

    for (counter = pos = 0, str = SEQ->sequence();
         pos < SEQ->length(); pos++, str++)
        if (ali_is_base(*str))
            counter++;
    seq_len = counter;

    seq      = (unsigned char*) CALLOC((unsigned int) seq_len, sizeof(unsigned char));
    dots     = (unsigned char **) CALLOC((unsigned int) (seq_len/8)+1, sizeof(unsigned char));
    seq_name = strdup(SEQ->name());

    if (seq == 0 || dots == 0 || seq_name == 0) {
        ali_fatal_error("Out of memory");
    }

    dot_flag = 0;
    (*dots)[0] |= (unsigned char) (1<<7);
    for (counter = pos = 0, str = SEQ->sequence(), s = seq;
         pos < SEQ->length(); str++, pos++) {
        if (ali_is_base(*str)) {
            *s++ = *str;
            dot_flag = 0;
            counter++;
        }
        else {
            if (dot_flag == 0 && ali_is_dot(*str)) {
                (*dots)[(counter/8)] |= (unsigned char) (1<<(7-(counter%8)));
                dot_flag = 1;
            }
        }
    }
}

char *ALI_NORM_SEQUENCE::string()
{
    char *str, *str_buf;
    unsigned char *seq_buf;
    unsigned long i;

    str = (char *) CALLOC((unsigned int) seq_len + 1, sizeof(char));
    if (str == 0)
        ali_fatal_error("Out of memory");

    for (i = seq_len, str_buf = str, seq_buf = seq; i-- > 0;)
        *str_buf++ = *seq_buf++;
    *str_buf = '\0';

    ali_sequence_to_string((unsigned char*) str, seq_len);

    return str;
}