Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Tools/Run/WrapperBase.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 # $Id: WrapperBase.pm,v 1.7.2.2 2003/03/11 10:52:26 jason Exp $ | |
2 # | |
3 # BioPerl module for Bio::Tools::Run::WrapperBase | |
4 # | |
5 # Cared for by Jason Stajich <jason@bioperl.org> | |
6 # | |
7 # Copyright Jason Stajich | |
8 # | |
9 # You may distribute this module under the same terms as perl itself | |
10 | |
11 # POD documentation - main docs before the code | |
12 | |
13 =head1 NAME | |
14 | |
15 Bio::Tools::Run::WrapperBase - A Base object for wrappers around executables | |
16 | |
17 =head1 SYNOPSIS | |
18 | |
19 # do not use this object directly, it provides the following methods | |
20 # for its subclasses | |
21 | |
22 my $errstr = $obj->error_string(); | |
23 my $exe = $obj->executable(); | |
24 $obj->save_tempfiles($booleanflag) | |
25 my $outfile= $obj->outfile_name(); | |
26 my $tempdir= $obj->tempdir(); # get a temporary dir for executing | |
27 my $io = $obj->io; # Bio::Root::IO object | |
28 my $cleanup= $obj->cleanup(); # remove tempfiles | |
29 | |
30 $obj->run({-arg1 => $value}); | |
31 | |
32 =head1 DESCRIPTION | |
33 | |
34 This is a basic module from which to build executable wrapper modules. | |
35 It has some basic methods to help when implementing new modules. | |
36 | |
37 =head1 FEEDBACK | |
38 | |
39 =head2 Mailing Lists | |
40 | |
41 User feedback is an integral part of the evolution of this and other | |
42 Bioperl modules. Send your comments and suggestions preferably to | |
43 the Bioperl mailing list. Your participation is much appreciated. | |
44 | |
45 bioperl-l@bioperl.org - General discussion | |
46 http://bioperl.org/MailList.shtml - About the mailing lists | |
47 | |
48 =head2 Reporting Bugs | |
49 | |
50 Report bugs to the Bioperl bug tracking system to help us keep track | |
51 of the bugs and their resolution. Bug reports can be submitted via | |
52 email or the web: | |
53 | |
54 bioperl-bugs@bioperl.org | |
55 http://bioperl.org/bioperl-bugs/ | |
56 | |
57 =head1 AUTHOR - Jason Stajich | |
58 | |
59 Email jason@bioperl.org | |
60 | |
61 Describe contact details here | |
62 | |
63 =head1 CONTRIBUTORS | |
64 | |
65 Additional contributors names and emails here | |
66 | |
67 =head1 APPENDIX | |
68 | |
69 The rest of the documentation details each of the object methods. | |
70 Internal methods are usually preceded with a _ | |
71 | |
72 =cut | |
73 | |
74 | |
75 # Let the code begin... | |
76 | |
77 | |
78 package Bio::Tools::Run::WrapperBase; | |
79 use vars qw(@ISA); | |
80 use strict; | |
81 | |
82 # Object preamble - inherits from Bio::Root::Root | |
83 | |
84 use Bio::Root::RootI; | |
85 use Bio::Root::IO; | |
86 | |
87 @ISA = qw(Bio::Root::RootI); | |
88 | |
89 =head2 run | |
90 | |
91 Title : run | |
92 Usage : $wrapper->run({ARGS HERE}); | |
93 Function: Support generic running with args passed in | |
94 as a hashref | |
95 Returns : Depends on the implementation, status OR data | |
96 Args : hashref of named arguments | |
97 | |
98 | |
99 =cut | |
100 | |
101 sub run { | |
102 my ($self,@args) = @_; | |
103 $self->throw_not_implemented(); | |
104 } | |
105 | |
106 | |
107 =head2 error_string | |
108 | |
109 Title : error_string | |
110 Usage : $obj->error_string($newval) | |
111 Function: Where the output from the last analysus run is stored. | |
112 Returns : value of error_string | |
113 Args : newvalue (optional) | |
114 | |
115 | |
116 =cut | |
117 | |
118 sub error_string{ | |
119 my ($self,$value) = @_; | |
120 if( defined $value) { | |
121 $self->{'_error_string'} = $value; | |
122 } | |
123 return $self->{'_error_string'} || ''; | |
124 } | |
125 | |
126 | |
127 =head2 no_param_checks | |
128 | |
129 Title : no_param_checks | |
130 Usage : $obj->no_param_checks($newval) | |
131 Function: Boolean flag as to whether or not we should | |
132 trust the sanity checks for parameter values | |
133 Returns : value of no_param_checks | |
134 Args : newvalue (optional) | |
135 | |
136 | |
137 =cut | |
138 | |
139 sub no_param_checks{ | |
140 my ($self,$value) = @_; | |
141 if( defined $value || ! defined $self->{'no_param_checks'} ) { | |
142 $value = 0 unless defined $value; | |
143 $self->{'no_param_checks'} = $value; | |
144 } | |
145 return $self->{'no_param_checks'}; | |
146 } | |
147 | |
148 =head2 save_tempfiles | |
149 | |
150 Title : save_tempfiles | |
151 Usage : $obj->save_tempfiles($newval) | |
152 Function: | |
153 Returns : value of save_tempfiles | |
154 Args : newvalue (optional) | |
155 | |
156 | |
157 =cut | |
158 | |
159 sub save_tempfiles{ | |
160 my ($self,$value) = @_; | |
161 if( defined $value) { | |
162 $self->{'save_tempfiles'} = $value; | |
163 } | |
164 return $self->{'save_tempfiles'}; | |
165 } | |
166 | |
167 =head2 outfile_name | |
168 | |
169 Title : outfile_name | |
170 Usage : my $outfile = $wrapper->outfile_name(); | |
171 Function: Get/Set the name of the output file for this run | |
172 (if you wanted to do something special) | |
173 Returns : string | |
174 Args : [optional] string to set value to | |
175 | |
176 | |
177 =cut | |
178 | |
179 sub outfile_name{ | |
180 my ($self,$nm) = @_; | |
181 if( defined $nm || ! defined $self->{'_outfilename'} ) { | |
182 $nm = 'mlc' unless defined $nm; | |
183 $self->{'_outfilename'} = $nm; | |
184 } | |
185 return $self->{'_outfilename'}; | |
186 } | |
187 | |
188 | |
189 =head2 tempdir | |
190 | |
191 Title : tempdir | |
192 Usage : my $tmpdir = $self->tempdir(); | |
193 Function: Retrieve a temporary directory name (which is created) | |
194 Returns : string which is the name of the temporary directory | |
195 Args : none | |
196 | |
197 | |
198 =cut | |
199 | |
200 sub tempdir{ | |
201 my ($self) = @_; | |
202 | |
203 unless( $self->{'_tmpdir'} ) { | |
204 $self->{'_tmpdir'} = $self->io->tempdir(CLEANUP => ! $self->save_tempfiles ); | |
205 } | |
206 unless( -d $self->{'_tmpdir'} ) { | |
207 mkdir($self->{'_tmpdir'},0777); | |
208 } | |
209 $self->{'_tmpdir'}; | |
210 } | |
211 | |
212 =head2 cleanup | |
213 | |
214 Title : cleanup | |
215 Usage : $wrapper->cleanup(); | |
216 Function: Will cleanup the tempdir directory after a PAML run | |
217 Returns : none | |
218 Args : none | |
219 | |
220 | |
221 =cut | |
222 | |
223 sub cleanup{ | |
224 my ($self) = @_; | |
225 $self->io->_io_cleanup(); | |
226 if( defined $self->{'_tmpdir'} && | |
227 -d $self->{'_tmpdir'} ) { | |
228 $self->io->rmtree($self->{'_tmpdir'}); | |
229 } | |
230 } | |
231 | |
232 =head2 io | |
233 | |
234 Title : io | |
235 Usage : $obj->io($newval) | |
236 Function: Gets a L<Bio::Root::IO> object | |
237 Returns : L<Bio::Root::IO> object | |
238 Args : none | |
239 | |
240 | |
241 =cut | |
242 | |
243 sub io{ | |
244 my ($self) = @_; | |
245 unless( defined $self->{'io'} ) { | |
246 $self->{'io'} = new Bio::Root::IO(-verbose => $self->verbose()); | |
247 } | |
248 return $self->{'io'}; | |
249 } | |
250 | |
251 =head2 version | |
252 | |
253 Title : version | |
254 Usage : $version = $wrapper->version() | |
255 Function: Returns the program version (if available) | |
256 Returns : string representing version of the program | |
257 Args : [Optional] value to (re)set version string | |
258 | |
259 | |
260 =cut | |
261 | |
262 sub version{ | |
263 my ($self,@args) = @_; | |
264 return undef; | |
265 } | |
266 | |
267 =head2 executable | |
268 | |
269 Title : executable | |
270 Usage : my $exe = $factory->executable(); | |
271 Function: Finds the full path to the executable | |
272 Returns : string representing the full path to the exe | |
273 Args : [optional] name of executable to set path to | |
274 [optional] boolean flag whether or not warn when exe is not found | |
275 | |
276 =cut | |
277 | |
278 sub executable{ | |
279 my ($self, $exe,$warn) = @_; | |
280 | |
281 if( defined $exe ) { | |
282 $self->{'_pathtoexe'} = $exe; | |
283 } | |
284 unless( defined $self->{'_pathtoexe'} ) { | |
285 my $prog_path = $self->program_path; | |
286 if( $prog_path && -e $prog_path && -x $prog_path ) { | |
287 $self->{'_pathtoexe'} = $prog_path; | |
288 } else { | |
289 my $exe; | |
290 if( ( $exe = $self->io->exists_exe($self->program_name) ) && | |
291 -x $exe ) { | |
292 $self->{'_pathtoexe'} = $exe; | |
293 } else { | |
294 $self->warn("Cannot find executable for ".$self->program_name) if $warn; | |
295 $self->{'_pathtoexe'} = undef; | |
296 } | |
297 } | |
298 } | |
299 $self->{'_pathtoexe'}; | |
300 } | |
301 | |
302 =head2 program_path | |
303 | |
304 Title : program_path | |
305 Usage : my $path = $factory->program_path(); | |
306 Function: Builds path for executable | |
307 Returns : string representing the full path to the exe | |
308 Args : none | |
309 | |
310 =cut | |
311 | |
312 sub program_path { | |
313 my ($self) = @_; | |
314 my @path; | |
315 push @path, $self->program_dir if $self->program_dir; | |
316 push @path, $self->program_name.($^O =~ /mswin/i ?'.exe':''); | |
317 | |
318 return Bio::Root::IO->catfile(@path); | |
319 } | |
320 | |
321 =head2 program_dir | |
322 | |
323 Title : program_dir | |
324 Usage : my $dir = $factory->program_dir(); | |
325 Function: Abstract get method for dir of program. To be implemented | |
326 by wrapper. | |
327 Returns : string representing program directory | |
328 Args : none | |
329 | |
330 =cut | |
331 | |
332 sub program_dir { | |
333 my ($self) = @_; | |
334 $self->throw_not_implemented(); | |
335 } | |
336 | |
337 =head2 program_name | |
338 | |
339 Title : program_name | |
340 Usage : my $name = $factory->program_name(); | |
341 Function: Abstract get method for name of program. To be implemented | |
342 by wrapper. | |
343 Returns : string representing program name | |
344 Args : none | |
345 | |
346 =cut | |
347 | |
348 sub program_name { | |
349 my ($self) = @_; | |
350 $self->throw_not_implemented(); | |
351 } | |
352 | |
353 | |
354 1; |