Add missing binaty and statis library
[jabaws.git] / binaries / src / ViennaRNA / Utils / colorrna.pl
1 #!/usr/bin/perl -w
2 # -*-CPerl-*-
3 # Last changed Time-stamp: <2005-11-07 12:08:38 ivo>
4 # $Id: colorrna.pl,v 1.1 2005/11/07 12:42:27 ivo Exp $
5 # colorize a secondary structure plot with reliability annotation
6 # from positional entropy
7 use strict;
8 use Getopt::Std;
9 $main::VERSION = 1.0;
10 $Getopt::Std::STANDARD_HELP_VERSION=1;
11
12 our $opt_p;
13 getopts('p');
14
15 sub HELP_MESSAGE {
16   print STDERR "\nusage: $0 FOO_ss.ps FOO_dp.ps > FOO_css.ps\n";
17   print STDERR "For more details run\n\tperldoc -F $0\n";
18 }
19
20 HELP_MESSAGE() unless $#ARGV >0;
21 my $macro_seen= 0;
22 my %mfe = ();        # hash of mfe pairs
23 my @ss_ps = ('',''); # head and tail of the ss.ps file
24
25 my $n = swallow_ss_ps();    # read ss plot
26 my %hsb = read_dp();   # read dot plot and compute entropies
27
28 print $ss_ps[0];     # print head
29 if (!$macro_seen) {
30   print <<_E_O_F_
31 /hsb {
32     dup 0.3 mul 1 exch sub sethsbcolor
33 } bind def
34 /colorpair { % i j hue sat colorpair
35    % draw basepair i,j in color
36    % 1 index 0.00 ne {
37    gsave
38    newpath
39    hsb
40    fsize setlinewidth
41    1 sub coor exch get aload pop moveto
42    1 sub coor exch get aload pop lineto
43    stroke
44    grestore
45    % } if
46 } bind def
47 _E_O_F_
48 }
49 foreach my $k (keys %hsb) {
50   my ($i,$j) = split($;,$k);
51   print "$i $j ", $hsb{$k}->[0], " ", $hsb{$k}->[1]," colorpair\n";
52 }
53 print $ss_ps[1];  # print main part
54 print $ss_ps[2];  # print showpage etc
55
56 sub swallow_ss_ps {
57   # read the secondary structure plot
58   my $length=0;
59   my $tail=0;
60   while (<>) {
61     $macro_seen=1 if /colorpair/;
62     $length ++ if /^\/coor/ .. /^\] def/;
63     if (/^\/pairs/ .. /^\] def/) {
64       $mfe{$1,$2}=1 if /(\d+)\s+(\d+)/;
65     }
66     next if /\d gmark$/;
67     $tail++ if /^drawpairs/;
68     s/^drawpairs/% drawpairs/;
69     $tail++ if /^showpage/;
70     $ss_ps[$tail] .= $_;
71     last if eof;
72   }
73   return $length-2;
74 }
75
76 sub read_dp {
77   # read dot plot and extract hsb values
78   my %hsb;
79   while (<>) {
80     next unless /lbox$/;
81     my @F = split;
82     $hsb{$F[3],$F[4]} = [$F[0], $F[1]];
83   }
84   return %hsb;
85 }
86
87 =head1 NAME
88
89 colorrna - colorize an alirna.ps file
90
91 =head1 SYNOPSIS
92
93    colorrna.pl alirna.ps alidot.ps > colorRNA.ps
94
95 =head1 DESCRIPTION
96
97 colorrna reads an RNA secondary structure plot and a dot plot
98 containing pair probabilities and covariance annotation as, produced
99 by C<RNAalifold -p>, and writes a new secondary structure plot with
100 color annotated seqence annotation to stdout.  The color annotation
101 is taken directly from the color dot plot file.
102
103 =head1 AUTHOR
104
105 Ivo L. Hofacker <ivo@tbi.univie.ac.at>
106 Stefan Washietl <wash@tbi.univie.ac.at>
107
108 =cut
109
110 #  End of file
111