1 \hypertarget{pair__mat_8h}{\section{pair\-\_\-mat.\-h}
2 \label{pair__mat_8h}\index{/home/asherstnev/\-Projects/\-Java.\-projects/jabaws/secure-\/git/develop/binaries/src/\-Vienna\-R\-N\-A/\-H/pair\-\_\-mat.\-h@{/home/asherstnev/\-Projects/\-Java.\-projects/jabaws/secure-\/git/develop/binaries/src/\-Vienna\-R\-N\-A/\-H/pair\-\_\-mat.\-h}}
6 00001 \textcolor{preprocessor}{#include <ctype.h>}
7 00002 \textcolor{preprocessor}{#include "\hyperlink{utils_8h}{utils.h}"}
8 00003 \textcolor{preprocessor}{#include "\hyperlink{fold__vars_8h}{fold\_vars.h}"}
10 00005 \textcolor{preprocessor}{#define NBASES 8}
11 00006 \textcolor{preprocessor}{}\textcolor{comment}{/*@notnull@*/}
13 00008 \textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} Law\_and\_Order[] = \textcolor{stringliteral}{"\_ACGUTXKI"};
14 00009 \textcolor{keyword}{static} \textcolor{keywordtype}{int} BP\_pair[NBASES][NBASES]=
15 00010 \textcolor{comment}{/* \_ A C G U X K I */}
16 00011 \{\{ 0, 0, 0, 0, 0, 0, 0, 0\},
17 00012 \{ 0, 0, 0, 0, 5, 0, 0, 5\},
18 00013 \{ 0, 0, 0, 1, 0, 0, 0, 0\},
19 00014 \{ 0, 0, 2, 0, 3, 0, 0, 0\},
20 00015 \{ 0, 6, 0, 4, 0, 0, 0, 6\},
21 00016 \{ 0, 0, 0, 0, 0, 0, 2, 0\},
22 00017 \{ 0, 0, 0, 0, 0, 1, 0, 0\},
23 00018 \{ 0, 6, 0, 0, 5, 0, 0, 0\}\};
25 00020 \textcolor{preprocessor}{#define MAXALPHA 20 }\textcolor{comment}{/* maximal length of alphabet */}\textcolor{preprocessor}{}
26 00021 \textcolor{preprocessor}{}
27 00022 \textcolor{keyword}{static} \textcolor{keywordtype}{short} alias[\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}+1];
28 00023 \textcolor{keyword}{static} \textcolor{keywordtype}{int} pair[\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}+1][\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}+1];
29 00024 \textcolor{comment}{/* rtype[pair[i][j]]:=pair[j][i] */}
30 00025 \textcolor{keyword}{static} \textcolor{keywordtype}{int} rtype[8] = \{0, 2, 1, 4, 3, 6, 5, 7\};
32 00027 \textcolor{preprocessor}{#ifdef \_OPENMP}
33 00028 \textcolor{preprocessor}{}\textcolor{preprocessor}{#pragma omp threadprivate(Law\_and\_Order, BP\_pair, alias, pair, rtype)}
34 00029 \textcolor{preprocessor}{}\textcolor{preprocessor}{#endif}
35 00030 \textcolor{preprocessor}{}
36 00031 \textcolor{comment}{/* for backward compatibility */}
37 00032 \textcolor{preprocessor}{#define ENCODE(c) encode\_char(c)}
38 00033 \textcolor{preprocessor}{}
39 00034 \textcolor{keyword}{static} \textcolor{keywordtype}{int} encode\_char(\textcolor{keywordtype}{char} c) \{
40 00035 \textcolor{comment}{/* return numerical representation of base used e.g. in pair[][] */}
41 00036 \textcolor{keywordtype}{int} code;
42 00037 \textcolor{keywordflow}{if} (energy\_set>0) code = (int) (c-\textcolor{charliteral}{'A'})+1;
43 00038 \textcolor{keywordflow}{else} \{
44 00039 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *pos;
45 00040 pos = strchr(Law\_and\_Order, c);
46 00041 \textcolor{keywordflow}{if} (pos==NULL) code=0;
47 00042 \textcolor{keywordflow}{else} code = (int) (pos-Law\_and\_Order);
48 00043 \textcolor{keywordflow}{if} (code>5) code = 0;
49 00044 \textcolor{keywordflow}{if} (code>4) code--; \textcolor{comment}{/* make T and U equivalent */}
51 00046 \textcolor{keywordflow}{return} code;
54 00049 \textcolor{comment}{/*@+boolint +charint@*/}
55 00050 \textcolor{comment}{/*@null@*/}
56 00051 \textcolor{keyword}{extern} \textcolor{keywordtype}{char} *\hyperlink{fold__vars_8h_a2695d91cc535d09c2eae5c3884e2ec64}{nonstandards};
57 00052 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} \hyperlink{utils_8h_a127ce946e56b5a5773781cabe68e38c5}{nrerror}(\textcolor{keyword}{const} \textcolor{keywordtype}{char} message[]);
58 00053 \textcolor{keyword}{static} \textcolor{keywordtype}{void} make\_pair\_matrix(\textcolor{keywordtype}{void})
60 00055 \textcolor{keywordtype}{int} i,j;
62 00057 \textcolor{keywordflow}{if} (energy\_set==0) \{
63 00058 \textcolor{keywordflow}{for} (i=0; i<5; i++) alias[i] = (\textcolor{keywordtype}{short}) i;
64 00059 alias[5] = 3; \textcolor{comment}{/* X <-> G */}
65 00060 alias[6] = 2; \textcolor{comment}{/* K <-> C */}
66 00061 alias[7] = 0; \textcolor{comment}{/* I <-> default base '@' */}
67 00062 \textcolor{keywordflow}{for} (i=0; i<NBASES; i++) \{
68 00063 \textcolor{keywordflow}{for} (j=0; j<NBASES; j++)
69 00064 pair[i][j] = BP\_pair[i][j];
71 00066 \textcolor{keywordflow}{if} (noGU) pair[3][4] = pair[4][3] =0;
72 00067 \textcolor{keywordflow}{if} (nonstandards!=NULL) \{ \textcolor{comment}{/* allow nonstandard bp's */}
73 00068 \textcolor{keywordflow}{for} (i=0; i<(int)strlen(nonstandards); i+=2)
74 00069 pair[encode\_char(nonstandards[i])]
75 00070 [encode\_char(nonstandards[i+1])]=7;
77 00072 \textcolor{keywordflow}{for} (i=0; i<NBASES; i++) \{
78 00073 \textcolor{keywordflow}{for} (j=0; j<NBASES; j++)
79 00074 rtype[pair[i][j]] = pair[j][i];
81 00076 \} \textcolor{keywordflow}{else} \{
82 00077 \textcolor{keywordflow}{for} (i=0; i<=\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}; i++) \{
83 00078 \textcolor{keywordflow}{for} (j=0; j<=\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}; j++)
86 00081 \textcolor{keywordflow}{if} (energy\_set==1) \{
87 00082 \textcolor{keywordflow}{for} (i=1; i<\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA};) \{
88 00083 alias[i++] = 3; \textcolor{comment}{/* A <-> G */}
89 00084 alias[i++] = 2; \textcolor{comment}{/* B <-> C */}
91 00086 \textcolor{keywordflow}{for} (i=1; i<\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}; i++) \{
92 00087 pair[i][i+1] = 2; \textcolor{comment}{/* AB <-> GC */}
94 00089 pair[i][i-1] = 1; \textcolor{comment}{/* BA <-> CG */}
97 00092 \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (energy\_set==2) \{
98 00093 \textcolor{keywordflow}{for} (i=1; i<\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA};) \{
99 00094 alias[i++] = 1; \textcolor{comment}{/* A <-> A*/}
100 00095 alias[i++] = 4; \textcolor{comment}{/* B <-> U */}
102 00097 \textcolor{keywordflow}{for} (i=1; i<\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}; i++) \{
103 00098 pair[i][i+1] = 5; \textcolor{comment}{/* AB <-> AU */}
105 00100 pair[i][i-1] = 6; \textcolor{comment}{/* BA <-> UA */}
108 00103 \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (energy\_set==3) \{
109 00104 \textcolor{keywordflow}{for} (i=1; i<MAXALPHA-2; ) \{
110 00105 alias[i++] = 3; \textcolor{comment}{/* A <-> G */}
111 00106 alias[i++] = 2; \textcolor{comment}{/* B <-> C */}
112 00107 alias[i++] = 1; \textcolor{comment}{/* C <-> A */}
113 00108 alias[i++] = 4; \textcolor{comment}{/* D <-> U */}
115 00110 \textcolor{keywordflow}{for} (i=1; i<MAXALPHA-2; i++) \{
116 00111 pair[i][i+1] = 2; \textcolor{comment}{/* AB <-> GC */}
118 00113 pair[i][i-1] = 1; \textcolor{comment}{/* BA <-> CG */}
120 00115 pair[i][i+1] = 5; \textcolor{comment}{/* CD <-> AU */}
122 00117 pair[i][i-1] = 6; \textcolor{comment}{/* DC <-> UA */}
125 00120 \textcolor{keywordflow}{else} \hyperlink{utils_8h_a127ce946e56b5a5773781cabe68e38c5}{nrerror}(\textcolor{stringliteral}{"What energy\_set are YOU using??"});
126 00121 \textcolor{keywordflow}{for} (i=0; i<=\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}; i++) \{
127 00122 \textcolor{keywordflow}{for} (j=0; j<=\hyperlink{data__structures_8h_a05a5ffe718aa431d97419a12fb082379}{MAXALPHA}; j++)
128 00123 rtype[pair[i][j]] = pair[j][i];
133 00128 \textcolor{keyword}{static} \textcolor{keywordtype}{short} *encode\_sequence(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *sequence, \textcolor{keywordtype}{short} how)\{
134 00129 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} i,l = (\textcolor{keywordtype}{unsigned} int)strlen(sequence);
135 00130 \textcolor{keywordtype}{short} *S = (\textcolor{keywordtype}{short} *) \hyperlink{utils_8h_ad7e1e137b3bf1f7108933d302a7f0177}{space}(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{short})*(l+2));
137 00132 \textcolor{keywordflow}{switch}(how)\{
138 00133 \textcolor{comment}{/* standard encoding as always used for S */}
139 00134 \textcolor{keywordflow}{case} 0: \textcolor{keywordflow}{for}(i=1; i<=l; i++) \textcolor{comment}{/* make numerical encoding of sequence */}
140 00135 S[i]= (\textcolor{keywordtype}{short}) encode\_char(toupper(sequence[i-1]));
142 00137 S[0] = (short) l;
143 00138 \textcolor{keywordflow}{break};
144 00139 \textcolor{comment}{/* encoding for mismatches of nostandard bases (normally used for S1) */}
145 00140 \textcolor{keywordflow}{case} 1: \textcolor{keywordflow}{for}(i=1; i<=l; i++)
146 00141 S[i] = alias[(\textcolor{keywordtype}{short}) encode\_char(toupper(sequence[i-1]))];
149 00144 \textcolor{keywordflow}{break};
152 00147 \textcolor{keywordflow}{return} S;