3 # BioPerl module for Bio::Tools::Run::ERPIN
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Chris Fields
9 # Copyright Chris Fields
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::Tools::Run::ERPIN - Wrapper for local execution of the ERPIN suite of
27 # Set up search strategy this way...
28 strategy => [ 'umask' => [1, 2],
29 'umask' => [1, 2, 3, 4],
30 'umask' => [1, 2, 3, 4, 5, 6],
32 'cutoff' => [0, 10, 15, 20]
34 # or use a simple string...
35 #strategy => 'Ðumask 4 Ðadd 5 -nomask -cutoff 0 10 15',
39 my $factory = Bio::Tools::Run::ERPIN->new(-program =>'erpin',
42 # Pass the factory a Bio::Seq object or a file name
43 # Returns a Bio::SearchIO object
45 #my $search = $factory->run("B_sub.fas");
46 my $search = $factory->run($seq);
48 while (my $result = $searchio->next_result){
49 while(my $hit = $result->next_hit){
50 while (my $hsp = $hit->next_hsp){
51 print join("\t", ( $r->query_name,
70 User feedback is an integral part of the evolution of this and other
71 Bioperl modules. Send your comments and suggestions preferably to one
72 of the Bioperl mailing lists. Your participation is much appreciated.
74 bioperl-l@bioperl.org - General discussion
75 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
79 Please direct usage questions or support issues to the mailing list:
81 I<bioperl-l@bioperl.org>
83 rather than to the module maintainer directly. Many experienced and
84 reponsive experts will be able look at the problem and quickly
85 address it. Please include a thorough description of the problem
86 with code and data examples if at all possible.
90 Report bugs to the Bioperl bug tracking system to help us keep track
91 the bugs and their resolution. Bug reports can be submitted via the
94 http://redmine.open-bio.org/projects/bioperl/
96 =head1 AUTHOR - Chris Fields
98 Email: cjfields-at-uiuc-dot-edu
102 cjfields-at-uiuc-dot-edu
106 The rest of the documentation details each of the object
107 methods. Internal methods are usually preceded with a _
111 package Bio
::Tools
::Run
::ERPIN
;
118 use Bio
::Tools
::Run
::WrapperBase
;
120 use base
qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
122 # will move parameters to each program, use this for _set_params
138 my %ERPIN_SWITCHES = map {$_ => 1} qw(dmp smp fwd rev fwd+rev long short mute
139 warnings globstat locstat unifstat Eon Eoff hist chrono);
141 # order is important here
142 my @ERPIN_PARAMS=qw(program model file strategy dmp smp fwd rev fwd+rev long
143 short mute warnings globstat locstat unifstat Eon Eoff hist seq1 nseq bgn
144 len logzero tablen chrono pcw hpcw spcw sumf tset);
149 Usage : my $wrapper = Bio::Tools::Run::RNAMotif->new(@params)
150 Function: creates a new RNAMotif factory
151 Returns: Bio::Tools::Run::RNAMotif
152 Args : list of parameters
153 -tempfile => set tempfile flag (default 0)
154 -outfile_name => set file to send output to (default none)
159 my ($class,@args) = @_;
160 my $self = $class->SUPER::new
(@args);
161 my ($out, $tf) = $self->_rearrange([qw(OUTFILE_NAME TEMPFILE)], @args);
162 $self->io->_initialize_io();
164 my ($tfh, $outfile) = $self->io->tempfile(-dir
=>$self->tempdir());
167 $self->outfile_name($outfile);
170 $self->outfile_name($out);
172 $tf && $self->tempfile($tf);
173 $self->_set_from_args(\
@args,
174 -methods
=> [@ERPIN_PARAMS],
183 Usage : $factory>program_name()
184 Function: holds the program name
192 return $self->program(@_);
198 Usage : $factory->program_dir(@params)
199 Function: returns the program directory, obtained from ENV variable.
206 return Bio
::Root
::IO
->catfile($ENV{ERPINDIR
}) if $ENV{ERPINDIR
};
212 Usage : $v = $prog->version();
213 Function: Determine the version number of the program
215 Returns : float or undef
222 return undef unless $self->executable;
223 my $string = `erpin -h 2>&1`;
225 if ($string =~ m{Version\s([\d.]+)}) {
228 return $self->{'_progversion'} = $v || $string;
234 Usage : $obj->run($seqFile)
235 Function: Runs ERPIN programs and returns Bio::SearchIO
237 Args : Must pass Bio::PrimarySeqI's or file names
242 my ($self,@seq) = @_;
243 $self->throw ("Must define 'db', pass a file name, or a list of Bio::PrimarySeqI objects")
245 if (ref $seq[0] && $seq[0]->isa("Bio::PrimarySeqI") ){# it is an object
246 my $infile1 = $self->_writeSeqFile(@seq);
247 return $self->_run($infile1);
249 return $self->_run(@seq);
256 Usage : $obj->tempfile(1)
257 Function: Set tempfile flag. When set, writes output to a tempfile; this
258 is overridden by outfile_name() if set
259 Returns : Boolean setting (or undef if not set)
260 Args : [OPTIONAL] Boolean
266 return $self->{'_tempfile'} = shift if @_;
267 return $self->{'_tempfile'};
274 Function: Internal(not to be used directly)
281 my ($self,$file,$prog) = @_;
282 return unless $self->executable;
283 $self->io->_io_cleanup();
284 my ($str, $progname, $outfile) =
285 ($prog || $self->executable, $self->program_name, $self->outfile_name);
286 my $param_str = $self->_setparams($file);
287 $str .= " $param_str";
288 $self->debug("ERPIN command: $str\n");
290 # rnamotif => SearchIO object
291 # rmfmt -a => AlignIO object
292 # all others sent to outfile, tempfile, or STDERR (upon verbose = 1)
294 my $obj = ($progname eq 'erpin') ?
295 Bio
::SearchIO
->new(-verbose
=> $self->verbose,
297 -version
=> $self->version,
305 local $SIG{CHLD
} = 'DEFAULT';
306 my $status = system($str);
307 if($status || !-e
$outfile || -z
$outfile ) {
308 my $error = ($!) ?
"$! Status: $status" : "Status: $status";
309 $self->throw( "ERPIN call crashed: $error \n[command $str]\n");
312 if ($obj && ref($obj)) {
313 $obj->file($outfile);
314 @args = (-file
=> $outfile);
318 open(my $fh,"$str |") || $self->throw("ERPIN call ($str) crashed: $?\n");
319 if ($obj && ref($obj)) {
321 @args = (-fh
=> $fh);
325 while(<$fh>) {$io .= $_;}
331 # initialize SearchIO/AlignIO...um...IO
332 # (since file/fh set post obj construction)
333 $obj->_initialize_io(@args) if $obj && ref($obj);
340 Usage : Internal function, not to be called directly
341 Function: creates a string of params to be used in the command string
343 Returns : string of params
349 my ($self, $file) = @_;
350 my $progname = $self->program_name;
352 $self->throw("Unknown program: $progname") if
353 (!exists $ERPIN_PROGS{$progname} );
356 my $outfile = ($self->outfile_name) ?
' > '.$self->outfile_name : '';
357 my ($tset, $st) = ($self->tset, $self->strategy);
359 $param_string = join " ", ($tset, $file, $st);
360 $self->debug("String : $param_string\n");
362 $self->throw("Must have both a training set and search strategy defined!")
363 if (!defined($tset) || !defined ($st));
366 foreach my $attr (@ERPIN_PARAMS) {
367 next if $attr eq 'program' || $attr eq 'tset' || $attr eq 'strategy';
368 my $value = $self->$attr();
369 next unless ($attr eq 'file' || defined $value);
370 my $attr_key = '-'.$attr;
371 if (exists $ERPIN_SWITCHES{$attr}) {
372 push @params, $attr_key;
374 if ($attr eq 'file') {
377 push @params, $attr_key.' '.$value;
382 $param_string .= ' '.join ' ', @params;
383 $param_string .= $outfile if $outfile;
385 return $param_string;
390 Title : _writeSeqFile
391 Usage : obj->_writeSeqFile($seq)
392 Function: Internal(not to be used directly)
393 Returns : writes passed Seq objects to tempfile, to be used as input
400 my ($self,@seq) = @_;
401 my ($tfh,$inputfile) = $self->io->tempfile(-dir
=>$self->tempdir);
402 my $in = Bio
::SeqIO
->new(-fh
=> $tfh , '-format' => 'fasta');