Gri - a programming language for drawing science-style graphs

A more complex example of producing 2D projections from 3D data will be highlighted in this section. Here, we use a program similar to gnuplot, named gri. It also provides you with an interactive terminal where you can type in several commands for data source selection, data post-processing and alteration of the resulting plot.

You can download the gri-reference- and the gri-command-reference-card under
http://gri.sourceforge.net/refcard.pdf and
http://gri.sourceforge.net/cmdrefcard.pdf

As you see in the reference cards, it is a very powerful language for drawing science-style graphs. We will rely on a small example that should just show you what may be possible if you have 3D data and want to produce nice graphs to include in your diploma- or Phd-thesis.

Usually gri does not run interactively as it produces a postscript image of the resulting graph that can not be viewed in the intermediate steps. Therefore, all commands you may want to pass to gri can be written into a textfile commands.gri that has the following structure:

command 1
command 2
command 3

...

command n

quit

Gri will execute all the commands listed in your commandfile commands.gri when you invoke it in the following way:

$ gri commands.gri yourdata.dat

You will be provided with an example command file and some example data. Download it here:
http://www.tbi.univie.ac.at/~ronny/Leere/sb1/commands.gri
http://www.tbi.univie.ac.at/~ronny/Leere/sb1/sv11.2D.out
http://www.tbi.univie.ac.at/~ronny/Leere/sb1/switch.2D.out

E.g. using wget:

$ wget http://www.tbi.univie.ac.at/~ronny/Leere/sb1/commands.gri
$ wget http://www.tbi.univie.ac.at/~ronny/Leere/sb1/sv11.2D.out
$ wget http://www.tbi.univie.ac.at/~ronny/Leere/sb1/switch.2D.out

First have a look inside the first data file.

$ less sv11.2D.out

It is filled with a lot of information, not entirely given as tabulated columns. In short, this data represents the output of a bioinformatics tool that computes the free energy of a given RNA molecule. RNA can can form stable secondary structures by base pairing and base stacking. A widely used nearest neighbor model with tons of parameters is then used to compute the free energy of a given secondary structure of a particular RNA. Furthermore, there exist algorithms that compute the minimum of free energy and the according secondary structure. RNA does not reside in a fixed configuration but may change its secondary structure. Thus, another algorithm computes the partition function of all secondary structure conformations compatible with the RNA sequence. Given the partition function one can calculate the Gibbs free energy of the ensemble of secondary structures. If a neighborhood relation is introduced that tells which secondary structure is a neighbor of another, e.g. if you delete/introduce a base pair, you get a so called energy landscape. This requires that each secondary structure state is associated with a certain free energy value. This energy landscape is a high dimensional raum (the number of dimensions relies on the number of neighbors a secondary structure may have) that can not be easily depicted. However, given one or two reference structures, one is able to project the entire high dimensional space onto a 2- or 3-dimensional plane. In our example this is done by partitioning all secondary structure states into so called distance classes originated by two given reference structures. This means that for each possible secondary structure state, the distance to the two reference structures according to the underlying neighborhood relation is computed which results in a ($ x$,$ y$) pair where $ x$ is the distance to the first and $ y$ the distance to the second reference structure. This partitioning can than be used to compute the representative with a minimum of free energy and/or the partition function/Gibbs free energy of the partitions. However, this is the data inside the example given.

In the first line of sv11.2D.out is the sequence of the RNA molecule. The second line denotes a secondary structure with minimum of free energy in dot-bracket notation, followd by the fre energy in $ \mathrm{kcal}/\mathrm{mol}$. The third and fourth line show the two reference structures with their appropriate free energy. In the next line you see the Gibbs free energy of the ensemble of all secondary structures compatible with the sequence given. Then a headerline of the following tabulated data is given that tells you which data is given in which column. The first column (k) is the distance to the first reference, the second (l) the distance to the second reference. Then there is a set of probabilities followed by the minimum free energy, the gibbs free energy and the minimum free energy structure of the partition.

We will use this data to draw a 2D projection of the following 3D data: (distance1, distance2, MFE)
Therefore consult the given command file commands.gri. Do not get confused with all the statements written there! Before each statement there is a line that starts with //. This is recognized as a comment and does not influence the plot produced by gri. It just helps you to know what is done in the next step.

To understand what is going on when gri is executing all the commands given in commands.gri, execute the command file using the provided data first.

$ gri commands.gri sv11.2D.out

The command file you got has a very special line on top:

#!/usr/bin/gri

This makes it possible to execute the textfile itself in the terminal, without writing the command gri in front. To do so, you first have to make the textfile executable using the command chmod:

$ chmod +x commands.gri

Now you are able to produce the postscript plot using the command file alone:

$ ./commands.gri sv11.2D.out

If you get an error message in your terminal that contains a line like:

bad interpreter: No such file or directory
you have to find out the exact path where the gri preogram is located in your directory tree. This can be done typing
$ which gri
or
$ whereis gri

You should now get a path like /usr/bin/gri or something similar if gri is installed in your system. Copy this path and replace the part after #! in the first line of your commands.gri with it. This line, by the way, tells the terminal which program it should use when executing a text file.

After everything went fine, check the content of you current working directory with the ls command

$ ls
You should now see a file named sv11.2D.out.ps that contains the plot produced by gri. This file can be viewed by any program that can read the postscript format, e.g. gv, evince, etc..
$ evince sv11.2D.out.ps

You can also convert the postscript image to a PDF using the ps2pdf command:

$ ps2pdf sv11.2D.out.ps
This produces a file named sv11.2D.out.pdf that can be viewed by any PDF-viewer.

After looking at hte produced plot, go through commands.gri to find out which commandss were necessary to produce the plot.

You can easily comment out some commands in the command file by putting a // in front of it...

Ronny Lorenz 2010-04-06