Delta Library

[Data Structures]   [Lattice]   [Pull Move]   [RNA-specific]   [Input/Output]

A library that includes basic data structures and functions for the 3D triangular lattice, pull moves, file input/output, and RNA-specific information such as stacking pair energies.

Data Structures

extern char *bases;
extern char *turns;

The array bases stores the sequence of RNA bases. The array turns stores the sequence of turn directions of consecutive bases, which encodes the lattice conformation; the 12 directions ±x, ±y, ±z, ±u, ±v, ±w are represented by 'X', 'x', 'Y', 'y', 'Z', 'z', 'U', 'u', 'V', 'v', 'W', 'w'. The length of the turn sequence is exactly one less the length of the base sequence.

typedef struct point {
	struct point *next;
	int x, y, z;
} s_point;

extern s_point *points;
extern int n_points;

The structure s_point has three fields x, y, z for the coordinates of a lattice point, and has a pointer next for linking the lattice points of all bases into a hashtable for efficient collision detection and neighborhood exploration. The array points stores the lattice points corresponding to the bases in the array bases. The integer n_points stores the sequence length. Hence the sizes of the three arrays points, bases, and turns are n_points, n_points, and n_points - 1, respectively.

extern int *pairs;
extern int n_pairs;

The two-dimensional array pairs stores the input base pairs (for reconstruction or visualization) as an adjacency matrix. The integer n_pairs is the number of such pairs.

Lattice

void lattice2();

The function lattice2 configures the Delta library to work on the 2D triangular lattice instead of the default 3D triangular lattice.

#define C_w 'w'
#define C_v 'v'
#define C_u 'u'
#define C_z 'z'
#define C_y 'y'
#define C_x 'x'
#define C_0 '0'
#define C_X 'X'
#define C_Y 'Y'
#define C_Z 'Z'
#define C_U 'U'
#define C_V 'V'
#define C_W 'W'

#define I_w -6
#define I_v -5
#define I_u -4
#define I_z -3
#define I_y -2
#define I_x -1
#define I_0  0
#define I_X  1
#define I_Y  2
#define I_Z  3
#define I_U  4
#define I_V  5
#define I_W  6

The macros C_? and I_? specify the character name and integer index, respectively, of the 12 lattice directions in the 3D triangular lattice and a dummy direction 0.

char axis_i2c(int i);
int axis_c2i(char c);

The function axis_i2c converts the integer index of an axis to its character name. The function axis_c2i performs the reverse conversion, form the character name to the integer index.

extern const s_point *vectors;

The array vectors is indexed by I_?, and stores the (x, y, z) components of the 12 lattice directions and the dummy direction.

int axis_pq(const s_point *p, const s_point *q);

This function axis_pq finds the vector from p and q, and returns the corresponding integer index I_? (the dummy index I_0 is returned if the vector is not one of the 12 axis vectors).

int adjacent_pq(const s_point *p, const s_point *q);
int adjacent_ij(int i, int j);

The boolean function adjacent_pq checks whether two lattice points p and q are adjacent. The boolean function adjacent_ij checks whether points[i] and points[j] are adjacent. The function adjacent_ij calls the function adjacent_pq internally.

int neighbor_pd(const s_point *p, int d);
int neighbor_id(int i, int d);

The function neighbor_pd returns an index j such that points[j] is the neighbor of p in the direction d, where d is one of the indices I_?. The value -1 is returned if no such index exists. Similarly, the function neighbor_id returns an index j such that points[j] is the neighbor of points[i] in the direction d. The function neighbor_id calls the function neighbor_pd internally.

void walk(const s_point *p, int d, s_point *q);

The function walk sets q to the lattice point obtained by walking from p in the direction d.

void turns_to_points();
void points_to_turns();

The function turns_to_points decodes the lattice conformation of the sequence from the array turns (lattice directions) to the array points (lattice points organized into a hashtable). The function points_to_turns encodes points to turns.

Pull Move

typedef struct {
	int i;	/* index */
	int d;	/* direction */
	int i_;	/* index for undo */
	int d_;	/* direction for undo */
} s_move;

The structure s_move has two fields i, d for the base index and the lattice direction of a pull move, and two fields i_, d_ for the corresponding undo move.

int test(s_move *move);
void pull(const s_move *move);
void undo(const s_move *move);

The boolean function test checks whether the two fields i, d in move specify a valid pull move. As a side effect, the function test also writes the two fields i_, d_ in move for the corresponding undo move. The function pull executes move by i, d. The function undo executes move by i_, d_.

Always test before pull to validate move. Only undo immediately after pull, use the same move.

RNA-specific

int valid_ij(int i, int j);

The boolean function valid_ij checks whether the two indices i and j are valid, that is, are within the range of 0 and n_points - 1 and differ by more than 3 (the hairpin constraint).

extern double energies[][6];

#define _AU_	0
#define _CG_	1
#define _GC_	2
#define _UA_	3
#define _GU_	4
#define _UG_	5

The two-dimensional array energies stores the free energies of stacking pairs formed by Watson-Crick and wobble base pairs with indices _AU_, _CG_, _GC_, _UA_, _GU_, and _UG_. For example, if the two base pairs AU and UG form a stacking pair, then the energy is energies[_AU_][_UG_].

int pair_ab(char a, char b);
int pair_ij(int i, int j);

The function pair_ab returns the index (_AU_, _CG_, _GC_, _UA_, _GU_, or _UG_) of the base pair formed by the two bases a and b. For example, pair_ab('A', 'U') returns _AU_. The function pair_ij returns the index of the base pair formed by the two bases bases[i] and bases[j].

int watson_crick(int index);
int wobble(int index);

The boolean function watson_crick checks whether index is one of _AU_, _CG_, _GC_, and _UA_. The boolean function wobble checks whether index is either _GU_ or _UG_.

int valid_adjacent_pair(int i, int j);

The boolean function valid_adjacent_pair checks whether i and j are valid indices, bases[i] and bases[j] form a Watson-Crick or wobble base pair, and points[i] and points[j] are adjacent lattice points.

Input/Output

void input_bases_turns(const char *filename);
void output_bases_turns(const char *filename);
void input_pairs(char *filename);
void output_pairs(char *filename);

The function input_bases_turns reads the input file in seq or seq2 format, and populates the two arrays bases and turns. If the input file is in seq format (which does not include the turn sequence), then the array turns is initialized to a stem-loop. The function output_bases_turns writes bases and turns to the output file in seq2 format.

The function input_pairs reads the input file in bp format, and populates the adjacency matrix pairs. The function output_pairs extracts the base pairs from stacking base pairs of the lattice conformation, and writes them to the output file in bp format.

_