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