modified: src1/common.h
[GalaxyCodeBases.git] / c_cpp / libgFileIO / chrseq.h
blob136d439818ec7e3cf05975ae897d19daba10a0d7
1 #ifndef _G_CHRSEQ_H
2 #define _G_CHRSEQ_H
4 #include <stdint.h> // int_fast8_t
5 #include <stdlib.h> // malloc
7 FORCE_INLINE void NormalizeChrSeq(char *seq){
8 while(*seq){
9 switch (*seq) {
10 case 'a': case 'A':
11 *seq = 'A';
12 break;
13 case 't': case 'T':
14 *seq = 'T';
15 break;
16 case 'c': case 'C':
17 *seq = 'C';
18 break;
19 case 'g': case 'G':
20 *seq = 'G';
21 break;
22 default:
23 *seq = 'N';
24 break;
25 } // Whether a looking-up array[64] can be faster ?
26 ++seq;
30 // *seq must have been Normalized to /[ATCGN]*/
31 FORCE_INLINE char *ChrSeqRevComp(char const * seq, size_t len){
32 char *revcomseq=malloc(len+1);
33 const char *tmpseqin=seq+len-1; // if len is shorter than real length, trim it.
34 char *tmpseqrc=revcomseq;
35 while(tmpseqin>=seq){
36 switch (*tmpseqin) {
37 case 'A':
38 *tmpseqrc++ = 'T';
39 break;
40 case 'T':
41 *tmpseqrc++ = 'A';
42 break;
43 case 'C':
44 *tmpseqrc++ = 'G';
45 break;
46 case 'G':
47 *tmpseqrc++ = 'C';
48 break;
49 default:
50 *tmpseqrc++ = 'N';
51 break;
52 } // Whether a looking-up array[32] can be faster ?
53 --tmpseqin;
55 *tmpseqrc++ = '\0';
56 return revcomseq;
59 #endif // chrseq.h