NAME
Bio::Tools::Run::Alignment::Clustalw - Object for the calculation of a multiple sequence alignment from a set of unaligned sequences or alignments using the Clustalw program
VERSION
version 1.7.4
SYNOPSIS
# Build a clustalw alignment factory@params = ('ktuple' => 2, 'matrix' => 'BLOSUM');$factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);# Pass the factory a list of sequences to be aligned.$inputfilename = 't/data/cysprot.fa';$aln = $factory->align($inputfilename); # $aln is a SimpleAlign object.# or$seq_array_ref = \@seq_array;# where @seq_array is an array of Bio::Seq objects$aln = $factory->align($seq_array_ref);# Or one can pass the factory a pair of (sub)alignments#to be aligned against each other, e.g.:$aln = $factory->profile_align($aln1,$aln2);# where $aln1 and $aln2 are Bio::SimpleAlign objects.# Or one can pass the factory an alignment and one or more unaligned# sequences to be added to the alignment. For example:$aln = $factory->profile_align($aln1,$seq); # $seq is a Bio::Seq object.# Get a tree of the sequences$tree = $factory->tree(\@seq_array);# Get both an alignment and a tree($aln, $tree) = $factory->run(\@seq_array);# Do a footprinting analysis on the supplied sequences, getting back the# most conserved sub-alignmentsmy @results = $factory->footprint(\@seq_array);foreach my $result (@results) {print $result->consensus_string, "\n";}# There are various additional options and input formats available.# See the DESCRIPTION section that follows for additional details.
DESCRIPTION
Note: this DESCRIPTION only documents the Bioperl interface to Clustalw. Clustalw, itself, is a large & complex program - for more information regarding clustalw, please see the clustalw documentation which accompanies the clustalw distribution. Clustalw is available from (among others) ftp://ftp.ebi.ac.uk/pub/software/. Clustalw.pm has only been tested using version 1.8 of clustalw. Compatibility with earlier versions of the clustalw program is currently unknown. Before running Clustalw successfully it will be necessary: to install clustalw on your system, and to ensure that users have execute privileges for the clustalw program.
Helping the module find your executable
You will need to enable Clustalw to find the clustalw program. This can be done in (at least) three ways:
1. Make sure the clustalw executable is in your path so thatwhich clustalwreturns a clustalw executable on your system.2. Define an environmental variable CLUSTALDIR which is adirectory which contains the 'clustalw' application:In bash:export CLUSTALDIR=/home/username/clustalw1.8In csh/tcsh:setenv CLUSTALDIR /home/username/clustalw1.83. Include a definition of an environmental variable CLUSTALDIR inevery script that will use this Clustalw wrapper module, e.g.:BEGIN { $ENV{CLUSTALDIR} = '/home/username/clustalw1.8/' }use Bio::Tools::Run::Alignment::Clustalw;
If you are running an application on a webserver make sure the webserver environment has the proper PATH set or use the options 2 or 3 to set the variables.
How it works
Bio::Tools::Run::Alignment::Clustalw is an object for performing a multiple sequence alignment from a set of unaligned sequences and/or sub-alignments by means of the clustalw program.
Initially, a clustalw "factory object" is created. Optionally, the factory may be passed most of the parameters or switches of the clustalw program, e.g.:
@params = ('ktuple' => 2, 'matrix' => 'BLOSUM');$factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
Any parameters not explicitly set will remain as the defaults of the clustalw program. Additional parameters and switches (not available in clustalw) may also be set. Currently, the only such parameter is "quiet", which when set to a non-zero value, suppresses clustalw terminal output. Not all clustalw parameters are supported at this stage.
By default, Clustalw output is returned solely in a the form of a Bio::SimpleAlign object which can then be printed and/or saved in multiple formats using the AlignIO.pm module. Optionally the raw clustalw output file can be saved if the calling script specifies an output file (with the clustalw parameter OUTFILE). Currently only the GCG-MSF output file formats is supported.
Not all parameters and features have been implemented yet in Perl format.
Alignment parameters can be changed and/or examined at any time after the factory has been created. The program checks that any parameter/switch being set/read is valid. However, currently no additional checks are included to check that parameters are of the proper type (eg string or numeric) or that their values are within the proper range. As an example, to change the value of the clustalw parameter ktuple to 3 and subsequently to check its value one would write:
$ktuple = 3;$factory->ktuple($ktuple);$get_ktuple = $factory->ktuple();
Once the factory has been created and the appropriate parameters set, one can call the method align() to align a set of unaligned sequences, or call profile_align() to add one or more sequences or a second alignment to an initial alignment.
Input to align() may consist of a set of unaligned sequences in the form of the name of file containing the sequences. For example,
$inputfilename = 't/data/cysprot.fa';$aln = $factory-E<gt>align($inputfilename);
Alternately one can create an array of Bio::Seq objects somehow
$str = Bio::SeqIO->new(-file=> 't/data/cysprot.fa', -format => 'Fasta');@seq_array =();while ( my $seq = $str->next_seq() ) {push (@seq_array, $seq) ;}
and pass the factory a reference to that array
$seq_array_ref = \@seq_array;$aln = $factory->align($seq_array_ref);
In either case, align() returns a reference to a SimpleAlign object which can then used (see Bio::SimpleAlign).
Once an initial alignment exists, one can pass the factory additional sequence(s) to be added (ie aligned) to the original alignment. The alignment can be passed as either an alignment file or a Bio:SimpleAlign object. The unaligned sequence(s) can be passed as a filename or as an array of BioPerl sequence objects or as a single BioPerl Seq object. For example (to add a single sequence to an alignment),
$str = Bio::AlignIO->new(-file=> 't/data/cysprot1a.msf');$aln = $str->next_aln();$str1 = Bio::SeqIO->new(-file=> 't/data/cysprot1b.fa');$seq = $str1->next_seq();$aln = $factory->profile_align($aln,$seq);
In either case, profile_align() returns a reference to a SimpleAlign object containing a new SimpleAlign object of the alignment with the additional sequence(s) added in.
Finally one can pass the factory a pair of (sub)alignments to be aligned against each other. The alignments can be passed in the form of either a pair of alignment files or a pair of Bio:SimpleAlign objects. For example,
$profile1 = 't/data/cysprot1a.msf';$profile2 = 't/data/cysprot1b.msf';$aln = $factory->profile_align($profile1,$profile2);
or
$str1 = Bio::AlignIO->new(-file=> 't/data/cysprot1a.msf');$aln1 = $str1->next_aln();$str2 = Bio::AlignIO->new(-file=> 't/data/cysprot1b.msf');$aln2 = $str2->next_aln();$aln = $factory->profile_align($aln1,$aln2);
In either case, profile_align() returns a reference to a SimpleAlign object containing an (super)alignment of the two input alignments.
For more examples of syntax and use of Clustalw, the user is encouraged to look at the script Clustalw.t in the t/ directory.
Note: Clustalw is still under development. Various features of the clustalw program have not yet been implemented. If you would like that a specific clustalw feature be added to this perl contact [email protected].
These can be specified as parameters when instantiating a new Clustalw object, or through get/set methods of the same name (lowercase).
INTERNAL METHODS
_run
Title : _runUsage : Internal function, not to be called directlyFunction: makes actual system call to clustalw programReturns : nothing; clustalw output is written to atemporary fileArgs : Name of a file containing a set of unaligned fasta sequencesand hash of parameters to be passed to clustalw
_setinput()
Title : _setinputUsage : Internal function, not to be called directlyFunction: Create input file for clustalw programReturns : name of file containing clustalw data inputArgs : Seq or Align object reference or input file name
_setparams()
Title : _setparamsUsage : Internal function, not to be called directlyFunction: Create parameter inputs for clustalw programReturns : parameter string to be passed to clustalwduring align or profile_alignArgs : name of calling object
EXAMPLE
You will need to have installed clustalw and to ensure that Clustalw.pm can find it. This can be done in different ways (bash syntax):
export PATH=$PATH:/home/peter/clustalw1.8
or define an environmental variable CLUSTALDIR:
export CLUSTALDIR=/home/peter/clustalw1.8
or include a definition of an environmental variable CLUSTALDIR in every script that will use Clustal.pm:
BEGIN {$ENV{CLUSTALDIR} = '/home/peter/clustalw1.8/'; }
We are going to demonstrate 3 possible applications of Clustalw.pm:
- 1.
-
Test effect of varying clustalw alignment parameter(s) on resulting alignment
- 2.
-
Test effect of changing the order that sequences are added to the alignment on the resulting alignment
- 3.
-
Test effect of incorporating an "anchor point" in the alignment process
Before we can do any tests, we need to set up the environment, create the factory and read in the unaligned sequences.
use Getopt::Long;use Bio::Tools::Run::Alignment::Clustalw;use Bio::SimpleAlign;use Bio::AlignIO;use Bio::SeqIO;use strict;# set some default valuesmy $infile = 't/data/cysprot1a.fa';my @params = ('quiet' => 1 );my $do_only = '123'; # string listing examples to be executed. Default is to# execute all tests (ie 1,2 and 3)my $param = 'ktuple'; # parameter to be varied in example 1my $startvalue = 1; # initial value for parameter $parammy $stopvalue = 3; # final value for parameter $parammy $regex = 'W[AT]F'; # regular expression for 'anchoring' alignment in example 3my $extension = 30; # distance regexp anchor should be extended in each direction# for local alignment in example 3my $helpflag = 0; # Flag to show usage info.# get user optionsmy @argv = @ARGV; # copy ARGV before GetOptions() massacres it.&GetOptions("h!" => \$helpflag, "help!" => \$helpflag,"in=s" => \$infile,"param=s" => \$param,"do=s" => \$do_only,"start=i" => \$startvalue,"stop=i" => \$stopvalue,"ext=i" => \$extension,"regex=s" => \$regex,) ;if ($helpflag) { &clustalw_usage(); exit 0;}# create factory & set user-specified global clustalw parametersforeach my $argv (@argv) {unless ($argv =~ /^(.*)=>(.*)$/) { next;}push (@params, $1 => $2);}my $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);# put unaligned sequences in a Bio::Seq arraymy $str = Bio::SeqIO->new(-file=> $infile, '-format' => 'Fasta');my ($paramvalue, $aln, $subaln, @consensus, $seq_num, $string, $strout, $id);my @seq_array =();while ( my $seq = $str->next_seq() ) { push (@seq_array, $seq) ;}# Do each example that has digit present in variable $do_only$_= $do_only;/1/ && &vary_params();/2/ && &vary_align_order();/3/ && &anchored_align();## End of "main"################################################## vary_params(): Example demonstrating varying of clustalw parameter#sub vary_params {print "Beginning parameter-varying example... \n";# Now we'll create several alignments, 1 for each value of the selected# parameter. We also compute a simple consensus string for each alignment.# (In the default case, we vary the "ktuple" parameter, creating 3# alignments using ktuple values from 1 to 3.)my $index =0;for ($paramvalue = $startvalue; $paramvalue < ($stopvalue + 1); $paramvalue++) {$factory->$param($paramvalue); # set parameter valueprint "Performing alignment with $param = $paramvalue \n";$aln = $factory->align(\@seq_array);$string = $aln->consensus_string(); # Get consensus of alignment# convert '?' to 'X' at non-consensus positions$string =~ s/\?/X/g;$consensus[$index] = Bio::Seq->new(-id=>"$param=$paramvalue",-seq=>$string);$index++;}# Compare consensus strings for alignments with different $param values by# making an alignment of the different consensus strings# $factory->ktuple(1); # set ktuple parameterprint "Performing alignment of $param consensus sequences \n";$aln = $factory->align(\@consensus);$strout = Bio::AlignIO->newFh('-format' => 'msf');print $strout $aln;return 1;}################################################## vary_align_order():## For our second example, we'll test the effect of changing the order# that sequences are added to the alignmentsub vary_align_order {print "\nBeginning alignment-order-changing example... \n";@consensus = (); # clear arrayfor ($seq_num = 0; $seq_num < scalar(@seq_array); $seq_num++) {my $obj_out = shift @seq_array; # remove one Seq object from array and save$id = $obj_out->display_id;# align remaining sequencesprint "Performing alignment with sequence $id left out \n";$subaln = $factory->align(\@seq_array);# add left-out sequence to subalignment$aln = $factory->profile_align($subaln,$obj_out);$string = $aln->consensus_string(); # Get consensus of alignment# convert '?' to 'X' for non-consensus positions$string =~ s/\?/X/g;$consensus[$seq_num] = Bio::Seq->new(-id=>"$id left out",-seq=>$string);push @seq_array, $obj_out; # return Seq object for next (sub) alignment}# Compare consensus strings for alignments created in different orders# $factory->ktuple(1); # set ktuple parameterprint "\nPerforming alignment of consensus sequences for different reorderings \n";print "Each consensus is labeled by the sequence which was omitted in the initial alignment\n";$aln = $factory->align(\@consensus);$strout = Bio::AlignIO->newFh('-format' => 'msf');print $strout $aln;return 1;}################################################## anchored_align()## For our last example, we'll test a way to perform a local alignment by# "anchoring" the alignment to a regular expression. This is similar# to the approach taken in the recent dbclustal program.# In principle, we could write a script to search for a good regular expression# to use. Instead, here we'll simply choose one manually after looking at the# previous alignments.sub anchored_align {my @local_array = ();my @seqs_not_matched = ();print "\n Beginning anchored-alignment example... \n";for ($seq_num = 0; $seq_num < scalar(@seq_array); $seq_num++) {my $seqobj = $seq_array[$seq_num];my $seq = $seqobj->seq();my $id = $seqobj->id();# if $regex is not found in the sequence, save sequence id name and set# array value =0 for laterunless ($seq =~/$regex/) {$local_array[$seq_num] = 0;push (@seqs_not_matched, $id) ;next;}# find positions of start and of subsequence to be alignedmy $match_start_pos = length($`);my $match_stop_pos = length($`) + length($&);my $start = ($match_start_pos - $extension) > 1 ?($match_start_pos - $extension) +1 : 1;my $stop = ($match_stop_pos + $extension) < length($seq) ?($match_stop_pos + $extension) : length($seq);my $string = $seqobj->subseq($start, $stop);$local_array[$seq_num] = Bio::Seq->new(-id=>$id, -seq=>$string);}@local_array = grep $_ , @local_array; # remove array entries with no match# Perform alignment on the local segments of the sequences which match "anchor"$aln = $factory->align(\@local_array);my $consensus = $aln->consensus_string(); # Get consensus of local alignmentif (scalar(@seqs_not_matched) ) {print " Sequences not matching $regex : @seqs_not_matched \n"} else {print " All sequences match $regex : @seqs_not_matched \n"}print "Consensus sequence of local alignment: $consensus \n";return 1;}#----------------sub clustalw_usage {#----------------#-----------------------# Prints usage information for general parameters.print STDERR <<"QQ_PARAMS_QQ";Command-line accessible script variables and commands:--------------------------------h : Display this usage info and exit.-in <str> : File containing input sequences in fasta format (default = $infile) .-do <str> : String listing examples to be executed. Default is to executeall tests (ie default = '123')-param <str> : Parameter to be varied in example 1. Any clustalw parameterwhich takes inteer values can be varied (default = 'ktuple')-start <int> : Initial value for varying parameter in example 1 (default = 1)-stop <int> : Final value for varying parameter (default = 3)-regex <str> : Regular expression for 'anchoring' alignment in example 3(default = $regex)-ext <int> : Distance regexp anchor should be extended in each directionfor local alignment in example 3 (default = 30)In addition, any valid Clustalw parameter can be set using the syntax"parameter=>value" as in "ktuple=>3"So a typical command lines might be:> clustalw.pl -param=pairgap -start=2 -stop=3 -do=1 "ktuple=>3"or> clustalw.pl -ext=10 -regex='W[AST]F' -do=23 -in='t/cysprot1a.fa'QQ_PARAMS_QQ}
PARAMETER FOR ALIGNMENT COMPUTATION
KTUPLE
Title : KTUPLEDescription : (optional) set the word size to be used in the alignmentThis is the size of exactly matching fragment that is used.INCREASE for speed (max= 2 for proteins; 4 for DNA),DECREASE for sensitivity.For longer sequences (e.g. >1000 residues) you mayneed to increase the default
TOPDIAGS
Title : TOPDIAGSDescription : (optional) number of best diagonals to useThe number of k-tuple matches on each diagonal(in an imaginary dot-matrix plot) is calculated.Only the best ones (with most matches) are used inthe alignment. This parameter specifies how many.Decrease for speed; increase for sensitivity.
WINDOW
Title : WINDOWDescription : (optional) window sizeThis is the number of diagonals around each of the 'best'diagonals that will be used. Decrease for speed;increase for sensitivity.
PAIRGAP
Title : PAIRGAPDescription : (optional) gap penalty for pairwise alignmentsThis is a penalty for each gap in the fast alignments.It has little affect on the speed or sensitivity exceptfor extreme values.
FIXEDGAP
Title : FIXEDGAPDescription : (optional) fixed length gap penalty
FLOATGAP
Title : FLOATGAPDescription : (optional) variable length gap penalty
MATRIX
Title : MATRIXDefault : PAM100 for DNA - PAM250 for protein alignmentDescription : (optional) substitution matrix used in the multiplealignments. Depends on the version of clustalw as towhat default matrix will be usedPROTEIN WEIGHT MATRIX leads to a new menu where you areoffered a choice of weight matrices. The default forproteins in version 1.8 is the PAM series derived byGonnet and colleagues. Note, a series is used! Theactual matrix that is used depends on how similar thesequences to be aligned at this alignment stepare. Different matrices work differently at eachevolutionary distance.DNA WEIGHT MATRIX leads to a new menu where a singlematrix (not a series) can be selected. The default isthe matrix used by BESTFIT for comparison of nucleicacid sequences.
TYPE
Title : TYPEDescription : (optional) sequence type: protein or DNA. This allowsyou to explicitly override the programs attempt atguessing the type of the sequence. It is only usefulif you are using sequences with a VERY strangecomposition.
OUTPUT
Title : OUTPUTDescription : (optional) clustalw supports GCG or PHYLIP or PIR orClustal format. See the Bio::AlignIO modules forwhich formats are supported by bioperl.
OUTFILE
Title : OUTFILEDescription : (optional) Name of clustalw output file. If not setmodule will erase output file. In any case alignment willbe returned in the form of SimpleAlign objects
TRANSMIT
Title : TRANSMITDescription : (optional) transitions not weighted. The default is toweight transitions as more favourable than othermismatches in DNA alignments. This switch makes allnucleotide mismatches equally weighted.
program_name
Title : program_nameUsage : $factory>program_name()Function: holds the program nameReturns: stringArgs : None
program_dir
Title : program_dirUsage : $factory->program_dir(@params)Function: returns the program directory, obtained from ENV variable.Returns: stringArgs :
version
Title : versionUsage : exit if $prog->version() < 1.8Function: Determine the version number of the programExample :Returns : float or undefArgs : none
run
Title : runUsage : ($aln, $tree) = $factory->run($inputfilename);($aln, $tree) = $factory->run($seq_array_ref);Function: Perform a multiple sequence alignment, generating a tree at the sametime. (Like align() and tree() combined.)Returns : A SimpleAlign object containing the sequence alignment and aBio::Tree::Tree object with the tree relating the sequences.Args : Name of a file containing a set of unaligned fasta sequencesor else an array of references to Bio::Seq objects.
align
Title : alignUsage : $inputfilename = 't/data/cysprot.fa';$aln = $factory->align($inputfilename);or$seq_array_ref = \@seq_array; # @seq_array is array of Seq objs$aln = $factory->align($seq_array_ref);Function: Perform a multiple sequence alignmentReturns : Reference to a SimpleAlign object containing thesequence alignment.Args : Name of a file containing a set of unaligned fasta sequencesor else an array of references to Bio::Seq objects.Throws an exception if argument is not either a string (eg afilename) or a reference to an array of Bio::Seq objects. Ifargument is string, throws exception if file corresponding to stringname can not be found. If argument is Bio::Seq array, throwsexception if less than two sequence objects are in array.
profile_align
Title : profile_alignUsage : $aln = $factory->profile_align(@simple_aligns);or$aln = $factory->profile_align(@subalignment_filenames);Function: Perform an alignment of 2 (sub)alignmentsReturns : Reference to a SimpleAlign object containing the (super)alignment.Args : Names of 2 files containing the subalignmentsor references to 2 Bio::SimpleAlign objects.
Throws an exception if arguments are not either strings (eg filenames) or references to SimpleAlign objects.
add_sequences
Title : add_sequencesUsage :Function: Align and add sequences into an alignmentExample :Returns : Reference to a SimpleAlign object containing the (super)alignment.Args : Names of 2 files, the first one containing an alignment and the second one containing sequences to be addedor references to 2 Bio::SimpleAlign objects.
Throws an exception if arguments are not either strings (eg filenames) or references to SimpleAlign objects.
tree
Title : treeUsage : @params = ('bootstrap' => 1000,'tossgaps' => 1,'kimura' => 1,'seed' => 121,'bootlabels'=> 'nodes','quiet' => 1);$factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);$tree_obj = $factory->tree($aln_obj);or$tree_obj = $factory->tree($treefilename);Function: Retrieve a tree corresponding to the inputReturns : Bio::TreeIO objectArgs : Bio::SimpleAlign or filename of a tree
footprint
Title : footprintUsage : @alns = $factory->footprint($treefilename, $window_size, $diff);@alns = $factory->footprint($seqs_array_ref);Function: Aligns all the supplied sequences and slices out of the alignmentthose regions along a sliding window who's tree length differssignificantly from the total average tree length.Returns : list of Bio::SimpleAlign objectsArgs : first argument as per run(), optional second argument to specifythe size of the sliding window (default 5 bp) and optional thirdargument to specify the % difference from the total tree lengthneeded for a window to be considered a footprint (default 33%).
FEEDBACK
Mailing lists
User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated.
[email protected] - General discussionhttp://bioperl.org/Support.html - About the mailing lists
Support
Please direct usage questions or support issues to the mailing list: [email protected]
rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible.
Reporting bugs
Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web:
https://github.com/bioperl/bio-tools-run-alignment-clustalw/issues
AUTHORS
Peter Schattner <[email protected]>
Jason Stajich <[email protected]>
Sendu Bala <[email protected]>
COPYRIGHT
This software is copyright (c) by Peter Schattner <[email protected]>.
This software is available under the same terms as the perl 5 programming language system itself.