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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3