ARB
ali_sequence.cxx
Go to the documentation of this file.
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 
19  unsigned char *seq_buf;
20  unsigned long i;
21 
22  seq_buf = seq;
23  for (i = 0; i < seq_len; i++, seq_buf++)
24  if (*seq_buf > 6)
25  ali_fatal_error("STOP");
26 
27  return 1;
28 }
29 
31  char *str, *str_buf;
32  unsigned char *seq_buf;
33  unsigned long i;
34 
35  str = (char *) CALLOC((unsigned int) seq_len + 1, sizeof(char));
36 
37  str_buf = str;
38  seq_buf = seq;
39  for (i = 0; i < seq_len; i++) {
40  *(str_buf++) = *(seq_buf++);
41  }
42  *str_buf = '\0';
43  ali_sequence_to_string((unsigned char*) str, seq_len);
44 
45  return str;
46 }
47 
48 // --------------------------
49 // ALI_NORM_SEQUENCE
50 
52  unsigned long counter;
53  unsigned char *s;
54  int dot_flag;
55  char *str;
56 
57  // Count only _BASES_
58  for (counter = 0, str = String; *str != '\0'; str++)
59  if (ali_is_base(*str))
60  counter++;
61  seq_len = counter;
62 
63  seq = (unsigned char*) CALLOC((unsigned int) seq_len, sizeof(unsigned char));
64  dots = (unsigned char **) CALLOC((unsigned int) (seq_len/8)+1, sizeof(unsigned char));
65  seq_name = ARB_strdup(Name);
66 
67  ali_out_of_memory_if(!seq || !dots || !seq_name);
68 
69  dot_flag = 0;
70  (*dots)[0] |= (unsigned char) (1<<7);
71  for (counter = 0, str = String, s = seq; *str != '\0'; str++) {
72  if (ali_is_base(*str)) {
73  *s++ = ali_base_to_number(*str);
74  dot_flag = 0;
75  counter++;
76  }
77  else {
78  if (dot_flag == 0 && ali_is_dot(*str)) {
79  (*dots)[(counter/8)] |= (unsigned char) (1<<(7-(counter%8)));
80  dot_flag = 1;
81  }
82  }
83  }
84 }
85 
87  unsigned long counter, pos;
88  unsigned char *s;
89  int dot_flag;
90  unsigned char *str;
91 
92  for (counter = pos = 0, str = SEQ->sequence();
93  pos < SEQ->length(); pos++, str++)
94  if (ali_is_base(*str))
95  counter++;
96  seq_len = counter;
97 
98  seq = (unsigned char*) CALLOC((unsigned int) seq_len, sizeof(unsigned char));
99  dots = (unsigned char **) CALLOC((unsigned int) (seq_len/8)+1, sizeof(unsigned char));
100  seq_name = ARB_strdup(SEQ->name());
101 
102  ali_out_of_memory_if(!seq || !dots || !seq_name);
103 
104  dot_flag = 0;
105  (*dots)[0] |= (unsigned char) (1<<7);
106  for (counter = pos = 0, str = SEQ->sequence(), s = seq;
107  pos < SEQ->length(); str++, pos++) {
108  if (ali_is_base(*str)) {
109  *s++ = *str;
110  dot_flag = 0;
111  counter++;
112  }
113  else {
114  if (dot_flag == 0 && ali_is_dot(*str)) {
115  (*dots)[(counter/8)] |= (unsigned char) (1<<(7-(counter%8)));
116  dot_flag = 1;
117  }
118  }
119  }
120 }
121 
123  char *str, *str_buf;
124  unsigned char *seq_buf;
125  unsigned long i;
126 
127  str = (char *) CALLOC((unsigned int) seq_len + 1, sizeof(char));
128  ali_out_of_memory_if(!str);
129 
130  for (i = seq_len, str_buf = str, seq_buf = seq; i-- > 0;)
131  *str_buf++ = *seq_buf++;
132  *str_buf = '\0';
133 
134  ali_sequence_to_string((unsigned char*) str, seq_len);
135 
136  return str;
137 }
138 
void ali_out_of_memory_if(bool cond)
Definition: ali_misc.hxx:52
int ali_is_base(char c)
Definition: ali_misc.hxx:66
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
unsigned char * sequence()
const char * String
Definition: gb_aci_impl.h:59
void * CALLOC(long i, long j)
Definition: ali_misc.hxx:56
unsigned char ali_base_to_number(char c, int no_gap_flag=0)
Definition: ali_misc.hxx:120
ALI_NORM_SEQUENCE(char *name, char *str)
char * str
Definition: defines.h:20
char * name()
char * string()
unsigned long length()
void ali_sequence_to_string(unsigned char *sequence, unsigned long length)
Definition: ali_misc.hxx:158
void ali_fatal_error(const char *message, const char *func)
Definition: ali_main.cxx:85
int ali_is_dot(char c)
Definition: ali_misc.hxx:96
GB_write_int const char s
Definition: AW_awar.cxx:156