2 Implementation of Nussinov Maximum Matching
12 #include "energy_par.h"
13 #include "fold_vars.h"
17 /* the encoded string MUST have the length of the sequence at position 0!!! */
18 PUBLIC unsigned int maximumMatching(const char *string){
19 unsigned int i, j, l, length, max = 0;
20 unsigned int *mm; /* holds maximum matching on subsequence [i,j] */
21 short *encodedString = encode_sequence(string, 0);
22 int *iindx = get_iindx((unsigned) encodedString[0]);
24 length = (unsigned int)encodedString[0];
25 mm = (unsigned int *) space(sizeof(unsigned int)*((length*(length+1))/2+2));
26 for(j = 1; j<=length; j++)
27 for(i=(j>TURN?(j-TURN):1); i<j; i++)
29 for(i=length-TURN-1;i>0; i--)
30 for(j=i+TURN+1; j<= length; j++){
31 max = mm[iindx[i]-j+1];
32 for(l=j-TURN-1; l>=i; l--)
33 if(pair[encodedString[l]][encodedString[j]])
34 max = MAX2(max, ((l>i) ? mm[iindx[i]-l+1] : 0) + 1 + mm[iindx[l+1]-j+1]);
37 max = mm[iindx[1]-length];
44 /* the encoded string MUST have the length of the sequence at position 0!!! */
45 PUBLIC unsigned int *maximumMatchingConstraint(const char *string, short *ptable){
46 unsigned int i, j, l, length, max = 0;
47 unsigned int *mm; /* holds maximum matching on subsequence [i,j] */
48 short *encodedString = encode_sequence(string, 0);
49 int *iindx = get_iindx((unsigned) encodedString[0]);
51 length = (unsigned int)encodedString[0];
52 mm = (unsigned int *) space(sizeof(unsigned int)*((length*(length+1))/2+2));
53 for(j = 1; j<=length; j++)
54 for(i=(j>TURN?(j-TURN):1); i<j; i++)
56 for(i=length-TURN-1;i>0; i--)
57 for(j=i+TURN+1; j<= length; j++){
58 max = mm[iindx[i]-j+1];
59 for(l=j-TURN-1; l>=i; l--){
60 if(pair[encodedString[l]][encodedString[j]]){
62 max = MAX2(max, ((l>i) ? mm[iindx[i]-l+1] : 0) + 1 + mm[iindx[l+1]-j+1]);
72 /* the encoded string MUST have the length of the sequence at position 0!!! */
73 PUBLIC unsigned int *maximumMatching2Constraint(const char *string, short *ptable, short *ptable2){
74 unsigned int i, j, l, length, max = 0;
75 unsigned int *mm; /* holds maximum matching on subsequence [i,j] */
76 short *encodedString = encode_sequence(string, 0);
77 int *iindx = get_iindx((unsigned) encodedString[0]);
79 length = (unsigned int)encodedString[0];
80 mm = (unsigned int *) space(sizeof(unsigned int)*((length*(length+1))/2+2));
81 for(j = 1; j<=length; j++)
82 for(i=(j>TURN?(j-TURN):1); i<j; i++)
84 for(i=length-TURN-1;i>0; i--)
85 for(j=i+TURN+1; j<= length; j++){
86 max = mm[iindx[i]-j+1];
87 for(l=j-TURN-1; l>=i; l--){
88 if(pair[encodedString[l]][encodedString[j]]){
89 if(ptable[l] != j && ptable2[l] != j)
90 max = MAX2(max, ((l>i) ? mm[iindx[i]-l+1] : 0) + 1 + mm[iindx[l+1]-j+1]);