1\hypertarget{pair__mat_8h_source}{}\doxysection{pair\+\_\+mat.\+h}
2\label{pair__mat_8h_source}\index{ViennaRNA/pair\_mat.h@{ViennaRNA/pair\_mat.h}}
3
4\begin{DoxyCode}{0}
5\DoxyCodeLine{00001 \textcolor{preprocessor}{\#ifndef VIENNA\_RNA\_PACKAGE\_PAIR\_MAT\_H}}
6\DoxyCodeLine{00002 \textcolor{preprocessor}{\#define VIENNA\_RNA\_PACKAGE\_PAIR\_MAT\_H}}
7\DoxyCodeLine{00003 }
8\DoxyCodeLine{00004 \textcolor{preprocessor}{\#include <ctype.h>}}
9\DoxyCodeLine{00005 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{utils_2basic_8h}{ViennaRNA/utils/basic.h}}>}}
10\DoxyCodeLine{00006 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{fold__vars_8h}{ViennaRNA/fold\_vars.h}}>}}
11\DoxyCodeLine{00007 }
12\DoxyCodeLine{00008 \textcolor{preprocessor}{\#define NBASES 8}}
13\DoxyCodeLine{00009 \textcolor{comment}{/*@notnull@*/}}
14\DoxyCodeLine{00010 }
15\DoxyCodeLine{00011 \textcolor{preprocessor}{\#ifndef INLINE}}
16\DoxyCodeLine{00012 \textcolor{preprocessor}{\# ifdef \_\_GNUC\_\_}}
17\DoxyCodeLine{00013 \textcolor{preprocessor}{\#  define INLINE inline}}
18\DoxyCodeLine{00014 \textcolor{preprocessor}{\# else}}
19\DoxyCodeLine{00015 \textcolor{preprocessor}{\#  define INLINE}}
20\DoxyCodeLine{00016 \textcolor{preprocessor}{\# endif}}
21\DoxyCodeLine{00017 \textcolor{preprocessor}{\#endif}}
22\DoxyCodeLine{00018 }
23\DoxyCodeLine{00019 \textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} Law\_and\_Order[]         = \textcolor{stringliteral}{"{}\_ACGUTXKI"{}};}
24\DoxyCodeLine{00020 \textcolor{keyword}{static} \textcolor{keywordtype}{int}        BP\_pair[NBASES][NBASES] =}
25\DoxyCodeLine{00021   \textcolor{comment}{/* \_  A  C  G  U  X  K  I */}}
26\DoxyCodeLine{00022 \{ \{ 0, 0, 0, 0, 0, 0, 0, 0 \},}
27\DoxyCodeLine{00023   \{ 0, 0, 0, 0, 5, 0, 0, 5 \},}
28\DoxyCodeLine{00024   \{ 0, 0, 0, 1, 0, 0, 0, 0 \},}
29\DoxyCodeLine{00025   \{ 0, 0, 2, 0, 3, 0, 0, 0 \},}
30\DoxyCodeLine{00026   \{ 0, 6, 0, 4, 0, 0, 0, 6 \},}
31\DoxyCodeLine{00027   \{ 0, 0, 0, 0, 0, 0, 2, 0 \},}
32\DoxyCodeLine{00028   \{ 0, 0, 0, 0, 0, 1, 0, 0 \},}
33\DoxyCodeLine{00029   \{ 0, 6, 0, 0, 5, 0, 0, 0 \} \};}
34\DoxyCodeLine{00030 }
35\DoxyCodeLine{00031 \textcolor{preprocessor}{\#define MAXALPHA 20       }\textcolor{comment}{/* maximal length of alphabet */}\textcolor{preprocessor}{}}
36\DoxyCodeLine{00032 }
37\DoxyCodeLine{00033 \textcolor{keyword}{static} \textcolor{keywordtype}{short}  alias[\mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}} + 1];}
38\DoxyCodeLine{00034 \textcolor{keyword}{static} \textcolor{keywordtype}{int}    pair[\mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}} + 1][\mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}} + 1];}
39\DoxyCodeLine{00035 \textcolor{comment}{/* rtype[pair[i][j]]:=pair[j][i] */}}
40\DoxyCodeLine{00036 \textcolor{keyword}{static} \textcolor{keywordtype}{int}    rtype[8] = \{}
41\DoxyCodeLine{00037   0, 2, 1, 4, 3, 6, 5, 7}
42\DoxyCodeLine{00038 \};}
43\DoxyCodeLine{00039 }
44\DoxyCodeLine{00040 \textcolor{preprocessor}{\#ifdef \_OPENMP}}
45\DoxyCodeLine{00041 \textcolor{preprocessor}{\#pragma omp threadprivate(Law\_and\_Order, BP\_pair, alias, pair, rtype)}}
46\DoxyCodeLine{00042 \textcolor{preprocessor}{\#endif}}
47\DoxyCodeLine{00043 }
48\DoxyCodeLine{00044 \textcolor{comment}{/* for backward compatibility */}}
49\DoxyCodeLine{00045 \textcolor{preprocessor}{\#define ENCODE(c) encode\_char(c)}}
50\DoxyCodeLine{00046 }
51\DoxyCodeLine{00047 \textcolor{keyword}{static} INLINE \textcolor{keywordtype}{int}}
52\DoxyCodeLine{00048 encode\_char(\textcolor{keywordtype}{char} c)}
53\DoxyCodeLine{00049 \{}
54\DoxyCodeLine{00050   \textcolor{comment}{/* return numerical representation of base used e.g. in pair[][] */}}
55\DoxyCodeLine{00051   \textcolor{keywordtype}{int} code;}
56\DoxyCodeLine{00052 }
57\DoxyCodeLine{00053   c = toupper(c);}
58\DoxyCodeLine{00054 }
59\DoxyCodeLine{00055   \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_gafb1ef1166da85092ae8a325e02dcae71}{energy\_set}} > 0) \{}
60\DoxyCodeLine{00056     code = (int)(c -\/ \textcolor{charliteral}{'A'}) + 1;}
61\DoxyCodeLine{00057   \} \textcolor{keywordflow}{else} \{}
62\DoxyCodeLine{00058     \textcolor{keyword}{const} \textcolor{keywordtype}{char} *pos;}
63\DoxyCodeLine{00059     pos = strchr(Law\_and\_Order, c);}
64\DoxyCodeLine{00060     \textcolor{keywordflow}{if} (pos == NULL)}
65\DoxyCodeLine{00061       code = 0;}
66\DoxyCodeLine{00062     \textcolor{keywordflow}{else}}
67\DoxyCodeLine{00063       code = (int)(pos -\/ Law\_and\_Order);}
68\DoxyCodeLine{00064 }
69\DoxyCodeLine{00065     \textcolor{keywordflow}{if} (code > 5)}
70\DoxyCodeLine{00066       code = 0;}
71\DoxyCodeLine{00067 }
72\DoxyCodeLine{00068     \textcolor{keywordflow}{if} (code > 4)}
73\DoxyCodeLine{00069       code-\/-\/;           \textcolor{comment}{/* make T and U equivalent */}}
74\DoxyCodeLine{00070   \}}
75\DoxyCodeLine{00071 }
76\DoxyCodeLine{00072   \textcolor{keywordflow}{return} code;}
77\DoxyCodeLine{00073 \}}
78\DoxyCodeLine{00074 }
79\DoxyCodeLine{00075 }
80\DoxyCodeLine{00076 \textcolor{comment}{/*@+boolint +charint@*/}}
81\DoxyCodeLine{00077 \textcolor{comment}{/*@null@*/}}
82\DoxyCodeLine{00078 \textcolor{keyword}{extern} \textcolor{keywordtype}{char} *\mbox{\hyperlink{group__model__details_ga2695d91cc535d09c2eae5c3884e2ec64}{nonstandards}};}
83\DoxyCodeLine{00079 }
84\DoxyCodeLine{00080 \textcolor{keyword}{static} INLINE \textcolor{keywordtype}{void}}
85\DoxyCodeLine{00081 make\_pair\_matrix(\textcolor{keywordtype}{void})}
86\DoxyCodeLine{00082 \{}
87\DoxyCodeLine{00083   \textcolor{keywordtype}{int} i, j;}
88\DoxyCodeLine{00084 }
89\DoxyCodeLine{00085   \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_gafb1ef1166da85092ae8a325e02dcae71}{energy\_set}} == 0) \{}
90\DoxyCodeLine{00086     \textcolor{keywordflow}{for} (i = 0; i < 5; i++)}
91\DoxyCodeLine{00087       alias[i] = (\textcolor{keywordtype}{short})i;}
92\DoxyCodeLine{00088     alias[5]  = 3;  \textcolor{comment}{/* X <-\/> G */}}
93\DoxyCodeLine{00089     alias[6]  = 2;  \textcolor{comment}{/* K <-\/> C */}}
94\DoxyCodeLine{00090     alias[7]  = 0;  \textcolor{comment}{/* I <-\/> default base '@' */}}
95\DoxyCodeLine{00091     \textcolor{keywordflow}{for} (i = 0; i < NBASES; i++)}
96\DoxyCodeLine{00092       \textcolor{keywordflow}{for} (j = 0; j < NBASES; j++)}
97\DoxyCodeLine{00093         pair[i][j] = BP\_pair[i][j];}
98\DoxyCodeLine{00094     \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_gabf380d09e4f1ab94fc6af57cf0ad5d32}{noGU}})}
99\DoxyCodeLine{00095       pair[3][4] = pair[4][3] = 0;}
100\DoxyCodeLine{00096 }
101\DoxyCodeLine{00097     \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_ga2695d91cc535d09c2eae5c3884e2ec64}{nonstandards}} != NULL) \{}
102\DoxyCodeLine{00098       \textcolor{comment}{/* allow nonstandard bp's */}}
103\DoxyCodeLine{00099       \textcolor{keywordflow}{for} (i = 0; i < (int)strlen(\mbox{\hyperlink{group__model__details_ga2695d91cc535d09c2eae5c3884e2ec64}{nonstandards}}); i += 2)}
104\DoxyCodeLine{00100         pair[encode\_char(\mbox{\hyperlink{group__model__details_ga2695d91cc535d09c2eae5c3884e2ec64}{nonstandards}}[i])]}
105\DoxyCodeLine{00101         [encode\_char(\mbox{\hyperlink{group__model__details_ga2695d91cc535d09c2eae5c3884e2ec64}{nonstandards}}[i + 1])] = 7;}
106\DoxyCodeLine{00102     \}}
107\DoxyCodeLine{00103 }
108\DoxyCodeLine{00104     \textcolor{keywordflow}{for} (i = 0; i < NBASES; i++)}
109\DoxyCodeLine{00105       \textcolor{keywordflow}{for} (j = 0; j < NBASES; j++)}
110\DoxyCodeLine{00106         rtype[pair[i][j]] = pair[j][i];}
111\DoxyCodeLine{00107   \} \textcolor{keywordflow}{else} \{}
112\DoxyCodeLine{00108     \textcolor{keywordflow}{for} (i = 0; i <= \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; i++)}
113\DoxyCodeLine{00109       \textcolor{keywordflow}{for} (j = 0; j <= \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; j++)}
114\DoxyCodeLine{00110         pair[i][j] = 0;}
115\DoxyCodeLine{00111     \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_gafb1ef1166da85092ae8a325e02dcae71}{energy\_set}} == 1) \{}
116\DoxyCodeLine{00112       \textcolor{keywordflow}{for} (i = 1; i < \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; ) \{}
117\DoxyCodeLine{00113         alias[i++]  = 3;      \textcolor{comment}{/* A <-\/> G */}}
118\DoxyCodeLine{00114         alias[i++]  = 2;      \textcolor{comment}{/* B <-\/> C */}}
119\DoxyCodeLine{00115       \}}
120\DoxyCodeLine{00116       \textcolor{keywordflow}{for} (i = 1; i < \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; i++) \{}
121\DoxyCodeLine{00117         pair[i][i + 1] = 2;       \textcolor{comment}{/* AB <-\/> GC */}}
122\DoxyCodeLine{00118         i++;}
123\DoxyCodeLine{00119         pair[i][i -\/ 1] = 1;       \textcolor{comment}{/* BA <-\/> CG */}}
124\DoxyCodeLine{00120       \}}
125\DoxyCodeLine{00121     \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_gafb1ef1166da85092ae8a325e02dcae71}{energy\_set}} == 2) \{}
126\DoxyCodeLine{00122       \textcolor{keywordflow}{for} (i = 1; i < \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; ) \{}
127\DoxyCodeLine{00123         alias[i++]  = 1;      \textcolor{comment}{/* A <-\/> A*/}}
128\DoxyCodeLine{00124         alias[i++]  = 4;      \textcolor{comment}{/* B <-\/> U */}}
129\DoxyCodeLine{00125       \}}
130\DoxyCodeLine{00126       \textcolor{keywordflow}{for} (i = 1; i < \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; i++) \{}
131\DoxyCodeLine{00127         pair[i][i + 1] = 5;       \textcolor{comment}{/* AB <-\/> AU */}}
132\DoxyCodeLine{00128         i++;}
133\DoxyCodeLine{00129         pair[i][i -\/ 1] = 6;       \textcolor{comment}{/* BA <-\/> UA */}}
134\DoxyCodeLine{00130       \}}
135\DoxyCodeLine{00131     \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__model__details_gafb1ef1166da85092ae8a325e02dcae71}{energy\_set}} == 3) \{}
136\DoxyCodeLine{00132       \textcolor{keywordflow}{for} (i = 1; i < \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}} -\/ 2; ) \{}
137\DoxyCodeLine{00133         alias[i++]  = 3;    \textcolor{comment}{/* A <-\/> G */}}
138\DoxyCodeLine{00134         alias[i++]  = 2;    \textcolor{comment}{/* B <-\/> C */}}
139\DoxyCodeLine{00135         alias[i++]  = 1;    \textcolor{comment}{/* C <-\/> A */}}
140\DoxyCodeLine{00136         alias[i++]  = 4;    \textcolor{comment}{/* D <-\/> U */}}
141\DoxyCodeLine{00137       \}}
142\DoxyCodeLine{00138       \textcolor{keywordflow}{for} (i = 1; i < \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}} -\/ 2; i++) \{}
143\DoxyCodeLine{00139         pair[i][i + 1] = 2;     \textcolor{comment}{/* AB <-\/> GC */}}
144\DoxyCodeLine{00140         i++;}
145\DoxyCodeLine{00141         pair[i][i -\/ 1] = 1;     \textcolor{comment}{/* BA <-\/> CG */}}
146\DoxyCodeLine{00142         i++;}
147\DoxyCodeLine{00143         pair[i][i + 1] = 5;     \textcolor{comment}{/* CD <-\/> AU */}}
148\DoxyCodeLine{00144         i++;}
149\DoxyCodeLine{00145         pair[i][i -\/ 1] = 6;     \textcolor{comment}{/* DC <-\/> UA */}}
150\DoxyCodeLine{00146       \}}
151\DoxyCodeLine{00147     \} \textcolor{keywordflow}{else} \{}
152\DoxyCodeLine{00148       \mbox{\hyperlink{group__message__utils_ga36b35be01d7f36cf7f59c245eee628d1}{vrna\_message\_error}}(\textcolor{stringliteral}{"{}What energy\_set are YOU using??"{}});}
153\DoxyCodeLine{00149     \}}
154\DoxyCodeLine{00150 }
155\DoxyCodeLine{00151     \textcolor{keywordflow}{for} (i = 0; i <= \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; i++)}
156\DoxyCodeLine{00152       \textcolor{keywordflow}{for} (j = 0; j <= \mbox{\hyperlink{group__model__details_ga05a5ffe718aa431d97419a12fb082379}{MAXALPHA}}; j++)}
157\DoxyCodeLine{00153         rtype[pair[i][j]] = pair[j][i];}
158\DoxyCodeLine{00154   \}}
159\DoxyCodeLine{00155 \}}
160\DoxyCodeLine{00156 }
161\DoxyCodeLine{00157 }
162\DoxyCodeLine{00158 \textcolor{keyword}{static} INLINE \textcolor{keywordtype}{short} *}
163\DoxyCodeLine{00159 encode\_sequence(\textcolor{keyword}{const} \textcolor{keywordtype}{char}  *sequence,}
164\DoxyCodeLine{00160                 \textcolor{keywordtype}{short}       how)}
165\DoxyCodeLine{00161 \{}
166\DoxyCodeLine{00162   \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int}  i, l = (\textcolor{keywordtype}{unsigned} int)strlen(sequence);}
167\DoxyCodeLine{00163   \textcolor{keywordtype}{short}         *S = (\textcolor{keywordtype}{short} *)\mbox{\hyperlink{group__utils_gaf37a0979367c977edfb9da6614eebe99}{vrna\_alloc}}(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{short}) * (l + 2));}
168\DoxyCodeLine{00164 }
169\DoxyCodeLine{00165   \textcolor{keywordflow}{switch} (how) \{}
170\DoxyCodeLine{00166     \textcolor{comment}{/* standard encoding as always used for S */}}
171\DoxyCodeLine{00167     \textcolor{keywordflow}{case} 0:}
172\DoxyCodeLine{00168       \textcolor{keywordflow}{for} (i = 1; i <= l; i++)    \textcolor{comment}{/* make numerical encoding of sequence */}}
173\DoxyCodeLine{00169         S[i] = (\textcolor{keywordtype}{short})encode\_char(sequence[i -\/ 1]);}
174\DoxyCodeLine{00170       S[l + 1]  = S[1];}
175\DoxyCodeLine{00171       S[0]      = (short)l;}
176\DoxyCodeLine{00172       \textcolor{keywordflow}{break};}
177\DoxyCodeLine{00173     \textcolor{comment}{/* encoding for mismatches of nostandard bases (normally used for S1) */}}
178\DoxyCodeLine{00174     \textcolor{keywordflow}{case} 1:}
179\DoxyCodeLine{00175       \textcolor{keywordflow}{for} (i = 1; i <= l; i++)}
180\DoxyCodeLine{00176         S[i] = alias[(\textcolor{keywordtype}{short})encode\_char(sequence[i -\/ 1])];}
181\DoxyCodeLine{00177       S[l + 1]  = S[1];}
182\DoxyCodeLine{00178       S[0]      = S[l];}
183\DoxyCodeLine{00179       \textcolor{keywordflow}{break};}
184\DoxyCodeLine{00180   \}}
185\DoxyCodeLine{00181 }
186\DoxyCodeLine{00182   \textcolor{keywordflow}{return} S;}
187\DoxyCodeLine{00183 \}}
188\DoxyCodeLine{00184 }
189\DoxyCodeLine{00185 }
190\DoxyCodeLine{00186 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* VIENNA\_RNA\_PACKAGE\_PAIR\_MAT\_H */}\textcolor{preprocessor}{}}
191
192\end{DoxyCode}
193