1 | /* |
---|
2 | * Copyright 1991 Steven Smith at the Harvard Genome Lab. |
---|
3 | * All rights reserved. |
---|
4 | */ |
---|
5 | #include "Flatio.c" |
---|
6 | |
---|
7 | |
---|
8 | main(ac,av) |
---|
9 | int ac; |
---|
10 | char **av; |
---|
11 | { |
---|
12 | struct data_format data[10000]; |
---|
13 | int Match = 2,Mismatch = 8; |
---|
14 | int i,j,k,l,numseqs,mis,Case = 32; |
---|
15 | int slen,pcnt,pos; |
---|
16 | int UT = FALSE; |
---|
17 | char c; |
---|
18 | if(ac < 3) |
---|
19 | { |
---|
20 | fprintf(stderr, |
---|
21 | "usage: %s search_string %%mismatch [-case] [-match color] [-mismatch color]\n", |
---|
22 | av[0]); |
---|
23 | fprintf(stderr," [-u=t]\n"); |
---|
24 | exit(0); |
---|
25 | } |
---|
26 | for (j=3;j<ac;j++) |
---|
27 | { |
---|
28 | if(strcmp("-case",av[j]) == 0) |
---|
29 | Case = 0; |
---|
30 | if(strcmp("-match",av[j]) == 0) |
---|
31 | sscanf(av[j+1],"%d",&Match); |
---|
32 | if(strcmp("-u=t",av[j]) == 0) |
---|
33 | UT = TRUE; |
---|
34 | if(strcmp("-mismatch",av[j]) == 0) |
---|
35 | sscanf(av[j+1],"%d",&Mismatch); |
---|
36 | } |
---|
37 | numseqs = ReadFlat(stdin,data,10000); |
---|
38 | |
---|
39 | slen = strlen(av[1]); |
---|
40 | sscanf(av[2],"%d",&pcnt); |
---|
41 | pcnt *= slen; |
---|
42 | pcnt /= 100; |
---|
43 | |
---|
44 | if(UT) |
---|
45 | for(j=0;j<=strlen(av[1]);j++) |
---|
46 | { |
---|
47 | if(av[1][j] == 't') |
---|
48 | av[1][j] = 'u'; |
---|
49 | if(av[1][j] == 'T') |
---|
50 | av[1][j] = 'U'; |
---|
51 | } |
---|
52 | |
---|
53 | for(i=0;i<numseqs;i++) |
---|
54 | { |
---|
55 | if(UT) |
---|
56 | for(j=0;data[i].nuc[j]!='\0';j++) |
---|
57 | { |
---|
58 | if(data[i].nuc[j] == 't') |
---|
59 | data[i].nuc[j] = 'u'; |
---|
60 | else if(data[i].nuc[j] == 'T') |
---|
61 | data[i].nuc[j] = 'U'; |
---|
62 | } |
---|
63 | printf("name:%s\n",data[i].name); |
---|
64 | printf("length:%zu\n",strlen(data[i].nuc)); |
---|
65 | printf("start:\n"); |
---|
66 | for(j=0;j<data[i].length;j++) |
---|
67 | { |
---|
68 | mis = 0; |
---|
69 | for(k=0,pos=j;k<slen && pos<data[i].length;k++,pos++) |
---|
70 | { |
---|
71 | c = data[i].nuc[pos]; |
---|
72 | for(;(c == ' ' || c == '-' || c == '~') && |
---|
73 | pos < data[i].length;) |
---|
74 | c = data[i].nuc[++pos]; |
---|
75 | c |= Case; |
---|
76 | |
---|
77 | if(data[i].type == '#') |
---|
78 | { |
---|
79 | if(CompIUP(c,(av[1][k]|Case)) == FALSE) |
---|
80 | mis++; |
---|
81 | } |
---|
82 | else |
---|
83 | { |
---|
84 | if(c!=(av[1][k]|Case)) |
---|
85 | mis++; |
---|
86 | } |
---|
87 | } |
---|
88 | if(k == slen && mis<=pcnt) |
---|
89 | { |
---|
90 | for(k=j;k<pos;k++) |
---|
91 | printf("%d\n",Match); |
---|
92 | j = pos-1; |
---|
93 | } |
---|
94 | else |
---|
95 | printf("%d\n",Mismatch); |
---|
96 | } |
---|
97 | } |
---|
98 | exit(0); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | int CompIUP(a,b) |
---|
103 | char a,b; |
---|
104 | { |
---|
105 | static int tmatr[16] = {'-','a','c','m','g','r','s','v', |
---|
106 | 't','w','y','h','k','d','b','n'}; |
---|
107 | |
---|
108 | static int matr[128] = { |
---|
109 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00, |
---|
110 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
---|
111 | 0x01,0xe,0x02,0x0d,0,0,0x04,0x0b,0,0,0x0c,0,0x03,0x0f,0,0,0,0x05,0x06, |
---|
112 | 0x08,0x08,0x07,0x09,0x00,0xa,0,0,0,0,0,0,0,0x01,0x0e,0x02,0x0d,0,0,0x04, |
---|
113 | 0x0b,0,0,0x0c,0,0x03,0x0f,0,0,0,0x05,0x06,0x08,0x08,0x07,0x09,0x00,0x0a, |
---|
114 | 0,0,0,0,0x00,0 |
---|
115 | }; |
---|
116 | |
---|
117 | |
---|
118 | int testa,testb; |
---|
119 | |
---|
120 | if(a&32 != b&32) |
---|
121 | return(FALSE); |
---|
122 | |
---|
123 | testa = matr[(int)a]; |
---|
124 | testb = matr[(int)b]; |
---|
125 | return(testa&testb); |
---|
126 | } |
---|