Go backward to Header File
Go up to Base Sequence Module
Executable Code
File name: bases.c
/* These numbers are designed so base k always pairs with base (k+2)%4.
The order corresponds to that in bases.h.
*/
char *base_names = "ACTG";
/* Given a string including ACTG's, turn it into an array of up to n
ints 0-3 in the given place. */
void read_bases (s, n, out, nout)
char *s;
int n;
int *out;
int *nout;
{
int k=0;
while (*s && k<n) {
int i;
for(i=0;i<4;i++){
if (base_names[i] == *s) {
out[k++] = i;
break;
}
}
s++;
}
*nout = k;
}
/* Print all the 1-letter codes for the bases in the given strand
of length n. */
void print_bases (strand, n)
int *strand;
int n;
{
int i;
for(i=0;i<n;i++){
putchar(base_names[strand[i]]);
}
}
/* Print all the 1-letter codes for the bases in the given strand
of length n. */
void print_reverse (strand, n)
int *strand;
int n;
{
int i;
for(i=n-1;i>=0;i--){
putchar(base_names[strand[i]]);
}
}
/* Reverse the order of bases in the given strand and write
to the output strand. */
void reverse_strand (s_in, n, s_out)
int *s_in;
int n;
int *s_out;
{
int i;
for(i=0;i<n;i++){
s_out[n-1-i] = s_in[i];
}
}
- Michael P. Frank, September 12, 1995.
Formatted using
HyperLaTeX-1.3.