Tools/Run/Alignment/Probalign.pm

filter: Statementstmt 33.5% 51 / 152 Branchbran 5.3% 3 / 56 Conditioncond 7.6% 1 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 65.2% 15 / 23 Podpod 100% 8 / 8 totaltotal 30.0% 78 / 260 CC 38 SCAR 44.0
CC
38
Cov
25%
_setinput
240.0
_setparams
110.0
AUTOLOAD
12.0
CRAP 81.3
« Tools/Run/Alignment/MAFFT.pm ↑ Summary Tools/Run/StandAloneBlast.pm »
1 # BioPerl module for Bio::Tools::Run::Alignment::Probalign
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Albert Vilella
6 #
7 #
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::Alignment::Probalign - Object for the calculation of
16 a multiple sequence alignment from a set of unaligned sequences or
17 alignments using the Probalign program
18  
19 =head1 SYNOPSIS
20  
21 # Build a muscle alignment factory
22 $factory = Bio::Tools::Run::Alignment::Probalign->new(@params);
23  
24 # Pass the factory a list of sequences to be aligned.
25 $inputfilename = 't/cysprot.fa';
26 # $aln is a SimpleAlign object.
27 $aln = $factory->align($inputfilename);
28  
29 # or where @seq_array is an array of Bio::Seq objects
30 $seq_array_ref = \@seq_array;
31 $aln = $factory->align($seq_array_ref);
32  
33 # Or one can pass the factory a pair of (sub)alignments
34 #to be aligned against each other, e.g.:
35  
36 #There are various additional options and input formats available.
37 #See the DESCRIPTION section that follows for additional details.
38  
39 $factory = Bio::Tools::Run::Alignment::Probalign->new();
40 $factory->outfile_name("$dir/$subdir/$outdir/outfile.afa");
41 $aln = $factory->align($seq_array_ref);
42  
43 =head1 DESCRIPTION
44  
45  
46 Probalign: multiple sequence alignment using partition function
47 posterior probabilities.
48  
49 Probalign uses partition function posterior probability estimates to
50 compute maximum expected accuracy multiple sequence alignments.
51 You can get it and see information about it at this URL
52 http://www.cs.njit.edu/usman/probalign
53  
54  
55 =head2 Helping the module find your executable
56  
57 You will need to enable Probalign to find the probalign program. This can be
58 done in (at least) three ways:
59  
60 1. Make sure the probalign executable is in your path (i.e.
61 'which probalign' returns a valid program
62 2. define an environmental variable PROBALIGNDIR which points to a
63 directory containing the 'probalign' app:
64 In bash
65 export PROBALIGNDIR=/home/progs/probalign or
66 In csh/tcsh
67 setenv PROBALIGNDIR /home/progs/probalign
68  
69 3. include a definition of an environmental variable PROBALIGNDIR
70 in every script that will
71 BEGIN {$ENV{PROBALIGNDIR} = '/home/progs/probalign'; }
72 use Bio::Tools::Run::Alignment::Probalign;
73  
74  
75 =head1 FEEDBACK
76  
77 =head2 Mailing Lists
78  
79 User feedback is an integral part of the evolution of this and other
80 Bioperl modules. Send your comments and suggestions preferably to one
81 of the Bioperl mailing lists. Your participation is much appreciated.
82  
83 bioperl-l@bioperl.org - General discussion
84 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
85  
86 =head2 Support
87  
88 Please direct usage questions or support issues to the mailing list:
89  
90 I<bioperl-l@bioperl.org>
91  
92 rather than to the module maintainer directly. Many experienced and
93 reponsive experts will be able look at the problem and quickly
94 address it. Please include a thorough description of the problem
95 with code and data examples if at all possible.
96  
97 =head2 Reporting Bugs
98  
99 Report bugs to the Bioperl bug tracking system to help us keep track
100 the bugs and their resolution. Bug reports can be submitted via the web:
101  
102 http://redmine.open-bio.org/projects/bioperl/
103  
104 =head1 AUTHOR - Albert Vilella
105  
106 Email avilella-at-gmail-dot-com
107  
108 =head1 APPENDIX
109  
110 The rest of the documentation details each of the object
111 methods. Internal methods are usually preceded with a _
112  
113 =cut
114  
115 package Bio::Tools::Run::Alignment::Probalign;
116  
117 1 ▶use vars qw($AUTOLOAD @ISA $PROGRAMNAME $PROGRAM %DEFAULTS
Subroutine BEGIN: called CC=1 SCAR=0.0
118 @PROBALIGN_PARAMS @PROBALIGN_SWITCHES @OTHER_SWITCHES
119 %OK_FIELD
120 1 );
121 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 ▶use Bio::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 1 ▶use Bio::SimpleAlign;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 1 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 1 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 1 ▶use Bio::Factory::ApplicationFactoryI;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 1 ▶use Bio::Tools::Run::WrapperBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 1 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase
131 Bio::Factory::ApplicationFactoryI);
132  
133  
134 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
135 1 %DEFAULTS = ( 'AFORMAT' => 'fasta' );
136 1 @PROBALIGN_PARAMS = qw (TEMPERATURE SCORE_MATRIX GAP-OPEN GAP-EXTENSION);
137 1 @PROBALIGN_SWITCHES = qw(CLUSTALW VERBOSE ALIGNMENT-ORDER NUC PROT);
138 1 @OTHER_SWITCHES = qw();
139  
140 # Authorize attribute fields
141 1 foreach my $attr ( @PROBALIGN_PARAMS, @PROBALIGN_SWITCHES, @OTHER_SWITCHES ) {
142 9 $OK_FIELD{$attr}++; }
143 }
144  
145 =head2 program_name
146  
147 Title : program_name
148 Usage : $factory->program_name()
149 Function: holds the program name
150 Returns: string
151 Args : None
152  
153 =cut
154  
155 6 ▶sub program_name {
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
156 6 return 'probalign';
157 }
158  
159 =head2 program_dir
160  
161 Title : program_dir
162 Usage : $factory->program_dir(@params)
163 Function: returns the program directory, obtained from ENV variable.
164 Returns: string
165 Args :
166  
167 =cut
168  
169 3 ▶sub program_dir {
Subroutine program_dir: called CC=2 SCAR=7.6
Pod documented
170 3 ▶ return Bio::Root::IO->catfile($ENV{PROBALIGNDIR}) if $ENV{PROBALIGNDIR};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PROBALIGNDIR"} 0 3 3
171 }
172  
173 =head2 new
174  
175 Title : new
176 Usage : my $probalign = Bio::Tools::Run::Alignment::Probalign->new();
177 Function: Constructor
178 Returns : Bio::Tools::Run::Alignment::Probalign
179 Args : -outfile_name => $outname
180  
181  
182 =cut
183  
184 1 ▶sub new{
Subroutine new: called CC=4 SCAR=16.9
Pod documented
185 1 my ($class,@args) = @_;
186 1 my $self = $class->SUPER::new(@args);
187 1 my ($on) = $self->SUPER::_rearrange([qw(OUTFILE_NAME)], @args);
188 1 ▶ $self->outfile_name($on || '');
Condition50%1/2
$on || ''
l!l
01
MC/DC0%0/1
$on || ''
$on
Truth table50%1/2
A
A= $on
Aresult
11
00
189 1 my ($attr, $value);
190 1 $self->aformat($DEFAULTS{'AFORMAT'});
191  
192 1 ▶ while ( @args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 1 1
193 0 $attr = shift @args;
194 0 $value = shift @args;
195 0 ▶ next if( $attr =~ /^-/); # don't want named parameters
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^-/ 0 0 0
196 0 $self->$attr($value);
197 }
198 1 return $self;
199 }
200  
201 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
202 0 my $self = shift;
203 0 my $attr = $AUTOLOAD;
204 0 $attr =~ s/.*:://;
205 0 $attr = uc $attr;
206 # aliasing
207 0 ▶ $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Tools::Run::Alignment::Probalign::OK_FIELD{$attr} 0 0 0
208  
209 0 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
210 0 return $self->{$attr};
211 }
212  
213 =head2 error_string
214  
215 Title : error_string
216 Usage : $obj->error_string($newval)
217 Function: Where the output from the last analysus run is stored.
218 Returns : value of error_string
219 Args : newvalue (optional)
220  
221  
222 =cut
223  
224 0 ▶sub error_string{
Subroutine error_string: not called CC=2 SCAR=17.9
Pod documented
225 0 my ($self,$value) = @_;
226 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
227 0 $self->{'error_string'} = $value;
228 }
229 0 return $self->{'error_string'};
230  
231 }
232  
233 =head2 version
234  
235 Title : version
236 Usage : exit if $prog->version() < 1.8
237 Function: Determine the version number of the program
238 Example :
239 Returns : float or undef
240 Args : none
241  
242 =cut
243  
244 0 ▶sub version {
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
245 0 my ($self) = @_;
246 0 my $exe;
247 0 ▶ return undef unless $exe = $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $exe = $self->executable 0 0 0
248 0 my $string = `$exe 2>&1` ;
249 #PROBALIGN version 1.09 - align multiple protein sequences and print to standard output
250 0 $string =~ /PROBALIGN\s+Beta\s+Version\s+(\d+\.\d+)/m;
251 0 ▶ return $1 || undef;
Condition0%0/2
$1 || undef
l!l
00
MC/DC0%0/1
$1 || undef
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
252 }
253  
254 =head2 run
255  
256 Title : run
257 Usage : my $output = $application->run(\@seqs);
258 Function: Generic run of an application
259 Returns : Bio::SimpleAlign object
260 Args : Arrayref of Bio::PrimarySeqI objects or
261 a filename to run on
262  
263 =cut
264  
265 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
266 0 my $self = shift;
267 0 return $self->align(shift);
268 }
269  
270 =head2 align
271  
272 Title : align
273 Usage :
274 $inputfilename = 't/data/cysprot.fa';
275 $aln = $factory->align($inputfilename);
276 or
277 $seq_array_ref = \@seq_array;
278 # @seq_array is array of Seq objs
279 $aln = $factory->align($seq_array_ref);
280 Function: Perform a multiple sequence alignment
281 Returns : Reference to a SimpleAlign object containing the
282 sequence alignment.
283 Args : Name of a file containing a set of unaligned fasta sequences
284 or else an array of references to Bio::Seq objects.
285  
286 Throws an exception if argument is not either a string (eg a
287 filename) or a reference to an array of Bio::Seq objects. If
288 argument is string, throws exception if file corresponding to string
289 name can not be found. If argument is Bio::Seq array, throws
290 exception if less than two sequence objects are in array.
291  
292 =cut
293  
294 0 ▶sub align {
Subroutine align: not called CC=2 SCAR=17.9
Pod documented
295 0 my ($self,$input) = @_;
296 # Create input file pointer
297 0 $self->io->_io_cleanup();
298 0 my ($infilename) = $self->_setinput($input);
299 0 ▶ if (! $infilename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($infilename) 0 0 0
300 0 $self->throw("Bad input data or less than 2 sequences in $input !");
301 }
302  
303 0 my $param_string = $self->_setparams();
304  
305 # run probalign
306 0 return &_run($self, $infilename, $param_string);
307 }
308  
309 =head2 _run
310  
311 Title : _run
312 Usage : Internal function, not to be called directly
313 Function: makes actual system call to probalign program
314 Example :
315 Returns : nothing; probalign output is written to a
316 temporary file OR specified output file
317 Args : Name of a file containing a set of unaligned fasta sequences
318 and hash of parameters to be passed to probalign
319  
320  
321 =cut
322  
323 0 ▶sub _run {
Subroutine _run: not called CC=3 SCAR=24.8
324 0 my ($self,$infilename,$params) = @_;
325 0 my $commandstring = $self->executable." $infilename $params";
326  
327 0 $self->debug( "probalign command = $commandstring \n");
328  
329 0 my $status = system($commandstring);
330 0 my $outfile = $self->outfile_name();
331  
332 0 ▶ if( !-e $outfile || -z $outfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $outfile or -z $outfile) 0 0 0
Condition0%0/3
not -e $outfile or -z $outfile
l!l&&r!l&&!r
000
MC/DC0%0/2
not -e $outfile or -z $outfile
not -e $outfile -z $outfile
Truth table0%0/3
not(A) or B
A= not -e $outfileB= -z $outfile
ABresult
1X1
011
000
333 0 $self->warn( "Probalign call crashed: $? [command $commandstring]\n");
334 0 return undef;
335 }
336  
337 0 my $in = Bio::AlignIO->new('-file' => $outfile,
338 '-format' => $self->aformat);
339 0 my $aln = $in->next_aln();
340 0 return $aln;
341 }
342  
343  
344 =head2 _setinput
345  
346 Title : _setinput
347 Usage : Internal function, not to be called directly
348 Function: Create input file for probalign program
349 Example :
350 Returns : name of file containing probalign data input AND
351 Args : Arrayref of Seqs or input file name
352  
353  
354 =cut
355  
356 0 ▶sub _setinput {
Subroutine _setinput: not called CC=15 SCAR=54.8
357 0 my ($self,$input) = @_;
358 0 my ($infilename, $seq, $temp, $tfh);
359 0 ▶ if (! ref $input) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $input) { } 0 0 0
elsif (ref($input) =~ /ARRAY/i) { } 0 0 0
360 # check that file exists or throw
361 0 $infilename = $input;
362 0 ▶ unless (-e $input) {return 0;}
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $input) 0 0 0
363 # let's peek and guess
364 0 ▶ open(IN,$infilename) || $self->throw("Cannot open $infilename");
Branch: 1 branch
BranchTrueFalseTotal
open IN, $infilename or $self->throw("Cannot open $infilename") 0 0 0
365 0 my $header;
366 0 ▶ while( defined ($header = <IN>) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($header = readline IN)) 0 0 0
367 0 ▶ last if $header !~ /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $header =~ /^\s+$/ 0 0 0
368 }
369 0 close(IN);
370 0 ▶ if ( $header !~ /^>\s*\S+/ ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($header =~ /^>\s*\S+/) 0 0 0
371 0 $self->throw("Need to provide a FASTA format file to probalign!");
372 }
373 0 return ($infilename);
374 } elsif (ref($input) =~ /ARRAY/i ) { # $input may be an
375 # array of BioSeq objects...
376 # Open temporary file for both reading & writing of array
377 0 ($tfh,$infilename) = $self->io->tempfile();
378 0 ▶ if( ! ref($input->[0]) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $input->[0]) { } 0 0 0
elsif ($input->[0]->isa('Bio::PrimarySeqI')) { } 0 0 0
379 0 $self->warn("passed an array ref which did not contain objects to _setinput");
380 0 return undef;
381 } elsif( $input->[0]->isa('Bio::PrimarySeqI') ) {
382 0 $temp = Bio::SeqIO->new('-fh' => $tfh,
383 '-format' => 'fasta');
384 0 my $ct = 1;
385 0 foreach $seq (@$input) {
386 0 ▶ return 0 unless ( ref($seq) &&
Branch: 1 branch
BranchTrueFalseTotal
unless ref $seq and $seq->isa("Bio::PrimarySeqI") 0 0 0
Condition0%0/3
ref $seq and $seq->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $seq and $seq->isa("Bio::PrimarySeqI")
ref $seq $seq->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= ref $seqB= $seq->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
387 $seq->isa("Bio::PrimarySeqI") );
388 0 ▶ if( ! defined $seq->display_id ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $seq->display_id or $seq->display_id =~ /^\s+$/) 0 0 0
Condition0%0/3
not defined $seq->display_id or $seq->display_id =~ /^\s+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $seq->display_id or $seq->display_id =~ /^\s+$/
not defined $seq->display_id $seq->display_id =~ /^\s+$/
Truth table0%0/3
not(A) or B
A= not defined $seq->display_idB= $seq->display_id =~ /^\s+$/
ABresult
1X1
011
000
389 $seq->display_id =~ /^\s+$/) {
390 0 $seq->display_id( "Seq".$ct++);
391 }
392 0 $temp->write_seq($seq);
393 }
394 0 $temp->close();
395 0 undef $temp;
396 0 close($tfh);
397 0 $tfh = undef;
398 } else {
399 0 $self->warn( "got an array ref with 1st entry ".
400 $input->[0].
401 " and don't know what to do with it\n");
402 }
403 0 return ($infilename);
404 } else {
405 0 $self->warn("Got $input and don't know what to do with it\n");
406 }
407 0 return 0;
408 }
409  
410  
411 =head2 _setparams
412  
413 Title : _setparams
414 Usage : Internal function, not to be called directly
415 Function: Create parameter inputs for probalign program
416 Example :
417 Returns : parameter string to be passed to probalign
418 during align or profile_align
419 Args : name of calling object
420  
421 =cut
422  
423 0 ▶sub _setparams {
Subroutine _setparams: not called CC=10 SCAR=47.0
424 0 my ($self) = @_;
425 0 my ($attr, $value,$param_string);
426 0 $param_string = '';
427 0 my $laststr;
428 0 for $attr ( @PROBALIGN_PARAMS ) {
429 0 $value = $self->$attr();
430 0 ▶ next unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
431 0 my $attr_key = lc $attr;
432 0 ▶ $attr_key = ' --'.$attr_key unless ($attr eq 'ANNOT');
Branch: 1 branch
BranchTrueFalseTotal
unless $attr eq "ANNOT" 0 0 0
433 0 ▶ $attr_key = ' -'.$attr_key if ($attr eq 'ANNOT');
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "ANNOT" 0 0 0
434 0 $param_string .= $attr_key .' '.$value;
435  
436 }
437 0 for $attr ( @PROBALIGN_SWITCHES) {
438 0 $value = $self->$attr();
439 0 ▶ next unless ($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
440 0 my $attr_key = lc $attr; #put switches in format expected by tcoffee
441 0 $attr_key = ' -'.$attr_key;
442 0 $param_string .= $attr_key ;
443 }
444 # Set default output file if no explicit output file selected
445 0 ▶ unless ($self->outfile_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->outfile_name) 0 0 0
446 0 my ($tfh, $outfile) = $self->io->tempfile(-dir=>$self->tempdir());
447 0 close($tfh);
448 0 undef $tfh;
449 0 $self->outfile_name($outfile);
450 }
451 #FIXME: This may be only for *nixes. Double check in other OSes
452 0 $param_string .= " > ".$self->outfile_name;
453  
454 0 ▶ if ($self->verbose < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose < 0) 0 0 0
455 0 ▶ my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin/i ? : 0 0 0
456 0 $param_string .= " 2> $null";
457 }
458 0 return $param_string;
459 }
460  
461 =head2 aformat
462  
463 Title : aformat
464 Usage : my $alignmentformat = $self->aformat();
465 Function: Get/Set alignment format
466 Returns : string
467 Args : string
468  
469  
470 =cut
471  
472 1 ▶sub aformat{
Subroutine aformat: called CC=2 SCAR=7.1
Pod documented
473 1 my $self = shift;
474 1 ▶ $self->{'_aformat'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
475 1 return $self->{'_aformat'};
476 }
477  
478 =head1 Bio::Tools::Run::BaseWrapper methods
479  
480 =cut
481  
482 =head2 no_param_checks
483  
484 Title : no_param_checks
485 Usage : $obj->no_param_checks($newval)
486 Function: Boolean flag as to whether or not we should
487 trust the sanity checks for parameter values
488 Returns : value of no_param_checks
489 Args : newvalue (optional)
490  
491  
492 =cut
493  
494 =head2 save_tempfiles
495  
496 Title : save_tempfiles
497 Usage : $obj->save_tempfiles($newval)
498 Function:
499 Returns : value of save_tempfiles
500 Args : newvalue (optional)
501  
502  
503 =cut
504  
505 =head2 outfile_name
506  
507 Title : outfile_name
508 Usage : my $outfile = $probalign->outfile_name();
509 Function: Get/Set the name of the output file for this run
510 (if you wanted to do something special)
511 Returns : string
512 Args : [optional] string to set value to
513  
514  
515 =cut
516  
517  
518 =head2 tempdir
519  
520 Title : tempdir
521 Usage : my $tmpdir = $self->tempdir();
522 Function: Retrieve a temporary directory name (which is created)
523 Returns : string which is the name of the temporary directory
524 Args : none
525  
526  
527 =cut
528  
529 =head2 cleanup
530  
531 Title : cleanup
532 Usage : $probalign->cleanup();
533 Function: Will cleanup the tempdir directory
534 Returns : none
535 Args : none
536  
537  
538 =cut
539  
540 =head2 io
541  
542 Title : io
543 Usage : $obj->io($newval)
544 Function: Gets a L<Bio::Root::IO> object
545 Returns : L<Bio::Root::IO>
546 Args : none
547  
548  
549 =cut
550  
551 1 1; # Needed to keep compiler happy
« Tools/Run/Alignment/MAFFT.pm ↑ Summary Tools/Run/StandAloneBlast.pm »