[Bio] / FigKernelScripts / svr_tree_to_html.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/svr_tree_to_html.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (view) (download) (as text)

1 : fangfang 1.1 #
2 :     # This is a SAS Component
3 :     #
4 :    
5 :     #
6 : golsen 1.13 # Copyright (c) 2003-2011 University of Chicago and Fellowship
7 : fangfang 1.1 # for Interpretations of Genomes. All Rights Reserved.
8 :     #
9 :     # This file is part of the SEED Toolkit.
10 :     #
11 :     # The SEED Toolkit is free software. You can redistribute
12 :     # it and/or modify it under the terms of the SEED Toolkit
13 :     # Public License.
14 :     #
15 :     # You should have received a copy of the SEED Toolkit Public License
16 :     # along with this program; if not write to the University of Chicago
17 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
18 :     # Genomes at veronika@thefig.info or download a copy from
19 :     # http://www.theseed.org/LICENSE.TXT.
20 :     #
21 :    
22 :     use strict;
23 :     use Data::Dumper;
24 :     use Carp;
25 :     use Getopt::Long;
26 :    
27 :     =head1 svr_tree_to_html
28 :    
29 :     svr_tree_to_html [options] < tree.newick > tree.html
30 :    
31 : fangfang 1.2 This script converts a newick tree into an HTML page. It has a rich
32 :     set of options.
33 : fangfang 1.1
34 :     =head1 Introduction
35 :    
36 :     usage: svr_tree_to_html [options] < tree.newick > tree.html
37 :    
38 :     -a alias_file - relabel tips using aliases # table: [id alias]
39 : fangfang 1.4 -b - show bootstrap/branch support values
40 : golsen 1.13 -bar - show scale bar
41 : fangfang 1.1 -c tax|role|file - color tips by taxonomy, roles,
42 :     or groups specified in a file # table: [id group]
43 :     -d desc_file - add description to each tip # table: [id description]
44 : fangfang 1.4 -f focus_list - highlight a list of tips # table: [id]
45 : fangfang 1.9 -k keep_list - keep only the taxa listed # table: [id]
46 : fangfang 1.1 -l link_file - add URL to each tip # table: [id URL]
47 : fangfang 1.7 -lt link_w_text - add additional linked text # table: [id text URL]
48 : fangfang 1.1 -m popup_file - add simple mouseover to each tip # table: [id popup]
49 : fangfang 1.3 -nc n_colors - number of colors to use (D = 10)
50 : fangfang 1.1 -p g|s|file - collapse trees by genus, species,
51 :     or groups specified in a file # table: [id group]
52 : fangfang 1.7 -s show_list - preferred tips to show when collapsing subtrees
53 :     (D = Woese' list of 69 common organisms)
54 : fangfang 1.1 -t title - title for html page
55 : golsen 1.13 -units label - units label for scale bar; implies -bar
56 : fangfang 1.14 -va fa1[,fa2,..] - vector annotation files
57 : fangfang 1.4 -x min_dx - minimum horizontal space between consecutive nodes (D = 1)
58 :     -y dy - vertical separation of consecutive tips (D = 1)
59 : fangfang 1.1
60 :     -anno - use the annotator's SEED for URLs
61 :     -gray n - gray out name from the n-th word # default: 2
62 :     -pseed - use PSEED
63 : fangfang 1.10 -ppseed - use PUBSEED
64 : fangfang 1.1 -raw - do not color or collapse tree,
65 :     may be superseded by -c and -p
66 :    
67 :     =head2 Command-line options
68 :    
69 :     =over 4
70 :    
71 :     =item -a alias_file
72 :    
73 :     The sequence IDs in the FASTA file may not be what a user wants to see
74 :     in the visualized tree. The alias file is a two-column table
75 :     containing ID to alias mapping [ id alias ], and the tree tips will be
76 :     relabeled with the aliases.
77 :    
78 :     The alias file can also be used to supply a mapping from original
79 :     sequence ID to FIG peg ID. With FIG ids, taxonomoy and function
80 :     information can be automatically retrieved from the SEED server and
81 :     painted to the tree tips.
82 :    
83 : fangfang 1.4 =item -b
84 : fangfang 1.1
85 : fangfang 1.4 With the -b option, bootstrap values (or branch support values) are
86 :     shown in percent for internal nodes of the tree. min_dx and dy are set
87 :     to 2 unless they are explicitly specified.
88 : fangfang 1.1
89 : golsen 1.13 =item -bar
90 :    
91 :     Include a scale bar on the drawing.
92 :    
93 : fangfang 1.1 =item -c tax | role | group_file
94 :    
95 :     The value for the -c option can be a string ('tax' or 'role') or the
96 :     name of a two-column table [ id, group ] that classifies the sequences
97 :     into multiple groups. Correspondingly, the tips of the tree will be
98 :     colord according to their major taxonomy group, functional role, or
99 :     the customized group.
100 :    
101 :     If tips are colored based on taxonomy groups, a taxonomy legend is
102 :     shown. Otherwise, a table of color group (functional role by default)
103 :     frequencies is shown.
104 :    
105 :     The default behavior is to color tree tips by taxonomy groups.
106 :    
107 :     =item -d description_file
108 :    
109 :     A two-column table [ id, description ]. The description string will
110 :     appear in parentheses after the sequence ID for each tip of the tree.
111 :    
112 : fangfang 1.4 =item -f focus_list
113 :    
114 :     A file with space-delimited IDs for sequences to be highlighted.
115 :    
116 : fangfang 1.9 =item -k keep_list
117 :    
118 :     Keep only the taxa listed (one per line) in the file keep.
119 :    
120 : fangfang 1.1 =item -l link_file
121 :    
122 :     A two-column table [ id, url ] for inserting URL for tree tips.
123 :    
124 : fangfang 1.7 =item -lt linked_text_file
125 :    
126 :     A three-column table [ id, text, url ] for inserting linked text for tree tips.
127 :    
128 : fangfang 1.1 =item -m mouseover_file
129 :    
130 :     A two-column table [ id, mouseover_description ]. The mouseover
131 :     description string will appear in the popup box for the specified tip.
132 :    
133 : fangfang 1.3 =item -nc n_colors
134 :    
135 :     The number of colors to use for tree tips (D = 10). Max: 20.
136 :    
137 : fangfang 1.1 =item -p g | s | group_file
138 :    
139 :     This option provides a rule for collapsing subtrees whose tips all
140 :     belong to the same group. The value for the -p option can be a string
141 :     ('g' for genus, or, 's' for species), or the name of a two-column
142 :     table [ id, group ] that classifies the sequenes into multiple groups.
143 :    
144 :     The default behavior is to collapse subtrees whose nodes all belong to
145 :     the same genus.
146 :    
147 : fangfang 1.7 =item -s show_list (D = Woese' list of 69 common organisms)
148 :    
149 :     Show a list of preferred tips when collapsing subtrees.
150 :    
151 : fangfang 1.1 =item -t html_title
152 :    
153 :     This title of the HTML page.
154 :    
155 : golsen 1.13 =item -units scale_bar_units
156 :    
157 :     Include a scale bar with the specified units (inplies -bar).
158 :    
159 : fangfang 1.4 =item -x n
160 :    
161 :     Specifies the minimum length of a distance between two nodes. (D = 1)
162 :    
163 :     =item -y n
164 :    
165 :     Specifies vertical separation of consecutive tips. (D = 1)
166 :    
167 : fangfang 1.1 =item -anno
168 :    
169 :     With the -anno option, the tree tips will be linked to the annotator's
170 :     SEED instead of the SEED viewer.
171 :    
172 :     =item -gray n
173 :    
174 :     Gray out the tip names after the n-th word. (D = 2)
175 :    
176 :     =item -pseed
177 :    
178 :     With the -pseed option, the taxonomy and function information is
179 :     retrieved from the PSEED server. Setting the environment variable
180 :     SAS_SERVER to 'PSEED' has the same effect.
181 :    
182 : fangfang 1.9 =item -ppseed
183 :    
184 :     With the -ppseed option, the taxonomy and function information is
185 : fangfang 1.10 retrieved from the PUBSEED server. Setting the environment variable
186 :     SAS_SERVER to 'PUBSEED' has the same effect.
187 : fangfang 1.9
188 : fangfang 1.1 =item -raw
189 :    
190 :     Do not color or collapse the tree. This option maybe superseded if -c
191 :     or -p is present.
192 :    
193 :     =back
194 :    
195 :     =head2 Input
196 :    
197 :     The input tree is a newick file read from STDIN.
198 :    
199 :     =head2 Output
200 :    
201 :     The output is a HTML page written to STDOUT.
202 :    
203 :     =cut
204 :    
205 :     use AlignTree;
206 :     use ATserver;
207 :     use SeedUtils;
208 :    
209 :     use ffxtree;
210 :     use gjoalignment;
211 : fangfang 1.11 use gjonewicklib;
212 : fangfang 1.1 use gjoseqlib;
213 :    
214 :     my $usage = <<"End_of_Usage";
215 :    
216 :     usage: svr_tree_to_html [options] < tree.newick > tree.html
217 :    
218 :     -a alias_file - relabel tips using aliases # file: [id alias]
219 : fangfang 1.4 -b - show bootstrap/branch support values
220 : golsen 1.13 -bar - show scale bar
221 : fangfang 1.1 -c tax|role|file - color tips by taxonomy, roles,
222 :     or groups specified in a file # file: [id group]
223 :     -d desc_file - add description to each tip # file: [id description]
224 : fangfang 1.5 -f focus_list - highlight a list of tips # file: [id]
225 : fangfang 1.9 -k keep_list - keep only the taxa listed # table: [id]
226 : fangfang 1.1 -l link_file - add URL to each tip # file: [id URL]
227 : fangfang 1.7 -lt link_w_text - add additional linked text # file: [id text URL]
228 : fangfang 1.1 -m popup_file - add simple mouseover to each tip # file: [id popup]
229 : fangfang 1.3 -nc n_colors - number of colors to use (D = 10)
230 : fangfang 1.1 -p g|s|file - collapse trees by genus, species,
231 :     or groups specified in a file # file: [id group]
232 : fangfang 1.7 -s show_list - preferred tips to show when collapsing subtrees
233 :     (D = Woese' list of 69 common organisms)
234 : fangfang 1.1 -t title - title for html page
235 : golsen 1.13 -units label - units label for scale bar; implies -bar
236 : fangfang 1.14 -va fa1[,fa2,..] - vector annotation files
237 : fangfang 1.4 -x min_dx - minimum horizontal space between consecutive nodes (D = 1)
238 :     -y dy - vertical separation of consecutive tips (D = 1)
239 : fangfang 1.1 -anno - use the annotator's SEED for URLs
240 :     -gray n - gray out name from the n-th word # default: 2
241 :     -pseed - use PSEED
242 : fangfang 1.10 -ppseed - use PUBSEED
243 : fangfang 1.1 -raw - do not color or collapse the tree,
244 :     may be superseded by -c and -p
245 :    
246 :     End_of_Usage
247 :    
248 : fangfang 1.7 my ($help, $url, $alias_file, $focus_file, $branch, $collapse_by, $show_file,
249 : fangfang 1.9 $desc_file, $keep_file, $link_file, $text_link, $popup_file, $id_file, $title,
250 : fangfang 1.14 $min_dx, $dy, $ncolor, $color_by, $anno, $gray, $pseed, $ppseed, $raw, $va_files,
251 : golsen 1.13 $scale_bar, $scale_lbl);
252 : fangfang 1.1
253 :     GetOptions("h|help" => \$help,
254 :     "a|alias=s" => \$alias_file,
255 : golsen 1.13 "bar" => \$scale_bar, # include a scale bar
256 : fangfang 1.4 "b|branch" => \$branch,
257 : fangfang 1.1 "c|color=s" => \$color_by,
258 :     "d|desc=s" => \$desc_file,
259 : fangfang 1.4 "f|focus=s" => \$focus_file,
260 : fangfang 1.1 "i|id=s" => \$id_file,
261 : fangfang 1.9 "k|keep=s" => \$keep_file,
262 : fangfang 1.1 "l|link=s" => \$link_file,
263 : fangfang 1.7 "lt=s" => \$text_link,
264 : fangfang 1.1 "m|popup=s" => \$popup_file,
265 :     "nc=i" => \$ncolor,
266 :     "p|collapse=s" => \$collapse_by,
267 : fangfang 1.7 "s|show=s" => \$show_file,
268 : fangfang 1.1 "t|title=s" => \$title,
269 : golsen 1.13 "units=s" => \$scale_lbl, # units label for scale bar
270 : fangfang 1.14 "va=s" => \$va_files,
271 : fangfang 1.4 "x|dx=i" => \$min_dx,
272 :     "y|dy=i" => \$dy,
273 : fangfang 1.1 "anno" => \$anno,
274 : fangfang 1.12 "g|gray=s" => \$gray,
275 : fangfang 1.1 "pseed" => \$pseed,
276 : fangfang 1.9 "ppseed" => \$ppseed,
277 : fangfang 1.1 "raw" => \$raw);
278 :    
279 :     $help and die $usage;
280 :    
281 : fangfang 1.14 my @va;
282 :     if ($va_files) {
283 :     for my $vaF (split(/,/, $va_files)) {
284 :     my $anno = ffxtree::read_vector_annotation($vaF);
285 :     push @va, $anno if $anno;
286 :     }
287 :     }
288 :    
289 : golsen 1.13 my $opts = {};
290 : fangfang 1.1
291 : fangfang 1.7 $opts->{show_branch} = $branch;
292 :     $opts->{color_by} = $color_by;
293 :     $opts->{collapse_by} = $collapse_by;
294 :     $opts->{focus_set} = ffxtree::read_set($focus_file) if $focus_file && -s $focus_file;
295 :     $opts->{alias} = ffxtree::read_hash($alias_file) if $alias_file && -s $alias_file;
296 :     $opts->{color_by} = ffxtree::read_hash($color_by) if $color_by && -s $color_by;
297 :     $opts->{collapse_by} = ffxtree::read_hash($collapse_by) if $collapse_by && -s $collapse_by;
298 :     $opts->{collapse_show} = ffxtree::read_set($show_file) if $show_file && -s $show_file;
299 : fangfang 1.9 $opts->{keep} = ffxtree::read_set($keep_file) if $keep_file && -s $keep_file;
300 : fangfang 1.7 $opts->{desc} = ffxtree::read_hash($desc_file) if $desc_file && -s $desc_file;
301 :     $opts->{popup} = ffxtree::read_hash($popup_file) if $popup_file && -s $popup_file;
302 :     $opts->{link} = ffxtree::read_hash($link_file) if $link_file && -s $link_file;
303 :     $opts->{text_link} = ffxtree::read_hash($text_link) if $text_link && -s $text_link;
304 :     $opts->{tree} = ffxtree::read_tree();
305 :     $opts->{ncolor} = $ncolor || 10;
306 :     $opts->{gray} = $gray || 2;
307 :     $opts->{min_dx} = $min_dx || $branch ? 2 : 1;
308 :     $opts->{dy} = $dy || $branch ? 2 : 1;
309 :     $opts->{title} = $title;
310 :     $opts->{anno} = $anno;
311 :     $opts->{raw} = $raw;
312 : golsen 1.13 $opts->{scale_bar} = $scale_bar if $scale_bar;
313 :     $opts->{scale_lbl} = $scale_lbl if defined $scale_lbl;
314 : fangfang 1.14 $opts->{anno_vectors} = \@va if @va;
315 : fangfang 1.7
316 :     $opts->{color_by} ||= $raw ? 'none' : 'taxonomy';
317 :     $opts->{collapse_by} ||= $raw ? 'none' : 'genus';
318 :     $opts->{collapse_show} ||= $raw ? 'none' : 'woese';
319 :    
320 : fangfang 1.8 $opts->{color_by} = 0 if $opts->{color_by} =~ /^none$/i;
321 :     $opts->{collapse_by} = 0 if $opts->{collapse_by} =~ /^none$/i;
322 :     $opts->{collapse_show} = 0 if $show_file =~ /^none$/i;
323 : fangfang 1.1
324 :     my $envParm = $ENV{SAS_SERVER};
325 :    
326 : fangfang 1.10 $ENV{SAS_SERVER} = 'PSEED' if $pseed;
327 :     $ENV{SAS_SERVER} = 'PUBSEED' if $ppseed;
328 : fangfang 1.1
329 :     my $html = ffxtree::tree_to_html($opts);
330 :    
331 : fangfang 1.9 $ENV{SAS_SERVER} = $envParm if $pseed || $ppseed;
332 : fangfang 1.1
333 :     print $html;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3