1
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <ctype.h>
|
|
5 #include <inttypes.h>
|
|
6 #include "structs.h"
|
|
7 #include "commonFunctions.h"
|
|
8
|
|
9 int seq2word(char* buf, int wsize, word* w) {
|
|
10 int i;
|
|
11 int b = 6;
|
|
12 memset(w, 0, sizeof(word));
|
|
13
|
|
14 for (i = 0; i < wsize; i++) {
|
|
15 if (buf[i] >= 4)
|
|
16 return -1;
|
|
17 w->b[i / 4] |= buf[i] << b;
|
|
18 b -= 2;
|
|
19 if (b < 0)
|
|
20 b = 6;
|
|
21 }
|
|
22 return 0;
|
|
23 }
|
|
24
|
|
25 void skipIDLine(FILE *fIn) {
|
|
26 char c;
|
|
27 // first line (skip ID fasta Line)
|
|
28 c = fgetc(fIn);
|
|
29 while (c != '\n')
|
|
30 c = fgetc(fIn);
|
|
31 }
|
|
32
|
|
33 int letterToIndex(char c) {
|
|
34 // coding (a=0,c=1,g=2,t=3,'>'=4 others=9 )
|
|
35 switch (c) {
|
|
36 case 'A':
|
|
37 return 0;
|
|
38 case 'C':
|
|
39 return 1;
|
|
40 case 'G':
|
|
41 return 2;
|
|
42 case 'T':
|
|
43 return 3;
|
|
44 case '>':
|
|
45 return 4;
|
|
46 default:
|
|
47 return 9;
|
|
48 }
|
|
49 }
|
|
50
|
|
51 int wordcmp(unsigned char *w1, unsigned char *w2, int n) {
|
|
52
|
|
53 int i = 0, limit;
|
|
54
|
|
55 if(n%4 != 0){
|
|
56 w1[n/4] = w1[n/4] >> (2*(3-((n-1)%4)));
|
|
57 w1[n/4] = w1[n/4] << (2*(3-((n-1)%4)));
|
|
58 w2[n/4] = w2[n/4] >> (2*(3-((n-1)%4)));
|
|
59 w2[n/4] = w2[n/4] << (2*(3-((n-1)%4)));
|
|
60 limit=(n/4)+1;
|
|
61 } else {
|
|
62 limit = n/4;
|
|
63 }
|
|
64
|
|
65 for (i=0;i<limit;i++) {
|
|
66 if (w1[i]<w2[i]) return -1;
|
|
67 if (w1[i]>w2[i]) return +1;
|
|
68 }
|
|
69 return 0;
|
|
70 }
|
|
71
|
|
72 void showWord(word* w, char *ws) {
|
|
73 char Alf[] = { 'A', 'C', 'G', 'T' };
|
|
74 int i;
|
|
75 int wsize = 8;
|
|
76 unsigned char c;
|
|
77 for (i = 0; i < wsize; i++) {
|
|
78 c = w->b[i];
|
|
79 c = c >> 6;
|
|
80 ws[4*i] = Alf[(int) c];
|
|
81 c = w->b[i];
|
|
82 c = c << 2;
|
|
83 c = c >> 6;
|
|
84 ws[4*i+1] = Alf[(int) c];
|
|
85 c = w->b[i];
|
|
86 c = c << 4;
|
|
87 c = c >> 6;
|
|
88 ws[4*i+2] = Alf[(int) c];
|
|
89 c = w->b[i];
|
|
90 c = c << 6;
|
|
91 c = c >> 6;
|
|
92 ws[4*i+3] = Alf[(int) c];
|
|
93 }
|
|
94 }
|