Mercurial > repos > mmaiensc > ember
comparison GALAXY_FILES/tools/EMBER/Make_Logo_Galaxy.pl @ 0:003f802d4c7d
Uploaded
author | mmaiensc |
---|---|
date | Wed, 29 Feb 2012 15:03:33 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:003f802d4c7d |
---|---|
1 #!/usr/bin/perl | |
2 # make a logo-ish gnu-plottable representation of a score matrix | |
3 | |
4 use Getopt::Long; | |
5 | |
6 # | |
7 # command line arguments | |
8 # | |
9 $options = "Usage: ./Make_Logo.pl <OPTIONS> | |
10 -m .model file from EMBER (required) | |
11 -c comparison list (used to make labels for the x-axis) | |
12 -o output (required) | |
13 -a include comparisons not used by EMBER (preceded by # in the .model file: y or n, default n) | |
14 -f image file format (default 1) | |
15 1 - eps | |
16 2 - cgm | |
17 -k key on/off (y or n, default y) | |
18 -lx x labels on/off (y or n, default y) | |
19 -ly y labels on/off (y or n, default y) | |
20 -yr set yrange manually (enter <min>,<max>, e.g. -1.5,3.5; default chosen automatically) | |
21 \n"; | |
22 | |
23 $m = ""; | |
24 $c = ""; | |
25 $o = ""; | |
26 $a = "n"; | |
27 $f = 1; | |
28 $k = "y"; | |
29 $lx= "y"; | |
30 $ly= "y"; | |
31 $yr= "zzzzzzzzzzz"; | |
32 | |
33 GetOptions('m=s' => \$m, | |
34 'c=s' => \$c, | |
35 'o=s' => \$o, | |
36 'a=s' => \$a, | |
37 'f=i' => \$f, | |
38 'k=s' => \$k, | |
39 'lx=s'=> \$lx, | |
40 'ly=s'=> \$ly, | |
41 'yr=s'=> \$yr | |
42 ) || die "\n$options"; | |
43 | |
44 if( $m eq "" ){ | |
45 print "Error: set a value for -m\n\n$options"; | |
46 exit; | |
47 } | |
48 if( $o eq "" ){ | |
49 print "Error: set a value for -o\n\n$options"; | |
50 exit; | |
51 } | |
52 if( $f != 1 && $f != 2 ){ | |
53 print "Error: set -f to be 1 or 2\n\n$options"; | |
54 exit; | |
55 } | |
56 if( $a ne "y" && $a ne "n" ){ | |
57 print "Error: set -a to be y or n\n\n$options"; | |
58 exit; | |
59 } | |
60 if( $k ne "y" && $k ne "n" ){ | |
61 print "Error: set -k to be y or n\n\n$options"; | |
62 exit; | |
63 } | |
64 if( $lx ne "y" && $lx ne "n" ){ | |
65 print "Error: set -lx to be y or n\n\n$options"; | |
66 exit; | |
67 } | |
68 if( $ly ne "y" && $ly ne "n" ){ | |
69 print "Error: set -ly to be y or n\n\n$options"; | |
70 exit; | |
71 } | |
72 if( $yr ne "zzzzzzzzzzz" && $yr !~ /,/ ){ | |
73 print "Error: if setting -yr, choose a range delimited by a comma\n\n$options"; | |
74 exit; | |
75 } | |
76 | |
77 @parts = split('\.',$m); | |
78 $name = $o; | |
79 #for($i=1; $i< $#parts; $i++){ | |
80 # $name = sprintf("%s.%s", $name, $parts[$i]); | |
81 #} | |
82 | |
83 # | |
84 # read in matrix | |
85 # | |
86 open(IN,"$m") || die "Error: can't open file $m\n"; | |
87 @re = (); | |
88 @mat = (); | |
89 | |
90 # burn 2 lines | |
91 $line = <IN>; | |
92 $line = <IN>; | |
93 | |
94 @coloffs = (); | |
95 while($line = <IN>){ | |
96 chomp($line); | |
97 @parts = split(' ',$line); | |
98 if( ($a eq "n" && $parts[0] !~ /#/) || $a eq "y" ){ | |
99 push(@coloffs, 1 ); | |
100 ($ind, $reval) = split(',', $parts[0]); | |
101 if( $reval eq "nan" ){$reval = 0.0;} | |
102 push(@re, $reval); | |
103 @tmp = (); | |
104 for($i=1; $i<= $#parts; $i++){ | |
105 if( $parts[$i] eq "NA" ){ | |
106 $parts[$i] = 0.0; | |
107 } | |
108 push(@tmp, $parts[$i]); | |
109 } | |
110 push(@mat, [@tmp] ); | |
111 } | |
112 else{ | |
113 push(@coloffs, 0); | |
114 } | |
115 } | |
116 close(IN); | |
117 | |
118 # | |
119 # rescale matrix so it's between 0 and 1, then multiply by re | |
120 # | |
121 for($i=0; $i<= $#mat; $i++){ | |
122 $min = $mat[$i][0]; | |
123 $max = $mat[$i][0]; | |
124 for($j=1; $j< 5; $j++){ | |
125 if( $min > $mat[$i][$j] ){ $min = $mat[$i][$j]; } | |
126 if( $max < $mat[$i][$j] ){ $max = $mat[$i][$j]; } | |
127 } | |
128 for($j=0; $j< 5; $j++){ | |
129 if( $max != $min ){ | |
130 $mat[$i][$j] = $re[$i]*(($mat[$i][$j]-$min)/($max-$min)); | |
131 } | |
132 else{ | |
133 $mat[$i][$j] = 0; | |
134 } | |
135 } | |
136 } | |
137 | |
138 | |
139 # | |
140 # print out in stacked format | |
141 # | |
142 open(OUT,">$name.logo"); | |
143 for($i=0; $i<= $#mat; $i++){ | |
144 $posn = ($mat[$i][0] + $mat[$i][1] + 0.5*$mat[$i][2]); | |
145 printf OUT ("%f ", -0.5*$mat[$i][2]); | |
146 printf OUT ("%f ", -$mat[$i][3]); | |
147 printf OUT ("%f ", -$mat[$i][4]); | |
148 printf OUT ("%f ", 0.5*$mat[$i][2]); | |
149 printf OUT ("%f ", $mat[$i][1]); | |
150 printf OUT ("%f ", $mat[$i][0]); | |
151 printf OUT ("0 0 0 0 0\n"); | |
152 } | |
153 close(OUT); | |
154 | |
155 # | |
156 # make gnu-plotable file | |
157 # | |
158 | |
159 # possibly read in conditions to define xtics | |
160 $tics = ""; | |
161 if( $c ne "" ){ | |
162 open(IN,"$c") || die "Error: can't open file $c\n"; | |
163 @comps = (); | |
164 $i = 0; | |
165 while($line = <IN>){ | |
166 chomp($line); | |
167 @parts = split(' ',$line); | |
168 if( $#parts != 1 ){ | |
169 print "Error: comparisons list does not have 2 columns\n"; | |
170 exit; | |
171 } | |
172 if( $coloffs[$i] == 1 ){ | |
173 $val = sprintf("%s vs %s", $parts[0], $parts[1]); | |
174 push(@comps, $val); | |
175 } | |
176 $i++; | |
177 } | |
178 $tics = "set xtics(\"$comps[0]\" 0"; | |
179 for($i=1; $i<= $#comps; $i++){ | |
180 $tics = sprintf("%s, \"%s\" %i", $tics, $comps[$i], $i); | |
181 } | |
182 $tics = sprintf("%s)\nset xtics rotate by -45", $tics); | |
183 } | |
184 | |
185 # choose format | |
186 if( $f == 1 ){ | |
187 $format = "postscript eps color 24"; | |
188 $suff = "eps"; | |
189 } | |
190 if( $f == 2 ){ | |
191 $format = "cgm \"Helvetica\" 14"; | |
192 $suff = "cgm"; | |
193 } | |
194 | |
195 # set xrange min and max | |
196 $min = -0.5; | |
197 $max = $#mat+0.5; | |
198 | |
199 # possibly turn off key, xlabel, ylabel | |
200 $keytoggle = ""; | |
201 $xtoggle = ""; | |
202 $ytoggle = ""; | |
203 if( $k eq "n" ){ | |
204 $keytoggle = "unset key"; | |
205 } | |
206 if( $lx eq "n" ){ | |
207 $xtoggle = "unset xtics"; | |
208 } | |
209 if( $ly eq "n" ){ | |
210 $ytoggle = "unset ylabel"; | |
211 } | |
212 | |
213 # possibly set yrange | |
214 $yrange = ""; | |
215 if( $yr ne "zzzzzzzzzzz" ){ | |
216 @parts = split(',',$yr); | |
217 if( $#parts != 1 ){ | |
218 print "Error: more than two fields in your -yr value\n"; | |
219 exit; | |
220 } | |
221 $yrange = sprintf("set yrange [%f:%f]", $parts[0], $parts[1]); | |
222 } | |
223 | |
224 @lines = ( "#!/bin/sh", | |
225 "gnuplot << EOF", | |
226 "reset", | |
227 "set style fill solid 1.00 noborder", | |
228 "set style histogram rowstacked", | |
229 "set style data histograms", | |
230 "set ylabel \"Bits x direction of regulation\"", | |
231 "set key outside", | |
232 "set xrange [$min: $max]", | |
233 "$tics", | |
234 "$keytoggle", | |
235 "$xtoggle", | |
236 "$ytoggle", | |
237 "$yrange", | |
238 "set terminal $format", | |
239 "set output \'$o\'", | |
240 "plot \'$name.logo\' u 1 notitle lc rgbcolor \"#000000\", \'\' u 2 notitle lc rgbcolor \"#008800\", \'\' u 3 notitle lc rgbcolor \"#00FF00\", \'\' u 7 t \"++\" lc rgbcolor \"#FF0000\", \'\' u 8 t \"+\" lc rgbcolor \"#880000\", \'\' u 9 t \"0\" lc rgbcolor \"#000000\", \'\' u 10 t \"-\" lc rgbcolor \"#008800\", \'\' u 11 t \"--\" lc rgbcolor \"#00FF00\", \'\' u 4 notitle lc rgbcolor \"#000000\", \'\' u 5 notitle lc rgbcolor \"#880000\", \'\' u 6 notitle lc rgbcolor \"#FF0000\"", | |
241 "EOF" | |
242 ); | |
243 | |
244 $command = sprintf("%s\n", $lines[0]); | |
245 for($i=1; $i<= $#lines; $i++){ | |
246 $command = sprintf("%s%s\n", $command, $lines[$i]); | |
247 } | |
248 | |
249 system("$command"); | |
250 | |
251 | |
252 | |
253 | |
254 |