blib/lib/Bio/Tools/Run/Alignment/Clustalw.pm

filter: Statementstmt 16.0% 36 / 224 Branchbran 0.0% 0 / 90 Conditioncond 2.6% 1 / 38 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 50.0% 11 / 22 Podpod 100% 10 / 10 totaltotal 14.2% 58 / 406 CC 63 SCAR 53.8
CC
63
Cov
11%
_run
600.0
_setinput
182.0
footprint
90.0
CRAP 216.9
« blib/lib/Bio/Tools/Run/Alignment/TCoffee.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Lagan.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Alignment::Clustalw
4 #
5 # You may distribute this module under the same terms as perl itself
6 # POD documentation - main docs before the code
7  
8 =head1 NAME
9  
10 Bio::Tools::Run::Alignment::Clustalw - Object for the calculation of a
11 multiple sequence alignment from a set of unaligned sequences or
12 alignments using the Clustalw program
13  
14 =head1 SYNOPSIS
15  
16 # Build a clustalw alignment factory
17 @params = ('ktuple' => 2, 'matrix' => 'BLOSUM');
18 $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
19  
20 # Pass the factory a list of sequences to be aligned.
21 $inputfilename = 't/data/cysprot.fa';
22 $aln = $factory->align($inputfilename); # $aln is a SimpleAlign object.
23 # or
24 $seq_array_ref = \@seq_array;
25 # where @seq_array is an array of Bio::Seq objects
26 $aln = $factory->align($seq_array_ref);
27  
28 # Or one can pass the factory a pair of (sub)alignments
29 #to be aligned against each other, e.g.:
30 $aln = $factory->profile_align($aln1,$aln2);
31 # where $aln1 and $aln2 are Bio::SimpleAlign objects.
32  
33 # Or one can pass the factory an alignment and one or more unaligned
34 # sequences to be added to the alignment. For example:
35 $aln = $factory->profile_align($aln1,$seq); # $seq is a Bio::Seq object.
36  
37 # Get a tree of the sequences
38 $tree = $factory->tree(\@seq_array);
39  
40 # Get both an alignment and a tree
41 ($aln, $tree) = $factory->run(\@seq_array);
42  
43 # Do a footprinting analysis on the supplied sequences, getting back the
44 # most conserved sub-alignments
45 my @results = $factory->footprint(\@seq_array);
46 foreach my $result (@results) {
47 print $result->consensus_string, "\n";
48 }
49  
50 # There are various additional options and input formats available.
51 # See the DESCRIPTION section that follows for additional details.
52  
53 =head1 DESCRIPTION
54  
55 Note: this DESCRIPTION only documents the Bioperl interface to
56 Clustalw. Clustalw, itself, is a large & complex program - for more
57 information regarding clustalw, please see the clustalw documentation
58 which accompanies the clustalw distribution. Clustalw is available
59 from (among others) ftp://ftp.ebi.ac.uk/pub/software/. Clustalw.pm has
60 only been tested using version 1.8 of clustalw. Compatibility with
61 earlier versions of the clustalw program is currently unknown. Before
62 running Clustalw successfully it will be necessary: to install clustalw
63 on your system, and to ensure that users have execute privileges for
64 the clustalw program.
65  
66 =head2 Helping the module find your executable
67  
68 You will need to enable Clustalw to find the clustalw program. This
69 can be done in (at least) three ways:
70  
71 1. Make sure the clustalw executable is in your path so that
72 which clustalw
73 returns a clustalw executable on your system.
74  
75 2. Define an environmental variable CLUSTALDIR which is a
76 directory which contains the 'clustalw' application:
77 In bash:
78  
79 export CLUSTALDIR=/home/username/clustalw1.8
80  
81 In csh/tcsh:
82  
83 setenv CLUSTALDIR /home/username/clustalw1.8
84  
85 3. Include a definition of an environmental variable CLUSTALDIR in
86 every script that will use this Clustalw wrapper module, e.g.:
87  
88 BEGIN { $ENV{CLUSTALDIR} = '/home/username/clustalw1.8/' }
89 use Bio::Tools::Run::Alignment::Clustalw;
90  
91 If you are running an application on a webserver make sure the
92 webserver environment has the proper PATH set or use the options 2 or
93 3 to set the variables.
94  
95 =head2 How it works
96  
97 Bio::Tools::Run::Alignment::Clustalw is an object for performing a
98 multiple sequence alignment from a set of unaligned sequences and/or
99 sub-alignments by means of the clustalw program.
100  
101 Initially, a clustalw "factory object" is created. Optionally, the
102 factory may be passed most of the parameters or switches of the
103 clustalw program, e.g.:
104  
105 @params = ('ktuple' => 2, 'matrix' => 'BLOSUM');
106 $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
107  
108 Any parameters not explicitly set will remain as the defaults of the
109 clustalw program. Additional parameters and switches (not available
110 in clustalw) may also be set. Currently, the only such parameter is
111 "quiet", which when set to a non-zero value, suppresses clustalw
112 terminal output. Not all clustalw parameters are supported at this
113 stage.
114  
115 By default, Clustalw output is returned solely in a the form of a
116 Bio::SimpleAlign object which can then be printed and/or saved
117 in multiple formats using the AlignIO.pm module. Optionally the raw
118 clustalw output file can be saved if the calling script specifies an
119 output file (with the clustalw parameter OUTFILE). Currently only the
120 GCG-MSF output file formats is supported.
121  
122 Not all parameters and features have been implemented yet in Perl format.
123  
124 Alignment parameters can be changed and/or examined at any time after
125 the factory has been created. The program checks that any
126 parameter/switch being set/read is valid. However, currently no
127 additional checks are included to check that parameters are of the
128 proper type (eg string or numeric) or that their values are within the
129 proper range. As an example, to change the value of the clustalw
130 parameter ktuple to 3 and subsequently to check its value one would
131 write:
132  
133 $ktuple = 3;
134 $factory->ktuple($ktuple);
135 $get_ktuple = $factory->ktuple();
136  
137 Once the factory has been created and the appropriate parameters set,
138 one can call the method align() to align a set of unaligned sequences,
139 or call profile_align() to add one or more sequences or a second
140 alignment to an initial alignment.
141  
142 Input to align() may consist of a set of unaligned sequences in the
143 form of the name of file containing the sequences. For example,
144  
145 $inputfilename = 't/data/cysprot.fa';
146 $aln = $factory-E<gt>align($inputfilename);
147  
148 Alternately one can create an array of Bio::Seq objects somehow
149  
150 $str = Bio::SeqIO->new(-file=> 't/data/cysprot.fa', -format => 'Fasta');
151 @seq_array =();
152 while ( my $seq = $str->next_seq() ) {push (@seq_array, $seq) ;}
153  
154 and pass the factory a reference to that array
155  
156 $seq_array_ref = \@seq_array;
157 $aln = $factory->align($seq_array_ref);
158  
159 In either case, align() returns a reference to a SimpleAlign object
160 which can then used (see L<Bio::SimpleAlign>).
161  
162 Once an initial alignment exists, one can pass the factory additional
163 sequence(s) to be added (ie aligned) to the original alignment. The
164 alignment can be passed as either an alignment file or a
165 Bio:SimpleAlign object. The unaligned sequence(s) can be passed as a
166 filename or as an array of BioPerl sequence objects or as a single
167 BioPerl Seq object. For example (to add a single sequence to an
168 alignment),
169  
170 $str = Bio::AlignIO->new(-file=> 't/data/cysprot1a.msf');
171 $aln = $str->next_aln();
172 $str1 = Bio::SeqIO->new(-file=> 't/data/cysprot1b.fa');
173 $seq = $str1->next_seq();
174 $aln = $factory->profile_align($aln,$seq);
175  
176 In either case, profile_align() returns a reference to a SimpleAlign
177 object containing a new SimpleAlign object of the alignment with the
178 additional sequence(s) added in.
179  
180 Finally one can pass the factory a pair of (sub)alignments to be
181 aligned against each other. The alignments can be passed in the form
182 of either a pair of alignment files or a pair of Bio:SimpleAlign
183 objects. For example,
184  
185 $profile1 = 't/data/cysprot1a.msf';
186 $profile2 = 't/data/cysprot1b.msf';
187 $aln = $factory->profile_align($profile1,$profile2);
188  
189 or
190  
191 $str1 = Bio::AlignIO->new(-file=> 't/data/cysprot1a.msf');
192 $aln1 = $str1->next_aln();
193 $str2 = Bio::AlignIO->new(-file=> 't/data/cysprot1b.msf');
194 $aln2 = $str2->next_aln();
195 $aln = $factory->profile_align($aln1,$aln2);
196  
197 In either case, profile_align() returns a reference to a SimpleAlign
198 object containing an (super)alignment of the two input alignments.
199  
200 For more examples of syntax and use of Clustalw, the user is
201 encouraged to look at the script Clustalw.t in the t/ directory.
202  
203 Note: Clustalw is still under development. Various features of the
204 clustalw program have not yet been implemented. If you would like
205 that a specific clustalw feature be added to this perl contact
206 bioperl-l@bioperl.org.
207  
208 These can be specified as paramters when instantiating a new Clustalw
209 object, or through get/set methods of the same name (lowercase).
210  
211 =head1 PARAMETER FOR ALIGNMENT COMPUTATION
212  
213 =head2 KTUPLE
214  
215 Title : KTUPLE
216 Description : (optional) set the word size to be used in the alignment
217 This is the size of exactly matching fragment that is used.
218 INCREASE for speed (max= 2 for proteins; 4 for DNA),
219 DECREASE for sensitivity.
220 For longer sequences (e.g. >1000 residues) you may
221 need to increase the default
222  
223 =head2 TOPDIAGS
224  
225 Title : TOPDIAGS
226 Description : (optional) number of best diagonals to use
227 The number of k-tuple matches on each diagonal
228 (in an imaginary dot-matrix plot) is calculated.
229 Only the best ones (with most matches) are used in
230 the alignment. This parameter specifies how many.
231 Decrease for speed; increase for sensitivity.
232  
233 =head2 WINDOW
234  
235 Title : WINDOW
236 Description : (optional) window size
237 This is the number of diagonals around each of the 'best'
238 diagonals that will be used. Decrease for speed;
239 increase for sensitivity.
240  
241 =head2 PAIRGAP
242  
243 Title : PAIRGAP
244 Description : (optional) gap penalty for pairwise alignments
245 This is a penalty for each gap in the fast alignments.
246 It has little affect on the speed or sensitivity except
247 for extreme values.
248  
249 =head2 FIXEDGAP
250  
251 Title : FIXEDGAP
252 Description : (optional) fixed length gap penalty
253  
254 =head2 FLOATGAP
255  
256 Title : FLOATGAP
257 Description : (optional) variable length gap penalty
258  
259 =head2 MATRIX
260  
261 Title : MATRIX
262 Default : PAM100 for DNA - PAM250 for protein alignment
263 Description : (optional) substitution matrix used in the multiple
264 alignments. Depends on the version of clustalw as to
265 what default matrix will be used
266  
267 PROTEIN WEIGHT MATRIX leads to a new menu where you are
268 offered a choice of weight matrices. The default for
269 proteins in version 1.8 is the PAM series derived by
270 Gonnet and colleagues. Note, a series is used! The
271 actual matrix that is used depends on how similar the
272 sequences to be aligned at this alignment step
273 are. Different matrices work differently at each
274 evolutionary distance.
275  
276 DNA WEIGHT MATRIX leads to a new menu where a single
277 matrix (not a series) can be selected. The default is
278 the matrix used by BESTFIT for comparison of nucleic
279 acid sequences.
280  
281 =head2 TYPE
282  
283 Title : TYPE
284 Description : (optional) sequence type: protein or DNA. This allows
285 you to explicitly overide the programs attempt at
286 guessing the type of the sequence. It is only useful
287 if you are using sequences with a VERY strange
288 composition.
289  
290 =head2 OUTPUT
291  
292 Title : OUTPUT
293 Description : (optional) clustalw supports GCG or PHYLIP or PIR or
294 Clustal format. See the Bio::AlignIO modules for
295 which formats are supported by bioperl.
296  
297 =head2 OUTFILE
298  
299 Title : OUTFILE
300 Description : (optional) Name of clustalw output file. If not set
301 module will erase output file. In any case alignment will
302 be returned in the form of SimpleAlign objects
303  
304 =head2 TRANSMIT
305  
306 Title : TRANSMIT
307 Description : (optional) transitions not weighted. The default is to
308 weight transitions as more favourable than other
309 mismatches in DNA alignments. This switch makes all
310 nucleotide mismatches equally weighted.
311  
312 =head1 FEEDBACK
313  
314 =head2 Mailing Lists
315  
316 User feedback is an integral part of the evolution of this and other
317 Bioperl modules. Send your comments and suggestions preferably to one
318 of the Bioperl mailing lists. Your participation is much appreciated.
319  
320 bioperl-l@bioperl.org - General discussion
321 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
322  
323 =head2 Support
324  
325 Please direct usage questions or support issues to the mailing list:
326  
327 I<bioperl-l@bioperl.org>
328  
329 rather than to the module maintainer directly. Many experienced and
330 reponsive experts will be able look at the problem and quickly
331 address it. Please include a thorough description of the problem
332 with code and data examples if at all possible.
333  
334 =head2 Reporting Bugs
335  
336 Report bugs to the Bioperl bug tracking system to help us keep track
337 the bugs and their resolution. Bug reports can be submitted via the
338 web:
339  
340 http://redmine.open-bio.org/projects/bioperl/
341  
342 =head1 AUTHOR - Peter Schattner
343  
344 Email schattner@alum.mit.edu
345  
346 =head1 CONTRIBUTORS
347  
348 Jason Stajich jason-AT-bioperl_DOT_org
349 Sendu Bala bix@sendu.me.uk
350  
351 =head1 APPENDIX
352  
353 The rest of the documentation details each of the object
354 methods. Internal methods are usually preceded with a _
355  
356 =cut
357  
358 #'
359  
360 package Bio::Tools::Run::Alignment::Clustalw;
361  
362 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
363 3 ▶use Bio::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
364 3 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
365 3 ▶use Bio::SimpleAlign;
Subroutine BEGIN: called CC=1 SCAR=0.0
366 3 ▶use Bio::AlignIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
367 3 ▶use Bio::TreeIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
368 3 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
369  
370 3 ▶use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
371  
372 3 our @CLUSTALW_PARAMS = qw(output ktuple topdiags window pairgap fixedgap
373 floatgap matrix type transit dnamatrix outfile
374 gapopen gapext maxdiv gapdist hgapresidues pwmatrix
375 pwdnamatrix pwgapopen pwgapext score transweight
376 seed helixgap outorder strandgap loopgap terminalgap
377 helixendin helixendout strandendin strandendout program
378 reps outputtree seed bootlabels bootstrap);
379  
380 3 our @CLUSTALW_SWITCHES = qw(help check options negative noweights endgaps
381 nopgap nohgap novgap kimura tossgaps
382 kimura tossgaps njtree);
383 3 our @OTHER_SWITCHES = qw(quiet);
384 3 our $PROGRAM_NAME = 'clustalw';
385 3 ▶our $PROGRAM_DIR = $ENV{'CLUSTALDIR'} || $ENV{'CLUSTALWDIR'};
Condition33%1/3
$ENV{'CLUSTALDIR'} || $ENV{'CLUSTALWDIR'}
l!l&&r!l&&!r
003
MC/DC0%0/2
$ENV{'CLUSTALDIR'} || $ENV{'CLUSTALWDIR'}
$ENV{'CLUSTALDIR'} $ENV{'CLUSTALWDIR'}
Truth table33%1/3
A || B
A= $ENV{'CLUSTALDIR'}B= $ENV{'CLUSTALWDIR'}
ABresult
1X1
011
000
386  
387  
388 =head2 program_name
389  
390 Title : program_name
391 Usage : $factory>program_name()
392 Function: holds the program name
393 Returns: string
394 Args : None
395  
396 =cut
397  
398 sub program_name {
399 7 ▶ return $PROGRAM_NAME;
Subroutine program_name: called CC=1 SCAR=0.0
Pod documented
400 }
401  
402 =head2 program_dir
403  
404 Title : program_dir
405 Usage : $factory->program_dir(@params)
406 Function: returns the program directory, obtained from ENV variable.
407 Returns: string
408 Args :
409  
410 =cut
411  
412 sub program_dir {
413 4 ▶ return $PROGRAM_DIR;
Subroutine program_dir: called CC=1 SCAR=0.0
Pod documented
414 }
415  
416 sub new {
417 1 ▶ my ($class,@args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
418 1 my $self = $class->SUPER::new(@args);
419  
420 1 $self->_set_from_args(\@args, -methods => [@CLUSTALW_PARAMS,
421 @CLUSTALW_SWITCHES,
422 @OTHER_SWITCHES],
423 -create => 1);
424
425 1 return $self;
426 }
427  
428 =head2 version
429  
430 Title : version
431 Usage : exit if $prog->version() < 1.8
432 Function: Determine the version number of the program
433 Example :
434 Returns : float or undef
435 Args : none
436  
437 =cut
438  
439 sub version {
440 0 ▶ my ($self) = @_;
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
441  
442 0 ▶ return undef unless $self->executable;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->executable 0 0 0
443 0 my $prog = $self->executable;
444 0 my $string = `$prog -- 2>&1` ;
445 0 $string =~ /\(?([\d.]+)\)?/xms;
446 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
447 }
448  
449 =head2 run
450  
451 Title : run
452 Usage : ($aln, $tree) = $factory->run($inputfilename);
453 ($aln, $tree) = $factory->run($seq_array_ref);
454 Function: Perform a multiple sequence alignment, generating a tree at the same
455 time. (Like align() and tree() combined.)
456 Returns : A SimpleAlign object containing the sequence alignment and a
457 Bio::Tree::Tree object with the tree relating the sequences.
458 Args : Name of a file containing a set of unaligned fasta sequences
459 or else an array of references to Bio::Seq objects.
460  
461 =cut
462  
463 sub run {
464 0 ▶ my ($self,$input) = @_;
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
465 0 my ($temp,$infilename, $seq);
466 0 my ($attr, $value, $switch);
467
468 0 $self->io->_io_cleanup();
469 # Create input file pointer
470 0 $infilename = $self->_setinput($input);
471 0 ▶ $self->throw("Bad input data (sequences need an id) or less than 2 sequences in $input!") unless $infilename;
Branch: 1 branch
BranchTrueFalseTotal
unless $infilename 0 0 0
472
473 # Create parameter string to pass to clustalw program
474 0 my $param_string = $self->_setparams();
475
476 # run clustalw
477 0 return $self->_run('both', $infilename, $param_string);
478 }
479  
480 =head2 align
481  
482 Title : align
483 Usage : $inputfilename = 't/data/cysprot.fa';
484 $aln = $factory->align($inputfilename);
485 or
486 $seq_array_ref = \@seq_array; # @seq_array is array of Seq objs
487 $aln = $factory->align($seq_array_ref);
488 Function: Perform a multiple sequence alignment
489 Returns : Reference to a SimpleAlign object containing the
490 sequence alignment.
491 Args : Name of a file containing a set of unaligned fasta sequences
492 or else an array of references to Bio::Seq objects.
493  
494 Throws an exception if argument is not either a string (eg a
495 filename) or a reference to an array of Bio::Seq objects. If
496 argument is string, throws exception if file corresponding to string
497 name can not be found. If argument is Bio::Seq array, throws
498 exception if less than two sequence objects are in array.
499  
500 =cut
501  
502 sub align {
503 0 ▶ my ($self,$input) = @_;
Subroutine align: not called CC=2 SCAR=17.9
Pod documented
504
505 0 $self->io->_io_cleanup();
506
507 # Create input file pointer
508 0 my $infilename = $self->_setinput($input);
509 0 ▶ $self->throw("Bad input data (sequences need an id ) or less than 2 sequences in $input !") unless $infilename;
Branch: 1 branch
BranchTrueFalseTotal
unless $infilename 0 0 0
510
511 # Create parameter string to pass to clustalw program
512 0 my $param_string = $self->_setparams();
513
514 # run clustalw
515 0 my $aln = $self->_run('align', $infilename, $param_string);
516 }
517  
518  
519 =head2 profile_align
520  
521 Title : profile_align
522 Usage : $aln = $factory->profile_align(@simple_aligns);
523 or
524 $aln = $factory->profile_align(@subalignment_filenames);
525 Function: Perform an alignment of 2 (sub)alignments
526 Returns : Reference to a SimpleAlign object containing the (super)alignment.
527 Args : Names of 2 files containing the subalignments
528 or references to 2 Bio::SimpleAlign objects.
529  
530 Throws an exception if arguments are not either strings (eg filenames)
531 or references to SimpleAlign objects.
532  
533 =cut
534  
535 sub profile_align {
536 0 ▶ my ($self,$input1,$input2) = @_;
Subroutine profile_align: not called CC=5 SCAR=34.0
Pod documented
537
538 0 $self->io->_io_cleanup();
539
540 # Create input file pointer
541 0 my $infilename1 = $self->_setinput($input1, 1);
542 0 my $infilename2 = $self->_setinput($input2, 2);
543 0 ▶ if (!$infilename1 || !$infilename2) {$self->throw("Bad input data: $input1 or $input2 !");}
Branch: 1 branch
BranchTrueFalseTotal
unless ($infilename1 and $infilename2) 0 0 0
Condition0%0/3
$infilename1 and $infilename2
!ll&&!rl&&r
000
MC/DC0%0/2
$infilename1 and $infilename2
$infilename1 $infilename2
Truth table0%0/3
A and B
A= $infilename1B= $infilename2
ABresult
0X0
100
111
544 0 ▶ unless ( -e $infilename1 and -e $infilename2) {$self->throw("Bad input file: $input1 or $input2 !");}
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $infilename1 and -e $infilename2) 0 0 0
Condition0%0/3
-e $infilename1 and -e $infilename2
!ll&&!rl&&r
000
MC/DC0%0/2
-e $infilename1 and -e $infilename2
-e $infilename1 -e $infilename2
Truth table0%0/3
A and B
A= -e $infilename1B= -e $infilename2
ABresult
0X0
100
111
545
546 # Create parameter string to pass to clustalw program
547 0 my $param_string = $self->_setparams();
548
549 # run clustalw
550 0 my $aln = $self->_run('profile-aln', $infilename1, $infilename2, $param_string);
551 }
552  
553 =head2 add_sequences
554  
555 Title : add_sequences
556 Usage :
557 Function: Align and add sequences into an alignment
558 Example :
559 Returns : Reference to a SimpleAlign object containing the (super)alignment.
560 Args : Names of 2 files, the first one containing an alignment and the second one containing sequences to be added
561 or references to 2 Bio::SimpleAlign objects.
562  
563 Throws an exception if arguments are not either strings (eg filenames)
564 or references to SimpleAlign objects.
565  
566  
567 =cut
568  
569 sub add_sequences {
570  
571 0 ▶ my ($self,$input1,$input2) = @_;
Subroutine add_sequences: not called CC=5 SCAR=34.0
Pod documented
572 0 my ($temp,$infilename1,$infilename2,$input,$seq);
573
574 0 $self->io->_io_cleanup();
575 # Create input file pointer
576 0 $infilename1 = $self->_setinput($input1,1);
577 0 $infilename2 = $self->_setinput($input2,2);
578 0 ▶ if (!$infilename1 || !$infilename2) {$self->throw("Bad input data: $input1 or $input2 !");}
Branch: 1 branch
BranchTrueFalseTotal
unless ($infilename1 and $infilename2) 0 0 0
Condition0%0/3
$infilename1 and $infilename2
!ll&&!rl&&r
000
MC/DC0%0/2
$infilename1 and $infilename2
$infilename1 $infilename2
Truth table0%0/3
A and B
A= $infilename1B= $infilename2
ABresult
0X0
100
111
579 0 ▶ unless ( -e $infilename1 and -e $infilename2) {$self->throw("Bad input file: $input1 or $input2 !");}
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $infilename1 and -e $infilename2) 0 0 0
Condition0%0/3
-e $infilename1 and -e $infilename2
!ll&&!rl&&r
000
MC/DC0%0/2
-e $infilename1 and -e $infilename2
-e $infilename1 -e $infilename2
Truth table0%0/3
A and B
A= -e $infilename1B= -e $infilename2
ABresult
0X0
100
111
580
581
582 # Create parameter string to pass to clustalw program
583 0 my $param_string = $self->_setparams();
584 # run clustalw
585 0 my $aln = $self->_run('add_sequences', $infilename1,
586 $infilename2, $param_string);
587  
588 }
589  
590 =head2 tree
591  
592 Title : tree
593 Usage : @params = ('bootstrap' => 1000,
594 'tossgaps' => 1,
595 'kimura' => 1,
596 'seed' => 121,
597 'bootlabels'=> 'nodes',
598 'quiet' => 1);
599 $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
600 $tree_obj = $factory->tree($aln_obj);
601 or
602 $tree_obj = $factory->tree($treefilename);
603 Function: Retrieve a tree corresponding to the input
604 Returns : Bio::TreeIO object
605 Args : Bio::SimpleAlign or filename of a tree
606  
607 =cut
608  
609 sub tree {
610 0 ▶ my ($self,$input) = @_;
Subroutine tree: not called CC=2 SCAR=17.9
Pod documented
611
612 0 $self->io->_io_cleanup();
613
614 # Create input file pointer
615 0 my $infilename = $self->_setinput($input);
616
617 0 ▶ if (!$infilename) {$self->throw("Bad input data (sequences need an id ) or less than 2 sequences in $input !");}
Branch: 1 branch
BranchTrueFalseTotal
unless ($infilename) 0 0 0
618
619 # Create parameter string to pass to clustalw program
620 0 my $param_string = $self->_setparams();
621  
622 # run clustalw
623 0 my $tree = $self->_run('tree', $infilename, $param_string);
624 }
625  
626 =head2 footprint
627  
628 Title : footprint
629 Usage : @alns = $factory->footprint($treefilename, $window_size, $diff);
630 @alns = $factory->footprint($seqs_array_ref);
631 Function: Aligns all the supplied sequences and slices out of the alignment
632 those regions along a sliding window who's tree length differs
633 significantly from the total average tree length.
634 Returns : list of Bio::SimpleAlign objects
635 Args : first argument as per run(), optional second argument to specify
636 the size of the sliding window (default 5 bp) and optional third
637 argument to specify the % difference from the total tree length
638 needed for a window to be considered a footprint (default 33%).
639  
640 =cut
641  
642 sub footprint {
643 0 ▶ my ($self, $in, $slice_size, $deviate) = @_;
Subroutine footprint: not called CC=9 SCAR=45.0
Pod documented
644
645 0 my ($simplealn, $tree) = $self->run($in);
646
647 # total tree length?
648 0 my $total_length = $tree->total_branch_length;
649
650 # tree length along sliding window, picking regions that significantly
651 # deviate from the average tree length
652 0 ▶ $slice_size ||= 5;
Condition0%0/2
$slice_size ||= 5
l!l
00
MC/DC0%0/1
$slice_size ||= 5
$slice_size
Truth table0%0/2
A
A= $slice_size
Aresult
11
00
653 0 ▶ $deviate ||= 33;
Condition0%0/2
$deviate ||= 33
l!l
00
MC/DC0%0/1
$deviate ||= 33
$deviate
Truth table0%0/2
A
A= $deviate
Aresult
11
00
654 0 my $threshold = $total_length - (($total_length / 100) * $deviate);
655 0 my $length = $simplealn->length;
656 0 my $below = 0;
657 0 my $found_minima = 0;
658 0 my $minima = [$threshold, ''];
659 0 my @results;
660 0 for my $i (1..($length - $slice_size + 1)) {
661 0 my $slice = $simplealn->slice($i, ($i + $slice_size - 1), 1);
662 0 my $tree = $self->tree($slice);
663 0 ▶ $self->throw("No tree returned") unless defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tree 0 0 0
664 0 my $slice_length = $tree->total_branch_length;
665
666 0 ▶ $slice_length <= $threshold ? ($below = 1) : ($below = 0);
Branch: 1 branch
BranchTrueFalseTotal
$slice_length <= $threshold ? : 0 0 0
667 0 ▶ if ($below) {
Branch: 1 branch
BranchTrueFalseTotal
if ($below) { } 0 0 0
668 0 ▶ unless ($found_minima) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found_minima) 0 0 0
669 0 ▶ if ($slice_length < ${$minima}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slice_length < do { $minima }->[0]) { } 0 0 0
670 0 $minima = [$slice_length, $slice];
671 }
672 else {
673 0 push(@results, ${$minima}[1]);
674 0 $minima = [$threshold, ''];
675 0 $found_minima = 1;
676 }
677 }
678 }
679 else {
680 0 $found_minima = 0;
681 }
682 }
683
684 0 return @results;
685 }
686  
687 =head2 _run
688  
689 Title : _run
690 Usage : Internal function, not to be called directly
691 Function: makes actual system call to clustalw program
692 Returns : nothing; clustalw output is written to a
693 temporary file
694 Args : Name of a file containing a set of unaligned fasta sequences
695 and hash of parameters to be passed to clustalw
696  
697 =cut
698  
699 sub _run {
700 0 ▶ my ($self, $command, $infile1, $infile2, $param_string) = @_;
Subroutine _run: not called CC=24 SCAR=64.0
701
702 0 my ($instring, $tree);
703 0 ▶ my $quiet = $self->quiet() || $self->verbose() < 0;
Condition0%0/3
$self->quiet || $self->verbose < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->quiet || $self->verbose < 0
$self->quiet $self->verbose < 0
Truth table0%0/3
A || B
A= $self->quietB= $self->verbose < 0
ABresult
1X1
011
000
704
705 0 ▶ if ($command =~ /align|both/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /align|both/) 0 0 0
706 0 ▶ if ($^O eq 'dec_osf') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'dec_osf') { } 0 0 0
707 0 $instring = $infile1;
708 0 $command = '';
709 }
710 else {
711 0 $instring = " -infile=". '"' . $infile1 . '"';
712 }
713 0 $param_string .= " $infile2";
714 }
715
716 0 ▶ if ($command =~ /profile/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /profile/) 0 0 0
717 0 $instring = "-profile1=$infile1 -profile2=$infile2";
718 0 chmod 0777, $infile1, $infile2;
719 0 $command = '-profile';
720 }
721
722 0 ▶ if ($command =~ /add_sequences/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /add_sequences/) 0 0 0
723 0 $instring = "-profile1=$infile1 -profile2=$infile2";
724 0 chmod 0777, $infile1,$infile2;
725 0 $command = '-sequences';
726 }
727  
728 0 ▶ if ($command =~ /tree/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /tree/) 0 0 0
729 0 ▶ if( $^O eq 'dec_osf' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'dec_osf') { } 0 0 0
730 0 $instring = $infile1;
731 0 $command = '';
732 }
733 else {
734 0 $instring = " -infile=". '"' . $infile1 . '"';
735 }
736 0 $param_string .= " $infile2";
737
738 0 $self->debug( "Program ".$self->executable."\n");
739 0 my $commandstring = $self->executable."$instring"."$param_string";
740 0 ▶ $commandstring .= ' 1>/dev/null' if $quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $quiet 0 0 0
741 0 $self->debug( "clustal command = $commandstring");
742
743 0 my $status = system($commandstring);
744 0 ▶ unless( $status == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status == 0) 0 0 0
745 0 $self->warn( "Clustalw call ($commandstring) crashed: $? \n");
746 0 return undef;
747 }
748
749 0 return $self->_get_tree($infile1, $param_string);
750 }
751
752 0 ▶ my $output = $self->output || 'gcg';
Condition0%0/2
$self->output || 'gcg'
l!l
00
MC/DC0%0/1
$self->output || 'gcg'
$self->output
Truth table0%0/2
A
A= $self->output
Aresult
11
00
753 0 $self->debug( "Program ".$self->executable."\n");
754 0 my $commandstring = $self->executable." $command"." $instring"." -output=$output". " $param_string";
755 0 $self->debug( "clustal command = $commandstring\n");
756
757 0 ▶ open(my $pipe, "$commandstring |") || $self->throw("ClustalW call ($commandstring) failed to start: $? | $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $pipe, "$commandstring |" or $self->throw("ClustalW call ($commandstring) failed to start: $? | $!") 0 0 0
758 0 my $score;
759 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
760 0 ▶ print unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 0 0
761 # Kevin Brown suggested the following regex, though it matches multiple
762 # times: we pick up the last one
763 0 ▶ $score = $1 if ($_ =~ /Score:(\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /Score:(\d+)/ 0 0 0
764 # This one is printed at the end and seems the most appropriate to pick
765 # up; we include the above regex incase 'Alignment Score' isn't given
766 0 ▶ $score = $1 if ($_ =~ /Alignment Score (-?\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /Alignment Score (-?\d+)/ 0 0 0
767 }
768 0 ▶ close($pipe) || ($self->throw("ClustalW call ($commandstring) crashed: $?"));
Branch: 1 branch
BranchTrueFalseTotal
close $pipe or $self->throw("ClustalW call ($commandstring) crashed: $?") 0 0 0
769
770 0 my $outfile = $self->outfile();
771
772 # retrieve alignment (Note: MSF format for AlignIO = GCG format of clustalw)
773 0 ▶ my $format = $output =~ /gcg/i ? 'msf' : $output;
Branch: 1 branch
BranchTrueFalseTotal
$output =~ /gcg/i ? : 0 0 0
774 0 ▶ if ($format =~ /clustal/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /clustal/i) 0 0 0
775 0 $format = 'clustalw'; # force clustalw incase 'clustal' is requested
776 }
777 0 my $in = Bio::AlignIO->new(-file => $outfile, -format=> $format);
778 0 my $aln = $in->next_aln();
779 0 $in->close;
780 0 $aln->score($score);
781
782 0 ▶ if ($command eq 'both') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "both") 0 0 0
783 0 $tree = $self->_get_tree($infile1, $param_string);
784 }
785
786 # Clean up the temporary files created along the way...
787 # Replace file suffix with dnd to find name of dendrogram file(s) to delete
788 0 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 0 0 0
789 0 foreach my $f ($infile1, $infile2) {
790 0 $f =~ s/\.[^\.]*$// ;
791 0 ▶ unlink $f .'.dnd' if ($f ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $f ne "" 0 0 0
792 }
793 }
794
795 0 ▶ if ($command eq 'both') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "both") 0 0 0
796 0 return ($aln, $tree);
797 }
798 0 return $aln;
799 }
800  
801 sub _get_tree {
802 0 ▶ my ($self, $treefile, $param_string) = @_;
Subroutine _get_tree: not called CC=6 SCAR=37.4
803
804 0 $treefile =~ s/\.[^\.]*$// ;
805
806 0 ▶ if ($param_string =~ /-bootstrap/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($param_string =~ /-bootstrap/) { } 0 0 0
elsif ($param_string =~ /-tree/) { } 0 0 0
807 0 $treefile .= '.phb';
808 }
809 elsif ($param_string =~ /-tree/) {
810 0 $treefile .= '.ph';
811 }
812 else {
813 0 $treefile .= '.dnd';
814 }
815
816 0 my $in = Bio::TreeIO->new('-file' => $treefile,
817 '-format'=> 'newick');
818
819 0 my $tree = $in->next_tree;
820 0 ▶ unless ( $self->save_tempfiles ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->save_tempfiles) 0 0 0
821 0 foreach my $f ( $treefile ) {
822 0 ▶ unlink $f if( $f ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if $f ne "" 0 0 0
823 }
824 }
825
826 0 return $tree;
827 }
828  
829 =head2 _setinput()
830  
831 Title : _setinput
832 Usage : Internal function, not to be called directly
833 Function: Create input file for clustalw program
834 Returns : name of file containing clustalw data input
835 Args : Seq or Align object reference or input file name
836  
837 =cut
838  
839 sub _setinput {
840 0 ▶ my ($self, $input, $suffix) = @_;
Subroutine _setinput: not called CC=13 SCAR=52.0
841 0 my ($infilename, $seq, $temp, $tfh);
842
843 # suffix is used to distinguish alignment files If $input is not a
844 # reference it better be the name of a file with the sequence/
845
846 # alignment data...
847 0 ▶ unless (ref $input) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $input) 0 0 0
848 # check that file exists or throw
849 0 $infilename = $input;
850 0 ▶ return unless -e $input;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $input 0 0 0
851 0 return $infilename;
852 }
853
854 # $input may be an array of BioSeq objects...
855 0 ▶ if (ref($input) eq "ARRAY") {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $input eq 'ARRAY') { } 0 0 0
elsif (ref $input eq 'Bio::SimpleAlign') { } 0 0 0
elsif (ref $input and $input->isa('Bio::PrimarySeqI') and $suffix == 2) { } 0 0 0
856 # Open temporary file for both reading & writing of BioSeq array
857 0 ($tfh,$infilename) = $self->io->tempfile(-dir=>$self->tempdir);
858 0 $temp = Bio::SeqIO->new('-fh'=>$tfh, '-format' =>'Fasta');
859
860 # Need at least 2 seqs for alignment
861 0 ▶ return unless (scalar(@$input) > 1);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$input > 1 0 0 0
862
863 0 foreach $seq (@$input) {
864 0 ▶ return unless (defined $seq && $seq->isa("Bio::PrimarySeqI") and $seq->id());
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq and $seq->isa("Bio::PrimarySeqI") and $seq->id 0 0 0
Condition0%0/6
defined $seq and $seq->isa("Bio::PrimarySeqI") and $seq->id
!ll&&!rl&&r
000
defined $seq and $seq->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/3
defined $seq and $seq->isa("Bio::PrimarySeqI") and $seq->id
defined $seq $seq->isa("Bio::PrimarySeqI") $seq->id
Truth table0%0/4
A and B and C
A= defined $seqB= $seq->isa("Bio::PrimarySeqI")C= $seq->id
ABCresult
0XX0
10X0
1100
1111
865 0 $temp->write_seq($seq);
866 }
867 0 $temp->close();
868 0 close($tfh);
869 0 undef $tfh;
870 0 return $infilename;
871 }
872
873 # $input may be a SimpleAlign object.
874 elsif (ref($input) eq "Bio::SimpleAlign") {
875 # Open temporary file for both reading & writing of SimpleAlign object
876 0 ($tfh,$infilename) = $self->io->tempfile(-dir=>$self->tempdir);
877 0 $temp = Bio::AlignIO->new('-fh'=> $tfh, '-format' => 'fasta');
878 0 $temp->write_aln($input);
879 0 close($tfh);
880 0 undef $tfh;
881 0 return $infilename;
882 }
883
884 # or $input may be a single BioSeq object (to be added to a previous alignment)
885 ▶ elsif (ref($input) && $input->isa("Bio::PrimarySeqI") && $suffix==2) {
Condition0%0/6
ref $input and $input->isa("Bio::PrimarySeqI") and $suffix == 2
!ll&&!rl&&r
000
ref $input and $input->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/3
ref $input and $input->isa("Bio::PrimarySeqI") and $suffix == 2
ref $input $input->isa("Bio::PrimarySeqI") $suffix == 2
Truth table0%0/4
A and B and C
A= ref $inputB= $input->isa("Bio::PrimarySeqI")C= $suffix == 2
ABCresult
0XX0
10X0
1100
1111
886 # Open temporary file for both reading & writing of BioSeq object
887 0 ($tfh,$infilename) = $self->io->tempfile();
888 0 $temp = Bio::SeqIO->new(-fh=> $tfh, '-format' =>'Fasta');
889 0 $temp->write_seq($input);
890 0 close($tfh);
891 0 undef $tfh;
892 0 return $infilename;
893 }
894
895 0 return;
896 }
897  
898 =head2 _setparams()
899  
900 Title : _setparams
901 Usage : Internal function, not to be called directly
902 Function: Create parameter inputs for clustalw program
903 Returns : parameter string to be passed to clustalw
904 during align or profile_align
905 Args : name of calling object
906  
907 =cut
908  
909 sub _setparams {
910 0 ▶ my $self = shift;
Subroutine _setparams: not called CC=2 SCAR=17.9
911
912 0 my $param_string = $self->SUPER::_setparams(-params => \@CLUSTALW_PARAMS,
913 -switches => \@CLUSTALW_SWITCHES,
914 -dash => 1,
915 -lc => 1,
916 -join => '=');
917
918 # Set default output file if no explicit output file selected
919 0 ▶ unless ($param_string =~ /outfile/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param_string =~ /outfile/) 0 0 0
920 0 my ($tfh, $outfile) = $self->io->tempfile(-dir => $self->tempdir());
921 0 close($tfh);
922 0 undef $tfh;
923 0 $self->outfile($outfile);
924 0 $param_string .= " -outfile=\"$outfile\"" ;
925 }
926
927 0 $param_string .= ' 2>&1';
928
929 0 return $param_string;
930 }
931  
932 3 1;
« blib/lib/Bio/Tools/Run/Alignment/TCoffee.pm ↑ Summary blib/lib/Bio/Tools/Run/Alignment/Lagan.pm »