Parent Directory
|
Revision Log
Revision 1.4 - (view) (download) (as text)
1 : | overbeek | 1.1 | ######################################################################## |
2 : | # -*- perl -*- | ||
3 : | # | ||
4 : | # Copyright (c) 2003-2006 University of Chicago and Fellowship | ||
5 : | # for Interpretations of Genomes. All Rights Reserved. | ||
6 : | # | ||
7 : | # This file is part of the SEED Toolkit. | ||
8 : | # | ||
9 : | # The SEED Toolkit is free software. You can redistribute | ||
10 : | # it and/or modify it under the terms of the SEED Toolkit | ||
11 : | # Public License. | ||
12 : | # | ||
13 : | # You should have received a copy of the SEED Toolkit Public License | ||
14 : | # along with this program; if not write to the University of Chicago | ||
15 : | # at info@ci.uchicago.edu or the Fellowship for Interpretation of | ||
16 : | # Genomes at veronika@thefig.info or download a copy from | ||
17 : | # http://www.theseed.org/LICENSE.TXT. | ||
18 : | # | ||
19 : | |||
20 : | use Carp; | ||
21 : | use Data::Dumper; | ||
22 : | use gjoseqlib; | ||
23 : | |||
24 : | use FIG; | ||
25 : | my $fig = new FIG; | ||
26 : | |||
27 : | use AliTree; | ||
28 : | use AliTrees; | ||
29 : | |||
30 : | # usage: ali_tree [DIR] | ||
31 : | |||
32 : | my $default_dir; | ||
33 : | if (@ARGV > 0) | ||
34 : | { | ||
35 : | $default_dir = shift @ARGV; | ||
36 : | } | ||
37 : | else | ||
38 : | { | ||
39 : | $default_dir = "$FIG_Config::data/AlignmentsAndTrees"; | ||
40 : | } | ||
41 : | |||
42 : | use AliTrees; | ||
43 : | my $ali_trees = new AliTrees($fig,$default_dir); | ||
44 : | |||
45 : | my $ali_tree; | ||
46 : | my($dir); | ||
47 : | while ($req = &get_req) | ||
48 : | { | ||
49 : | overbeek | 1.2 | if ($req =~ /^\s*set\s+(\d+\.\d+\.peg\.\S+)\s*$/) |
50 : | overbeek | 1.1 | { |
51 : | $id = $1; | ||
52 : | $ali_tree = new AliTree($id,$fig,$default_dir); | ||
53 : | $ali_tree | ||
54 : | || warn "could not handle $id in $default_dir\n"; | ||
55 : | } | ||
56 : | elsif ($req =~ /^\s*set_all\s*$/) | ||
57 : | { | ||
58 : | $ali_trees->set_all; | ||
59 : | print "set_all completed\n"; | ||
60 : | } | ||
61 : | elsif ($req =~ /^\s*all_alignments\s*$/) | ||
62 : | { | ||
63 : | foreach $_ ($ali_trees->all_alignments) | ||
64 : | { | ||
65 : | print "$_\n"; | ||
66 : | } | ||
67 : | print "\n"; | ||
68 : | } | ||
69 : | elsif ($req =~ /^\s*delete_ali\s+(\S+)\s*$/) | ||
70 : | { | ||
71 : | $ali = $1; | ||
72 : | $rc = $ali_trees->delete_ali($ali); | ||
73 : | print &Dumper($rc); | ||
74 : | print "\n"; | ||
75 : | } | ||
76 : | elsif ($req =~ /^\s*add_ali\s+(\S+)\s*$/) | ||
77 : | { | ||
78 : | $dir_to_add = $1; | ||
79 : | $rc = $ali_trees->add_ali($dir_to_add); | ||
80 : | print &Dumper($rc); | ||
81 : | print "\n"; | ||
82 : | } | ||
83 : | elsif ($req =~ /^\s*alignments_containing_peg\s+(\S+)\s*$/) | ||
84 : | { | ||
85 : | $peg = $1; | ||
86 : | foreach $_ ($ali_trees->alignments_containing_peg($peg)) | ||
87 : | { | ||
88 : | print "$_\n"; | ||
89 : | } | ||
90 : | print "\n"; | ||
91 : | } | ||
92 : | overbeek | 1.4 | elsif ($req =~ /^\s*functions_in(\s+(\S+))?\s*$/) |
93 : | { | ||
94 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
95 : | my $ali = $ali_tree->id; | ||
96 : | |||
97 : | my($pegM,$funcM); | ||
98 : | if ($ali =~ /^(\d+\.\d+\.peg\.\d+)/) | ||
99 : | { | ||
100 : | $pegM = 'fig|' . $1; | ||
101 : | $funcM = $fig->function_of($pegM); | ||
102 : | print "$ali\t$pegM\t$funcM\n\n"; | ||
103 : | } | ||
104 : | foreach $_ ($ali_tree->functions_in) | ||
105 : | { | ||
106 : | print join("\t",@$_),"\n"; | ||
107 : | } | ||
108 : | print "\n"; | ||
109 : | } | ||
110 : | overbeek | 1.1 | elsif ($req =~ /^\s*pegs_in_alignment(\s+(\S+))?\s*$/) |
111 : | { | ||
112 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
113 : | if (! $ali_tree) | ||
114 : | { | ||
115 : | print "you need to specify an alignment\n\n"; | ||
116 : | } | ||
117 : | else | ||
118 : | { | ||
119 : | my $h = $ali_tree->pegs_in_alignment($ali_tree->id); | ||
120 : | foreach $peg (sort { &FIG::by_fig_id($a,$b) } keys(%$h)) | ||
121 : | { | ||
122 : | my $coords = $h->{$peg}; | ||
123 : | print join("\t",($peg,@$coords)),"\n"; | ||
124 : | } | ||
125 : | } | ||
126 : | print "\n"; | ||
127 : | } | ||
128 : | elsif ($req =~ /^\s*merge\s+(\S+)\s+(\S+)\s*$/) | ||
129 : | { | ||
130 : | $aliID1 = $1; | ||
131 : | $aliID2 = $2; | ||
132 : | $aliID3 = $ali_trees->merge_ali($aliID1,$aliID2); | ||
133 : | print defined($aliID3) ? $aliID3 : "failed to merge $aliID1 and $aliID2","\n\n"; | ||
134 : | } | ||
135 : | elsif ($req =~ /^\s*indel_ratio(\s+(\S+))?\s*$/) | ||
136 : | { | ||
137 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
138 : | if (! $ali_tree) | ||
139 : | { | ||
140 : | print "you need to specify an alignment\n\n"; | ||
141 : | } | ||
142 : | else | ||
143 : | { | ||
144 : | print $ali_tree->indel_ratio,"\n"; | ||
145 : | } | ||
146 : | print "\n"; | ||
147 : | } | ||
148 : | elsif ($req =~ /^\s*overlaps(\s+(\S+))?\s*$/) | ||
149 : | { | ||
150 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
151 : | if (! $ali_tree) | ||
152 : | { | ||
153 : | print "you need to specify an alignment\n\n"; | ||
154 : | } | ||
155 : | else | ||
156 : | { | ||
157 : | $sz = $ali_tree->sz; | ||
158 : | print "Overlaps for ",$ali_tree->id,", which contains $sz seqauences\n\n"; | ||
159 : | $overlaps = $ali_tree->overlaps; | ||
160 : | @tmp = (); | ||
161 : | foreach $ali1 (keys(%$overlaps)) | ||
162 : | { | ||
163 : | my $ali_tree1 = new AliTree($ali1,$fig,$default_dir); | ||
164 : | push(@tmp,[$ali1,scalar @{$overlaps->{$ali1}},$ali_tree1->sz]); | ||
165 : | } | ||
166 : | @tmp = sort { $b->[1] <=> $a->[1] } @tmp; | ||
167 : | foreach $tuple (@tmp) | ||
168 : | { | ||
169 : | print join("\t",@$tuple),"\n"; | ||
170 : | } | ||
171 : | } | ||
172 : | print "\n"; | ||
173 : | } | ||
174 : | elsif ($req =~ /^\s*tree(\s+(\S+))?\s*$/) | ||
175 : | { | ||
176 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
177 : | if (! $ali_tree) | ||
178 : | { | ||
179 : | print "you need to specify an alignment\n\n"; | ||
180 : | } | ||
181 : | else | ||
182 : | { | ||
183 : | $id = $ali_tree->id; | ||
184 : | $tree = $ali_tree->tree; | ||
185 : | overbeek | 1.3 | if (-s "$default_dir/Library/$id/tree.newick") |
186 : | overbeek | 1.1 | { |
187 : | overbeek | 1.3 | system "sketch_tree -a $default_dir/Library/$id/tree.newick"; |
188 : | overbeek | 1.1 | } |
189 : | else | ||
190 : | { | ||
191 : | print "no tree for $id\n"; | ||
192 : | } | ||
193 : | } | ||
194 : | print "\n"; | ||
195 : | } | ||
196 : | elsif ($req =~ /^\s*sz(\s+(\S+))?\s*$/) | ||
197 : | { | ||
198 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
199 : | if (! $ali_tree) | ||
200 : | { | ||
201 : | print "you need to specify an alignment\n\n"; | ||
202 : | } | ||
203 : | else | ||
204 : | { | ||
205 : | print $ali_tree->sz;; | ||
206 : | } | ||
207 : | print "\n"; | ||
208 : | } | ||
209 : | elsif ($req =~ /^\s*display(\s+(\S+))?\s*$/) | ||
210 : | { | ||
211 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
212 : | if (! $ali_tree) | ||
213 : | { | ||
214 : | print "you need to specify an alignment\n\n"; | ||
215 : | } | ||
216 : | else | ||
217 : | { | ||
218 : | print $ali_tree->display; | ||
219 : | } | ||
220 : | print "\n"; | ||
221 : | } | ||
222 : | elsif ($req =~ /^\s*html(\s+(\S+))?\s*$/) | ||
223 : | { | ||
224 : | $ali_tree = $2 ? new AliTree($2,$fig,$default_dir) : $ali_tree; | ||
225 : | if (! $ali_tree) | ||
226 : | { | ||
227 : | print "you need to specify an alignment\n\n"; | ||
228 : | } | ||
229 : | else | ||
230 : | { | ||
231 : | my $id = $ali_tree->id; | ||
232 : | my $tmpdir = "$FIG_Config::fig/Tmp/Alignments"; | ||
233 : | &FIG::verify_dir($tmpdir); | ||
234 : | if (! -s "$tmpdir/$id.html") | ||
235 : | { | ||
236 : | if (open(HTML,">$tmpdir/$id.html")) | ||
237 : | { | ||
238 : | print HTML $ali_tree->html,"\n"; | ||
239 : | close(HTML); | ||
240 : | } | ||
241 : | } | ||
242 : | } | ||
243 : | print "\n"; | ||
244 : | } | ||
245 : | elsif ($req =~ /^\s*load_db\s*$/) | ||
246 : | { | ||
247 : | $ali_trees->load_db; | ||
248 : | } | ||
249 : | elsif ($req =~ /^\s*h\s*$/ || $req =~ /^\s*help\s*$/) | ||
250 : | { | ||
251 : | &help; | ||
252 : | } | ||
253 : | else | ||
254 : | { | ||
255 : | print "invalid command\n"; | ||
256 : | } | ||
257 : | print "\n"; | ||
258 : | } | ||
259 : | |||
260 : | sub get_req { | ||
261 : | my($x); | ||
262 : | |||
263 : | print "?? "; | ||
264 : | $x = <STDIN>; | ||
265 : | while (defined($x) && ($x =~ /^h$/i) ) | ||
266 : | { | ||
267 : | &help; | ||
268 : | print "?? "; | ||
269 : | $x = <STDIN>; | ||
270 : | } | ||
271 : | |||
272 : | if ((! defined($x)) || ($x =~ /^\s*[qQxX]/)) | ||
273 : | { | ||
274 : | return ""; | ||
275 : | } | ||
276 : | else | ||
277 : | { | ||
278 : | if ($echo) | ||
279 : | { | ||
280 : | print ">> $x\n"; | ||
281 : | } | ||
282 : | return $x; | ||
283 : | } | ||
284 : | } | ||
285 : | |||
286 : | |||
287 : | sub help { | ||
288 : | print <<END; | ||
289 : | |||
290 : | add_ali Ali | ||
291 : | alignments_containing_peg PEG | ||
292 : | all_alignments | ||
293 : | delete_ali Ali | ||
294 : | display [Ali] | ||
295 : | overbeek | 1.4 | functions_in [Ali] |
296 : | overbeek | 1.1 | h |
297 : | html Ali | ||
298 : | indel_ratio [Ali] | ||
299 : | load_db | ||
300 : | merge Ali1 Ali2 [creates Ali1-n and displays the computed ID] | ||
301 : | overlaps [Ali] | ||
302 : | pegs_in_alignment [Ali] | ||
303 : | set Ali | ||
304 : | set_all | ||
305 : | sz [Ali] | ||
306 : | tree [Ali] | ||
307 : | END | ||
308 : | } |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |