\subsection*{Representations of Secondary Structures}

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.

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.

The following example illustrates the different linear tree representations used by the package. All lines show the same secondary structure.

\begin{DoxyVerb}
a) .((((..(((...)))..((..)))).)).
   (U)(((((U)(U)((((U)(U)(U)P)P)P)(U)(U)(((U)(U)P)P)P)P)(U)P)P)(U)
b) (U)(((U2)((U3)P3)(U2)((U2)P2)P2)(U)P2)(U)
c) (((H)(H)M)B)
   ((((((H)S)((H)S)M)S)B)S)
   (((((((H)S)((H)S)M)S)B)S)E)
d) ((((((((H3)S3)((H2)S2)M4)S2)B1)S2)E2)R)
\end{DoxyVerb}


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.

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:

\begin{DoxyVerb}
a) (UU)(P(P(P(P(UU)(UU)(P(P(P(UU)(UU)(UU)P)P)P)(UU)(UU)(P(P(UU)(U...
b) (UU)(P2(P2(U2U2)(P2(U3U3)P3)(U2U2)(P2(U2U2)P2)P2)(UU)P2)(UU)
c) (B(M(HH)(HH)M)B)
   (S(B(S(M(S(HH)S)(S(HH)S)M)S)B)S)
   (E(S(B(S(M(S(HH)S)(S(HH)S)M)S)B)S)E)
d) (R(E2(S2(B1(S2(M4(S3(H3)S3)((H2)S2)M4)S2)B1)S2)E2)R)
\end{DoxyVerb}


Aligned structures additionally contain the gap character '\_\-'.

\subsection*{Parsing and Coarse Graining of Structures}

Several functions are provided for parsing structures and converting to different representations.

\begin{DoxyVerb}
char  *expand_Full(const char *structure)
\end{DoxyVerb}
 Convert the full structure from bracket notation to the expanded notation including root. 

\begin{DoxyVerb}
char *b2HIT (const char *structure)
\end{DoxyVerb}
 Converts the full structure from bracket notation to the HIT notation including root. 

\begin{DoxyVerb}
char *b2C (const char *structure)
\end{DoxyVerb}
 Converts the full structure from bracket notation to the a coarse grained notation using the 'H' 'B' 'I' 'M' and 'R' identifiers. 

\begin{DoxyVerb}
char *b2Shapiro (const char *structure)
\end{DoxyVerb}
 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. 

\begin{DoxyVerb}
char  *expand_Shapiro (const char *coarse);
\end{DoxyVerb}
 Inserts missing 'S' identifiers in unweighted coarse grained structures as obtained from \hyperlink{RNAstruct_8h_a9c80d92391f2833549a8b6dac92233f0}{b2C()}. 

\begin{DoxyVerb}
char *add_root (const char *structure)
\end{DoxyVerb}
 Adds a root to an un-\/rooted tree in any except bracket notation. 

\begin{DoxyVerb}
char  *unexpand_Full (const char *ffull)
\end{DoxyVerb}
 Restores the bracket notation from an expanded full or HIT tree, that is any tree using only identifiers 'U' 'P' and 'R'. 

\begin{DoxyVerb}
char  *unweight (const char *wcoarse)
\end{DoxyVerb}
 Strip weights from any weighted tree. 

\begin{DoxyVerb}
void   unexpand_aligned_F (char *align[2])
\end{DoxyVerb}
 Converts two aligned structures in expanded notation. 

\begin{DoxyVerb}
void   parse_structure (const char *structure)
\end{DoxyVerb}
 Collects a statistic of structure elements of the full structure in bracket notation. 

\begin{DoxySeeAlso}{See also}
\hyperlink{RNAstruct_8h}{RNAstruct.h} for prototypes and more detailed description
\end{DoxySeeAlso}
\subsection*{Distance Measures}

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

\begin{DoxyVerb}
int bp_distance(const char *str1,
                const char *str2)
\end{DoxyVerb}
 

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.

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.

Two cost matrices are provided for coarse grained structures:

\begin{DoxyVerb}
/*  Null,   H,   B,   I,   M,   S,   E    */
   {   0,   2,   2,   2,   2,   1,   1},   /* Null replaced */
   {   2,   0,   2,   2,   2, INF, INF},   /* H    replaced */
   {   2,   2,   0,   1,   2, INF, INF},   /* B    replaced */
   {   2,   2,   1,   0,   2, INF, INF},   /* I    replaced */
   {   2,   2,   2,   2,   0, INF, INF},   /* M    replaced */
   {   1, INF, INF, INF, INF,   0, INF},   /* S    replaced */
   {   1, INF, INF, INF, INF, INF,   0},   /* E    replaced */


/* Null,   H,   B,   I,   M,   S,   E   */
   {   0, 100,   5,   5,  75,   5,   5},   /* Null replaced */
   { 100,   0,   8,   8,   8, INF, INF},   /* H    replaced */
   {   5,   8,   0,   3,   8, INF, INF},   /* B    replaced */
   {   5,   8,   3,   0,   8, INF, INF},   /* I    replaced */
   {  75,   8,   8,   8,   0, INF, INF},   /* M    replaced */
   {   5, INF, INF, INF, INF,   0, INF},   /* S    replaced */
   {   5, INF, INF, INF, INF, INF,   0},   /* E    replaced */
\end{DoxyVerb}


The lower matrix uses the costs given in  shapiro:1990. All distance functions use the following global variables:

\begin{DoxyVerb}
int  cost_matrix;
\end{DoxyVerb}
 Specify the cost matrix to be used for distance calculations. 

\begin{DoxyVerb}
int   edit_backtrack;
\end{DoxyVerb}
 Produce an alignment of the two structures being compared by tracing the editing path giving the minimum distance. 

\begin{DoxyVerb}
char *aligned_line[4];
\end{DoxyVerb}
 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. 

\begin{DoxySeeAlso}{See also}
\hyperlink{utils_8h}{utils.h}, \hyperlink{dist__vars_8h}{dist\_\-vars.h} and \hyperlink{stringdist_8h}{stringdist.h} for more details
\end{DoxySeeAlso}
\subsubsection*{Functions for \hyperlink{structTree}{Tree} Edit Distances}

\begin{DoxyVerb}
Tree   *make_tree (char *struc)
\end{DoxyVerb}
 Constructs a \hyperlink{structTree}{Tree} ( essentially the postorder list ) of the structure 'struc', for use in \hyperlink{treedist_8h_a3b21f1925f7071f46d93431a835217bb}{tree\_\-edit\_\-distance()}. 

\begin{DoxyVerb}
float   tree_edit_distance (Tree *T1,
                            Tree *T2) 
\end{DoxyVerb}
 Calculates the edit distance of the two trees. 

\begin{DoxyVerb}
void    free_tree(Tree *t)
\end{DoxyVerb}
 Free the memory allocated for \hyperlink{structTree}{Tree} t. 

\begin{DoxySeeAlso}{See also}
\hyperlink{dist__vars_8h}{dist\_\-vars.h} and \hyperlink{treedist_8h}{treedist.h} for prototypes and more detailed descriptions
\end{DoxySeeAlso}
\subsubsection*{Functions for String Alignment}

\begin{DoxyVerb}
swString *Make_swString (char *string)
\end{DoxyVerb}
 Convert a structure into a format suitable for \hyperlink{stringdist_8h_a89e3c335ef17780576d7c0e713830db9}{string\_\-edit\_\-distance()}. 

\begin{DoxyVerb}
float     string_edit_distance (swString *T1,
                                swString *T2)
\end{DoxyVerb}
 Calculate the string edit distance of T1 and T2. 

\begin{DoxySeeAlso}{See also}
\hyperlink{dist__vars_8h}{dist\_\-vars.h} and \hyperlink{stringdist_8h}{stringdist.h} for prototypes and more detailed descriptions
\end{DoxySeeAlso}
\subsubsection*{Functions for Comparison of Base Pair Probabilities}

For comparison of base pair probability matrices, the matrices are first condensed into probability profiles which are the compared by alignment.

\begin{DoxyVerb}
float *Make_bp_profile_bppm ( double *bppm,
                              int length)
\end{DoxyVerb}
 condense pair probability matrix into a vector containing probabilities for unpaired, upstream paired and downstream paired. 

\begin{DoxyVerb}
float profile_edit_distance ( const float *T1,
                              const float *T2)
\end{DoxyVerb}
 Align the 2 probability profiles T1, T2\par
. 

\begin{DoxySeeAlso}{See also}
ProfileDist.h for prototypes and more details of the above functions
\end{DoxySeeAlso}
\hyperlink{mp_utils}{Next Page: Utilities} 