source: tags/ms_r16q3/NALIGNER/ali_sequence.cxx

Last change on this file was 15176, checked in by westram, 8 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : ali_sequence.cxx                                  //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include "ali_sequence.hxx"
12
13#include <arb_string.h>
14
15// ---------------------
16//      ALI_SEQUENCE
17
18int ALI_SEQUENCE::check()
19{
20    unsigned char *seq_buf;
21    unsigned long i;
22
23    seq_buf = seq;
24    for (i = 0; i < seq_len; i++, seq_buf++)
25        if (*seq_buf > 6)
26            ali_fatal_error("STOP");
27
28    return 1;
29}
30
31char *ALI_SEQUENCE::string()
32{
33    char *str, *str_buf;
34    unsigned char *seq_buf;
35    unsigned long i;
36
37    str = (char *) CALLOC((unsigned int) seq_len + 1, sizeof(char));
38
39    str_buf = str;
40    seq_buf = seq;
41    for (i = 0; i < seq_len; i++) {
42        *(str_buf++) = *(seq_buf++);
43    }
44    *str_buf = '\0';
45    ali_sequence_to_string((unsigned char*) str, seq_len);
46
47    return str;
48}
49
50// --------------------------
51//      ALI_NORM_SEQUENCE
52
53ALI_NORM_SEQUENCE::ALI_NORM_SEQUENCE(char *Name, char *String)
54{
55    unsigned long counter;
56    unsigned char *s;
57    int dot_flag;
58    char *str;
59
60    // Count only _BASES_
61    for (counter = 0, str = String; *str != '\0'; str++)
62        if (ali_is_base(*str))
63            counter++;
64    seq_len = counter;
65
66    seq      = (unsigned char*) CALLOC((unsigned int) seq_len, sizeof(unsigned char));
67    dots     = (unsigned char **) CALLOC((unsigned int) (seq_len/8)+1, sizeof(unsigned char));
68    seq_name = ARB_strdup(Name);
69
70    if (seq == 0 || dots == 0 || seq_name == 0) {
71        ali_fatal_error("Out of memory");
72    }
73
74    dot_flag = 0;
75    (*dots)[0] |= (unsigned char) (1<<7);
76    for (counter = 0, str = String, s = seq; *str != '\0'; str++) {
77        if (ali_is_base(*str)) {
78            *s++ = ali_base_to_number(*str);
79            dot_flag = 0;
80            counter++;
81        }
82        else {
83            if (dot_flag == 0 && ali_is_dot(*str)) {
84                (*dots)[(counter/8)] |= (unsigned char) (1<<(7-(counter%8)));
85                dot_flag = 1;
86            }
87        }
88    }
89}
90
91ALI_NORM_SEQUENCE::ALI_NORM_SEQUENCE(ALI_SEQUENCE *SEQ)
92{
93    unsigned long counter, pos;
94    unsigned char *s;
95    int dot_flag;
96    unsigned char *str;
97
98    for (counter = pos = 0, str = SEQ->sequence();
99         pos < SEQ->length(); pos++, str++)
100        if (ali_is_base(*str))
101            counter++;
102    seq_len = counter;
103
104    seq      = (unsigned char*) CALLOC((unsigned int) seq_len, sizeof(unsigned char));
105    dots     = (unsigned char **) CALLOC((unsigned int) (seq_len/8)+1, sizeof(unsigned char));
106    seq_name = ARB_strdup(SEQ->name());
107
108    if (seq == 0 || dots == 0 || seq_name == 0) {
109        ali_fatal_error("Out of memory");
110    }
111
112    dot_flag = 0;
113    (*dots)[0] |= (unsigned char) (1<<7);
114    for (counter = pos = 0, str = SEQ->sequence(), s = seq;
115         pos < SEQ->length(); str++, pos++) {
116        if (ali_is_base(*str)) {
117            *s++ = *str;
118            dot_flag = 0;
119            counter++;
120        }
121        else {
122            if (dot_flag == 0 && ali_is_dot(*str)) {
123                (*dots)[(counter/8)] |= (unsigned char) (1<<(7-(counter%8)));
124                dot_flag = 1;
125            }
126        }
127    }
128}
129
130char *ALI_NORM_SEQUENCE::string()
131{
132    char *str, *str_buf;
133    unsigned char *seq_buf;
134    unsigned long i;
135
136    str = (char *) CALLOC((unsigned int) seq_len + 1, sizeof(char));
137    if (str == 0)
138        ali_fatal_error("Out of memory");
139
140    for (i = seq_len, str_buf = str, seq_buf = seq; i-- > 0;)
141        *str_buf++ = *seq_buf++;
142    *str_buf = '\0';
143
144    ali_sequence_to_string((unsigned char*) str, seq_len);
145
146    return str;
147}
148
Note: See TracBrowser for help on using the repository browser.