JWS-117 Compiled all tools with ./compilebin.sh and some were missing related files.
[jabaws.git] / binaries / src / ViennaRNA / doc / latex / mp_parse.tex
1 \subsection*{Representations of Secondary Structures}
2
3 The standard representation of a secondary structure is the {\itshape bracket notation\/}, where matching brackets symbolize base pairs and unpaired bases are shown as dots. Alternatively, one may use two types of node labels, 'P' for paired and 'U' for unpaired; a dot is then replaced by '(U)', and each closed bracket is assigned an additional identifier 'P'. We call this the expanded notation. In  fontana:1993b a condensed representation of the secondary structure is proposed, the so-\/called homeomorphically irreducible tree (HIT) representation. Here a stack is represented as a single pair of matching brackets labeled 'P' and weighted by the number of base pairs. Correspondingly, a contiguous strain of unpaired bases is shown as one pair of matching brackets labeled 'U' and weighted by its length. Generally any string consisting of matching brackets and identifiers is equivalent to a plane tree with as many different types of nodes as there are identifiers.
4
5 Bruce Shapiro proposed a coarse grained representation  shapiro:1988, which, does not retain the full information of the secondary structure. He represents the different structure elements by single matching brackets and labels them as 'H' (hairpin loop), 'I' (interior loop), 'B' (bulge), 'M' (multi-\/loop), and 'S' (stack). We extend his alphabet by an extra letter for external elements 'E'. Again these identifiers may be followed by a weight corresponding to the number of unpaired bases or base pairs in the structure element. All tree representations (except for the dot-\/bracket form) can be encapsulated into a virtual root (labeled 'R'), see the example below.
6
7 The following example illustrates the different linear tree representations used by the package. All lines show the same secondary structure.
8
9 \begin{DoxyVerb}
10 a) .((((..(((...)))..((..)))).)).
11    (U)(((((U)(U)((((U)(U)(U)P)P)P)(U)(U)(((U)(U)P)P)P)P)(U)P)P)(U)
12 b) (U)(((U2)((U3)P3)(U2)((U2)P2)P2)(U)P2)(U)
13 c) (((H)(H)M)B)
14    ((((((H)S)((H)S)M)S)B)S)
15    (((((((H)S)((H)S)M)S)B)S)E)
16 d) ((((((((H3)S3)((H2)S2)M4)S2)B1)S2)E2)R)
17 \end{DoxyVerb}
18
19
20 Above: \hyperlink{structTree}{Tree} representations of secondary structures. a) Full structure: the first line shows the more convenient condensed notation which is used by our programs; the second line shows the rather clumsy expanded notation for completeness, b) HIT structure, c) different versions of coarse grained structures: the second line is exactly Shapiro's representation, the first line is obtained by neglecting the stems. Since each loop is closed by a unique stem, these two lines are equivalent. The third line is an extension taking into account also the external digits. d) weighted coarse structure, this time including the virtual root.
21
22 For the output of aligned structures from string editing, different representations are needed, where we put the label on both sides. The above examples for tree representations would then look like:
23
24 \begin{DoxyVerb}
25 a) (UU)(P(P(P(P(UU)(UU)(P(P(P(UU)(UU)(UU)P)P)P)(UU)(UU)(P(P(UU)(U...
26 b) (UU)(P2(P2(U2U2)(P2(U3U3)P3)(U2U2)(P2(U2U2)P2)P2)(UU)P2)(UU)
27 c) (B(M(HH)(HH)M)B)
28    (S(B(S(M(S(HH)S)(S(HH)S)M)S)B)S)
29    (E(S(B(S(M(S(HH)S)(S(HH)S)M)S)B)S)E)
30 d) (R(E2(S2(B1(S2(M4(S3(H3)S3)((H2)S2)M4)S2)B1)S2)E2)R)
31 \end{DoxyVerb}
32
33
34 Aligned structures additionally contain the gap character '\_\-'.
35
36 \subsection*{Parsing and Coarse Graining of Structures}
37
38 Several functions are provided for parsing structures and converting to different representations.
39
40 \begin{DoxyVerb}
41 char  *expand_Full(const char *structure)
42 \end{DoxyVerb}
43  Convert the full structure from bracket notation to the expanded notation including root. 
44
45 \begin{DoxyVerb}
46 char *b2HIT (const char *structure)
47 \end{DoxyVerb}
48  Converts the full structure from bracket notation to the HIT notation including root. 
49
50 \begin{DoxyVerb}
51 char *b2C (const char *structure)
52 \end{DoxyVerb}
53  Converts the full structure from bracket notation to the a coarse grained notation using the 'H' 'B' 'I' 'M' and 'R' identifiers. 
54
55 \begin{DoxyVerb}
56 char *b2Shapiro (const char *structure)
57 \end{DoxyVerb}
58  Converts the full structure from bracket notation to the {\itshape weighted\/} coarse grained notation using the 'H' 'B' 'I' 'M' 'S' 'E' and 'R' identifiers. 
59
60 \begin{DoxyVerb}
61 char  *expand_Shapiro (const char *coarse);
62 \end{DoxyVerb}
63  Inserts missing 'S' identifiers in unweighted coarse grained structures as obtained from \hyperlink{RNAstruct_8h_a9c80d92391f2833549a8b6dac92233f0}{b2C()}. 
64
65 \begin{DoxyVerb}
66 char *add_root (const char *structure)
67 \end{DoxyVerb}
68  Adds a root to an un-\/rooted tree in any except bracket notation. 
69
70 \begin{DoxyVerb}
71 char  *unexpand_Full (const char *ffull)
72 \end{DoxyVerb}
73  Restores the bracket notation from an expanded full or HIT tree, that is any tree using only identifiers 'U' 'P' and 'R'. 
74
75 \begin{DoxyVerb}
76 char  *unweight (const char *wcoarse)
77 \end{DoxyVerb}
78  Strip weights from any weighted tree. 
79
80 \begin{DoxyVerb}
81 void   unexpand_aligned_F (char *align[2])
82 \end{DoxyVerb}
83  Converts two aligned structures in expanded notation. 
84
85 \begin{DoxyVerb}
86 void   parse_structure (const char *structure)
87 \end{DoxyVerb}
88  Collects a statistic of structure elements of the full structure in bracket notation. 
89
90 \begin{DoxySeeAlso}{See also}
91 \hyperlink{RNAstruct_8h}{RNAstruct.h} for prototypes and more detailed description
92 \end{DoxySeeAlso}
93 \subsection*{Distance Measures}
94
95 A simple measure of dissimilarity between secondary structures of equal length is the base pair distance, given by the number of pairs present in only one of the two structures being compared. I.e. the number of base pairs that have to be opened or closed to transform one structure into the other. It is therefore particularly useful for comparing structures on the same sequence. It is implemented by
96
97 \begin{DoxyVerb}
98 int bp_distance(const char *str1,
99                 const char *str2)
100 \end{DoxyVerb}
101  
102
103 For other cases a distance measure that allows for gaps is preferable. We can define distances between structures as edit distances between trees or their string representations. In the case of string distances this is the same as \char`\"{}sequence alignment\char`\"{}. Given a set of edit operations and edit costs, the edit distance is given by the minimum sum of the costs along an edit path converting one object into the other. Edit distances like these always define a metric. The edit operations used by us are insertion, deletion and replacement of nodes. String editing does not pay attention to the matching of brackets, while in tree editing matching brackets represent a single node of the tree. \hyperlink{structTree}{Tree} editing is therefore usually preferable, although somewhat slower. String edit distances are always smaller or equal to tree edit distances.
104
105 The different level of detail in the structure representations defined above naturally leads to different measures of distance. For full structures we use a cost of 1 for deletion or insertion of an unpaired base and 2 for a base pair. Replacing an unpaired base for a pair incurs a cost of 1.
106
107 Two cost matrices are provided for coarse grained structures:
108
109 \begin{DoxyVerb}
110 /*  Null,   H,   B,   I,   M,   S,   E    */
111    {   0,   2,   2,   2,   2,   1,   1},   /* Null replaced */
112    {   2,   0,   2,   2,   2, INF, INF},   /* H    replaced */
113    {   2,   2,   0,   1,   2, INF, INF},   /* B    replaced */
114    {   2,   2,   1,   0,   2, INF, INF},   /* I    replaced */
115    {   2,   2,   2,   2,   0, INF, INF},   /* M    replaced */
116    {   1, INF, INF, INF, INF,   0, INF},   /* S    replaced */
117    {   1, INF, INF, INF, INF, INF,   0},   /* E    replaced */
118
119
120 /* Null,   H,   B,   I,   M,   S,   E   */
121    {   0, 100,   5,   5,  75,   5,   5},   /* Null replaced */
122    { 100,   0,   8,   8,   8, INF, INF},   /* H    replaced */
123    {   5,   8,   0,   3,   8, INF, INF},   /* B    replaced */
124    {   5,   8,   3,   0,   8, INF, INF},   /* I    replaced */
125    {  75,   8,   8,   8,   0, INF, INF},   /* M    replaced */
126    {   5, INF, INF, INF, INF,   0, INF},   /* S    replaced */
127    {   5, INF, INF, INF, INF, INF,   0},   /* E    replaced */
128 \end{DoxyVerb}
129
130
131 The lower matrix uses the costs given in  shapiro:1990. All distance functions use the following global variables:
132
133 \begin{DoxyVerb}
134 int  cost_matrix;
135 \end{DoxyVerb}
136  Specify the cost matrix to be used for distance calculations. 
137
138 \begin{DoxyVerb}
139 int   edit_backtrack;
140 \end{DoxyVerb}
141  Produce an alignment of the two structures being compared by tracing the editing path giving the minimum distance. 
142
143 \begin{DoxyVerb}
144 char *aligned_line[4];
145 \end{DoxyVerb}
146  Contains the two aligned structures after a call to one of the distance functions with \hyperlink{dist__vars_8h_aa03194c513af6b860e7b33e370b82bdb}{edit\_\-backtrack} set to 1. 
147
148 \begin{DoxySeeAlso}{See also}
149 \hyperlink{utils_8h}{utils.h}, \hyperlink{dist__vars_8h}{dist\_\-vars.h} and \hyperlink{stringdist_8h}{stringdist.h} for more details
150 \end{DoxySeeAlso}
151 \subsubsection*{Functions for \hyperlink{structTree}{Tree} Edit Distances}
152
153 \begin{DoxyVerb}
154 Tree   *make_tree (char *struc)
155 \end{DoxyVerb}
156  Constructs a \hyperlink{structTree}{Tree} ( essentially the postorder list ) of the structure 'struc', for use in \hyperlink{treedist_8h_a3b21f1925f7071f46d93431a835217bb}{tree\_\-edit\_\-distance()}. 
157
158 \begin{DoxyVerb}
159 float   tree_edit_distance (Tree *T1,
160                             Tree *T2) 
161 \end{DoxyVerb}
162  Calculates the edit distance of the two trees. 
163
164 \begin{DoxyVerb}
165 void    free_tree(Tree *t)
166 \end{DoxyVerb}
167  Free the memory allocated for \hyperlink{structTree}{Tree} t. 
168
169 \begin{DoxySeeAlso}{See also}
170 \hyperlink{dist__vars_8h}{dist\_\-vars.h} and \hyperlink{treedist_8h}{treedist.h} for prototypes and more detailed descriptions
171 \end{DoxySeeAlso}
172 \subsubsection*{Functions for String Alignment}
173
174 \begin{DoxyVerb}
175 swString *Make_swString (char *string)
176 \end{DoxyVerb}
177  Convert a structure into a format suitable for \hyperlink{stringdist_8h_a89e3c335ef17780576d7c0e713830db9}{string\_\-edit\_\-distance()}. 
178
179 \begin{DoxyVerb}
180 float     string_edit_distance (swString *T1,
181                                 swString *T2)
182 \end{DoxyVerb}
183  Calculate the string edit distance of T1 and T2. 
184
185 \begin{DoxySeeAlso}{See also}
186 \hyperlink{dist__vars_8h}{dist\_\-vars.h} and \hyperlink{stringdist_8h}{stringdist.h} for prototypes and more detailed descriptions
187 \end{DoxySeeAlso}
188 \subsubsection*{Functions for Comparison of Base Pair Probabilities}
189
190 For comparison of base pair probability matrices, the matrices are first condensed into probability profiles which are the compared by alignment.
191
192 \begin{DoxyVerb}
193 float *Make_bp_profile_bppm ( double *bppm,
194                               int length)
195 \end{DoxyVerb}
196  condense pair probability matrix into a vector containing probabilities for unpaired, upstream paired and downstream paired. 
197
198 \begin{DoxyVerb}
199 float profile_edit_distance ( const float *T1,
200                               const float *T2)
201 \end{DoxyVerb}
202  Align the 2 probability profiles T1, T2\par
203
204
205 \begin{DoxySeeAlso}{See also}
206 ProfileDist.h for prototypes and more details of the above functions
207 \end{DoxySeeAlso}
208 \hyperlink{mp_utils}{Next Page: Utilities}