3 # Last changed Time-stamp: <2004-08-09 16:50:14 ivo>
4 # $Id: rotate_ss.pl,v 1.4 2006/02/28 14:44:14 ivo Exp $
8 use vars qw/$ss_ps $opt_a $opt_m/;
9 use constant PI => 3.14159265;
11 my $ss_ps = { Header => [],
16 usage() unless GetOptions("a=f" => \$opt_a, "m");
19 my $ar = to_Array($ss_ps->{Coords});
20 my $mp = get_Midpt($ar);
21 $ar = flip_Array($mp, $ar) if $opt_m;
22 $ar = rot_Array($mp, $ar) if $opt_a;
27 printf STDERR "\nusage: $0 [-a ANGLE] [-m] FOO_ss.ps > BAR_ss.ps\n";
37 $toggle = 1 if m/^\/coor/;
38 push @{$ss_ps->{Header}}, $_ if $toggle == 0;
39 push @{$ss_ps->{Coords}}, $_ if $toggle == 1;
40 push @{$ss_ps->{BPairs}}, $_ if $toggle == 2;
41 push @{$ss_ps->{Tailer}}, $_ if $toggle > 2;
42 $toggle++ if m/\]\s+def/;
49 return [ map {chomp; s/\[//; s/\]//; [split] } @$aref[$[+1 .. $#$aref-1] ];
56 my ($xl, $yl, $xu, $yu) = ( 100000, 100000, -100000, -100000 );
58 $xl = ($_->[0] < $xl) ? $_->[0] : $xl;
59 $yl = ($_->[1] < $yl) ? $_->[1] : $yl;
60 $xu = ($_->[0] > $xu) ? $_->[0] : $xu;
61 $yu = ($_->[1] > $yu) ? $_->[1] : $yu;
63 return [($xl+$xu)/2, ($yl+$yu)/2, $xl, $yl, $xu, $yu];
69 my $a = $opt_a/360*2*PI;
70 my ($ca, $sa) = (cos($a), sin($a));
73 map { [ ($ca*($_->[0]-$mp->[0]) + (-$sa*($_->[1]-$mp->[1])))+$mp->[0],
74 ($sa*($_->[0]-$mp->[0]) + $ca*($_->[1]-$mp->[1])) +$mp->[1]
81 [ map { [ ($mp->[0]-$_->[0]), $_->[1]] } @$ar ];
88 for (qw/Header Coords BPairs Tailer/) {
92 print sprintf("[%7.3f %7.3f]\n", $xy->[0], $xy->[1]);
97 print join "", @{$ss_ps->{$_}};
103 rotate_ss - rotate or mirror coordinates of secondary structure plot
107 rotate_ss.pl [-a angle] [-m] old_ss.ps > new_ss.ps
111 B<rotate_ss> reads a PostScript RNA secondary structure plot, as
112 produced by B<RNAfold> or B<RNAplot>, rotates and/or mirrors the
113 coordinates, and writes the new plot to STDOUT.
121 Rotate the plot counter-clockwise by I<angle> degrees.
125 Mirror the coordinates in the plot, i.e. convert from a
126 couter-clockwise to clockwise layout. Note that, if both B<-m> and
127 B<-a> are given, the plot is first mirrored, then rotated.
133 Ivo L. Hofacker <ivo@tbi.univie.ac.at>,
134 Christoph Flamm <xtof@tbi.univie.ac.at>