~ubuntu-branches/ubuntu/intrepid/kalign/intrepid

« back to all changes in this revision

Viewing changes to kalign2_string_matching.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille, Charles Plessy, David Paleino, Andreas Tille
  • Date: 2008-03-18 09:54:17 UTC
  • mfrom: (2.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080318095417-cepxmgf2xsoxk84l
Tags: 2.03-2
[ Charles Plessy ]
* debian/control:
  - Add Subversion repository URL to debian/control.
  - Moved the Homepage: field out from the package's description.
  - Enhances: t-coffee.

[ David Paleino ]
* debian/kalign.1 added - manpages are now statically generated
* debian/control:
  - B-D updated (see above)
  - added myself to Uploaders
  - moved XS-Vcs-* fields to Vcs-*
* debian/rules:
  - reflecting static build of manpages
  - minor changes
* Updated to Standards-Version 3.7.3 (no changes needed)

[ Andreas Tille ]
* Added myself to Uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        kalign2_string_matching.c
 
3
        
 
4
        Released under GPL - see the 'COPYING' file   
 
5
        
 
6
        Copyright (C) 2006 Timo Lassmann <timolassmann@gmail.com>
 
7
        
 
8
        This program is free software; you can redistribute it and/or modify
 
9
        it under the terms of the GNU General Public License as published by
 
10
        the Free Software Foundation; either version 2 of the License, or
 
11
        any later version.
 
12
 
 
13
        This program is distributed in the hope that it will be useful,
 
14
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
        GNU General Public License for more details.
 
17
 
 
18
        You should have received a copy of the GNU General Public License
 
19
        along with this program; if not, write to the Free Software
 
20
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
    
 
22
        Please send bug reports, comments etc. to:
 
23
        timolassmann@gmail.com
 
24
*/
 
25
 
 
26
#include <string.h>
 
27
 
 
28
int byg_detect(int* text,int n)
 
29
{
 
30
        int Tc;
 
31
        int i  = 0;
 
32
        int s = 0;
 
33
        int T[256];
 
34
        for (i = 0;i < 256;i++){ 
 
35
                T[i] = 0; 
 
36
        }
 
37
        int mb = 1;
 
38
        //char *unique_aa = "EFILPQXZ";//permissiv
 
39
        //ABCDEFGHIJKLMNOPQRSTUVWXYZ
 
40
        char *unique_aa = "BDEFHIJKLMNOPQRSVWYZ";//restrictive
 
41
        int aacode[26] = {0,1,2,3,4,5,6,7,8,-1,9,10,11,12,23,13,14,15,16,17,17,18,19,20,21,22};
 
42
        for (i= 0;i < 20;i++){
 
43
                T[(int)aacode[unique_aa[i]-65]] |= 1;
 
44
        }
 
45
        for (i = 0;i < n;i++){
 
46
        //      fprintf(stderr,"%d\n",text[i]);
 
47
                if(text[i] != -1){
 
48
                        s <<= 1;
 
49
                        s |= 1;
 
50
                        Tc = T[text[i]];
 
51
                        s &= Tc;
 
52
                        if(s & mb){
 
53
                                return 0;
 
54
                        }
 
55
                }
 
56
        }
 
57
        return 1;
 
58
}
 
59
 
 
60
int check_identity(char* n,char*m)
 
61
{
 
62
        int len_n;
 
63
        int len_m;
 
64
        int i;
 
65
        
 
66
        len_n = strlen(n);
 
67
        len_m = strlen(m);
 
68
        if(len_m != len_n){
 
69
                return -1;
 
70
        }
 
71
        for (i = 0; i < len_n;i++){
 
72
                if(n[i] != m[i]){
 
73
                        return -1;
 
74
                }
 
75
        }
 
76
        return 1;
 
77
        
 
78
}
 
79
 
 
80
 
 
81
int byg_count(char* pattern,char*text)
 
82
{
 
83
        int Tc;
 
84
        int count = 0;
 
85
        int i  = 0;
 
86
        int s = 0;
 
87
        int T[256];
 
88
        for (i = 0;i < 256;i++){ 
 
89
                T[i] = 0; 
 
90
        }
 
91
        
 
92
        int m = strlen(pattern);
 
93
        int n = strlen (text);
 
94
        int mb = (1 << (m-1));
 
95
        
 
96
        for (i= 0;i < m;i++){
 
97
                T[(int)pattern[i]] |= (1 << i);
 
98
        }
 
99
 
 
100
        for (i = 0;i < n;i++){
 
101
                s <<= 1;
 
102
                s |= 1;
 
103
                Tc = T[(int)text[i]];
 
104
                s &= Tc;
 
105
                if(s & mb){
 
106
                        count++;
 
107
                }
 
108
        }
 
109
        return count;
 
110
}
 
111
 
 
112
int byg_end(char* pattern,char*text)
 
113
{
 
114
        int Tc;
 
115
        int i  = 0;
 
116
        int s = 0;
 
117
        int T[256];
 
118
        for (i = 0;i < 256;i++){ 
 
119
                T[i] = 0; 
 
120
        }
 
121
        
 
122
        int m = strlen(pattern);
 
123
        int n = strlen (text);
 
124
        int mb = (1 << (m-1));
 
125
 
 
126
        for (i= 0;i < m;i++){
 
127
                T[(int)pattern[i]] |= (1 << i);
 
128
        }
 
129
 
 
130
        for (i = 0;i < n;i++){
 
131
                s <<= 1;
 
132
                s |= 1;
 
133
                if(!text[i]){
 
134
                        return -1;
 
135
                }
 
136
                Tc = T[(int)text[i]];
 
137
                s &= Tc;
 
138
                if(s & mb){
 
139
                        return i+1;
 
140
                }
 
141
        }
 
142
        return -1;
 
143
}
 
144
 
 
145
int byg_start(char* pattern,char*text)
 
146
{
 
147
        int Tc;
 
148
        int i  = 0;
 
149
        int s = 0;
 
150
        int T[256];
 
151
        for (i = 0;i < 256;i++){ 
 
152
                T[i] = 0; 
 
153
        }
 
154
        
 
155
        int m = strlen(pattern);
 
156
        int n = strlen(text);
 
157
        int mb = (1 << (m-1));
 
158
        
 
159
        for (i= 0;i < m;i++){
 
160
                T[(int)pattern[i]] |= (1 << i);
 
161
        }
 
162
 
 
163
        for (i = 0;i < n;i++){
 
164
                s <<= 1;
 
165
                s |= 1;
 
166
                Tc = T[(int)text[i]];
 
167
                s &= Tc;
 
168
                if(s & mb){
 
169
                        return i-m+1;
 
170
                }
 
171
        }
 
172
        return -1;
 
173
}
 
174