annotate gecko/src/dictionaryFunctions.c @ 1:35af401890c0 draft

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