3 # Last changed Time-stamp: <2006-04-04 14:51:06 ivo>
5 # Perl implementation of RNAfold
6 # This is an example script demonstrating how to use the RNA Perl module
13 Getopt::Long::config("no_ignore_case");
15 use vars qw/$opt_debug $opt_v $ParamFile $pf $ns_bases/;
17 &usage() unless GetOptions("p|p1" => \$pf,
18 "p0" => sub {$pf=1; $RNA::do_backtrack=0},
19 "C" => \$RNA::fold_constrained,
20 "T=f" => \$RNA::temperature,
21 "4" => sub {$RNA::tetra_loop = 0},
22 "d|d0" => sub {$RNA::dangles=0},
23 "d2" => sub {$RNA::dangles=2},,
24 "noGU" => \$RNA::noGU,
25 "noCloseGU" => \$RNA::no_closingGU,
26 "noLP" => \$RNA::noLonelyPairs,
27 "e=i" => \$RNA::energy_set,
29 "nsp=s" => \$ns_bases,
32 RNA::read_parameter_file($ParamFile) if ($ParamFile);
35 $RNA::nonstandards = "";
36 foreach my $p ( split(/,/, $ns_bases) ) {
38 $RNA::nonstandards .= reverse($p)
40 $RNA::nonstandards .= $p;
42 print "$RNA::nonstandards\n";
45 my $istty = (-t STDIN) && (-t STDOUT);
46 if (($RNA::fold_constrained)&&($istty)) {
48 Input constraints using the following notation:
49 | : paired with another base
50 . : no constraint at all
51 x : base must not pair
52 < : base i is paired with a base j<i
53 > : base i is paired with a base j>i
54 matching brackets ( ): base i pairs base j
59 print "\nInput string (upper or lower case); @ to quit\n";
60 for (1..8) { print "....,....$_";}
64 while (<>) { # main loop: continue until end of file
65 my ($string, $cstruc, $structure, $min_en);
66 # skip comment lines and get filenames
79 $string = uc($string);
80 my $length = length($string);
81 printf("length = %d\n", $length) if ($istty);
83 if ($RNA::fold_constrained) {
85 $cstruc = $1 if (/(\S+)/);
86 die("constraint string has wrong length")
87 if (length($cstruc)!=$length);
88 ($structure, $min_en) = RNA::fold($string, $structure);
90 ($structure, $min_en) = RNA::fold($string);
92 print "$string\n$structure";
94 printf("\n minimum free energy = %6.2f kcal/mol\n", $min_en);
96 printf(" (%6.2f)\n", $min_en);
98 my $ffname = ($fname) ? ($fname . '_ss.ps') : 'rna.ps';
99 RNA::PS_rna_plot($string, $structure, $ffname);
103 # recompute with dangles as in pf_fold()
104 $RNA::dangles=2 if ($RNA::dangles);
105 $min_en = RNA::energy_of_struct($string, $structure);
107 my $kT = ($RNA::temperature+273.15)*1.98717/1000.; # in Kcal
108 $RNA::pf_scale = exp(-($sfact*$min_en)/$kT/$length);
109 print STDERR "scaling factor $RNA::pf_scale\n" if ($length>2000);
111 $structure = $cstruc if ($RNA::fold_constrained);
112 my $energy = RNA::pf_fold($string, $structure);
114 if ($RNA::do_backtrack) {
116 printf(" [%6.2f]\n", $energy) if (!$istty);
119 if (($istty)||(!$RNA::do_backtrack)) {
120 printf(" free energy of ensemble = %6.2f kcal/mol\n", $energy);
121 printf(" frequency of mfe structure in ensemble %g\n",
122 exp(($energy-$min_en)/$kT));
125 if ($RNA::do_backtrack) {
126 $ffname = ($fname)?($fname . "_dp.ps"):"dot.ps";
127 &RNA::PS_dot_plot($string, $ffname);
133 RNA::free_pf_arrays() if ($pf);
139 "RNAfold [-p[0]] [-C] [-T temp] [-4] [-d] [-noGU] [-noCloseGU]\n" .
140 " [-e e_set] [-P paramfile] [-nsp pairs] [-S scale]");