1 |
gpertea |
2 |
#include "gdna.h" |
2 |
|
|
#include <string.h> |
3 |
|
|
|
4 |
|
|
#define IUPAC_DEFS "AaCcTtGgUuMmRrWwSsYyKkVvHhDdBbNnXx-*" |
5 |
|
|
#define IUPAC_COMP "TtGgAaCcAaKkYyWwSsRrMmBbDdHhVvNnXx-*" |
6 |
|
|
|
7 |
|
|
unsigned char ntCompTable[256]; |
8 |
|
|
|
9 |
|
|
static bool gdna_ntCompTableReady=ntCompTableInit(); |
10 |
|
|
|
11 |
|
|
char ntComplement(char c) { |
12 |
|
|
return ntCompTable[(int)c]; |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
//in place reverse complement of nucleotide (sub)sequence |
16 |
|
|
char* reverseComplement(char* seq, int slen) { |
17 |
|
|
if (slen==0) slen=strlen(seq); |
18 |
|
|
//reverseChars(seq,len); |
19 |
|
|
int l=0; |
20 |
|
|
int r=slen-1; |
21 |
|
|
register char c; |
22 |
|
|
while (l<r) { |
23 |
|
|
c=seq[l];seq[l]=seq[r]; |
24 |
gpertea |
144 |
seq[r]=c; //this was: Gswap(str[l],str[r]); |
25 |
gpertea |
2 |
l++;r--; |
26 |
|
|
} |
27 |
|
|
for (int i=0;i<slen;i++) seq[i]=ntComplement(seq[i]); |
28 |
|
|
return seq; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
bool ntCompTableInit() { |
32 |
|
|
//if (gdna_ntCompTableReady) return true; |
33 |
|
|
char n[]=IUPAC_DEFS; |
34 |
|
|
char c[]=IUPAC_COMP; |
35 |
|
|
int l=strlen(IUPAC_DEFS); |
36 |
|
|
ntCompTable[0]=0; |
37 |
|
|
for (int ch=1;ch<256;ch++) { |
38 |
|
|
ntCompTable[ch]=0; |
39 |
|
|
for (int i=0;i<l;i++) |
40 |
|
|
if (ch==n[i]) { |
41 |
|
|
ntCompTable[ch]=c[i]; |
42 |
|
|
break; |
43 |
|
|
} |
44 |
|
|
if (ntCompTable[ch]==0) |
45 |
|
|
ntCompTable[ch]='N'; |
46 |
|
|
} |
47 |
|
|
//gdna_ntCompTableReady=true; |
48 |
|
|
return true; |
49 |
|
|
} |