BioPerl-Run
view release on metacpan or search on metacpan
lib/Bio/Tools/Run/Phylo/Phylip/ProtDist.pm view on Meta::CPAN
Usage : @params = ('freq'=>('W','X','Y','Z')
where W + X + Y + Z = 1
Defaults to Equal (0.25,0.25,0.25,0.25)
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
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.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
http://redmine.open-bio.org/projects/bioperl/
=head1 AUTHOR - Shawn Hoon
Email shawnh@fugu-sg.org
=head1 APPENDIX
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
=cut
#'
package Bio::Tools::Run::Phylo::Phylip::ProtDist;
use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
@PROTDIST_PARAMS @OTHER_SWITCHES
%OK_FIELD);
use strict;
use Bio::SimpleAlign;
use Bio::AlignIO;
use Bio::TreeIO;
use Bio::Tools::Run::Phylo::Phylip::Base;
use Bio::Tools::Run::Phylo::Phylip::PhylipConf qw(%Menu);
use Bio::Tools::Phylo::Phylip::ProtDist;
use Cwd;
# inherit from Phylip::Base which has some methods for dealing with
# Phylip specifics
@ISA = qw(Bio::Tools::Run::Phylo::Phylip::Base);
# You will need to enable the protdist program. This
# can be done in (at least) 3 ways:
#
# 1. define an environmental variable PHYLIPDIR:
# export PHYLIPDIR=/home/shawnh/PHYLIP/bin
#
# 2. include a definition of an environmental variable CLUSTALDIR in
# every script that will use Clustal.pm.
# $ENV{PHYLIPDIR} = '/home/shawnh/PHYLIP/bin';
#
# 3. You can set the path to the program through doing:
# my @params('program'=>'/usr/local/bin/protdist');
# my $protdist_factory = Bio::Tools::Run::Phylo::Phylip::ProtDist->new(@params);
#
BEGIN {
@PROTDIST_PARAMS = qw(MODEL GENCODE CATEGORY PROBCHANGE TRANS WEIGHTS FREQ MULTIPLE);
@OTHER_SWITCHES = qw(QUIET);
foreach my $attr(@PROTDIST_PARAMS,@OTHER_SWITCHES) {
$OK_FIELD{$attr}++;
}
}
=head2 program_name
Title : program_name
Usage : >program_name()
Function: holds the program name
Returns: string
Args : None
=cut
sub program_name {
return 'protdist';
}
=head2 program_dir
Title : program_dir
Usage : ->program_dir()
Function: returns the program directory, obtained from ENV variable.
Returns: string
Args :
=cut
sub program_dir {
return Bio::Root::IO->catfile($ENV{PHYLIPDIR}) if $ENV{PHYLIPDIR};
}
lib/Bio/Tools/Run/Phylo/Phylip/ProtDist.pm view on Meta::CPAN
my ($alnfilename,$tfh);
# suffix is used to distinguish alignment files from an align obkect
#If $input is not a reference it better be the name of a file with the sequence/
# a phy formatted alignment file
unless (ref $input) {
# check that file exists or throw
$alnfilename= $input;
unless (-e $input) {return 0;}
return $alnfilename;
}
my @input = ref $input eq 'ARRAY' ? @{$input} : ($input);
# $input may be a SimpleAlign Object
($tfh,$alnfilename) = $self->io->tempfile(-dir=>$self->tempdir);
my $alnIO = Bio::AlignIO->new(-fh => $tfh,
-format=>'phylip',
-idlength=>$self->idlength());
my $input_count = 0;
foreach my $input(@input){
if ($input->isa("Bio::SimpleAlign")){
# Open temporary file for both reading & writing of BioSeq array
$alnIO->write_aln($input);
}
$input_count++;
}
$alnIO->close();
close($tfh);
$tfh = undef;
$self->_input_nbr($input_count);
return $alnfilename;
}
sub _input_nbr {
my ($self,$val) = @_;
if($val){
$self->{'_input_nbr'} = $val;
}
return $self->{'_input_nbr'};
}
=head2 _setparams()
Title : _setparams
Usage : Internal function, not to be called directly
Function: Create parameter inputs for protdist program
Example :
Returns : parameter string to be passed to protdist
Args : name of calling object
=cut
sub _setparams {
my ($attr, $value, $self);
#do nothing for now
$self = shift;
my $param_string = "";
my $cat = 0;
my %menu = %{$Menu{$self->version}->{'PROTDIST'}};
foreach my $attr ( @PROTDIST_PARAMS) {
$value = $self->$attr();
next unless (defined $value);
if ($attr =~/MODEL/i){
if ($value=~/CAT/i){
$cat = 1;
}
$param_string .= $menu{'MODEL'}{$value};
}
if($attr=~/MULTIPLE/i){
$param_string.=$menu{'MULTIPLE'}."$value\n";
}
if ($cat == 1){
if($attr =~ /GENCODE/i){
my $allowed = $menu{'GENCODE'}{'ALLOWED'};
$self->throw("Unallowed value for genetic code") unless ($value =~ /[$allowed]/);
$param_string .= $menu{'GENCODE'}{'OPTION'}."$value\n";
}
if ($attr =~/CATEGORY/i){
my $allowed = $menu{'CATEGORY'}{'ALLOWED'};
$self->throw("Unallowed value for categorization of amino acids") unless ($value =~/[$allowed]/);
$param_string .= $menu{'CATEGORY'}{'OPTION'}."$value\n";
}
if ($attr =~/PROBCHANGE/i){
if (($value =~ /\d+/)&&($value >= 0) && ($value < 1)){
$param_string .= $menu{'PROBCHANGE'}."$value\n";
}
else {
$self->throw("Unallowed value for probability change category");
}
}
if ($attr =~/TRANS/i){
if (($value=~/\d+/) && ($value >=0)){
$param_string .=$menu{'TRANS'}."$value\n";
}
}
if ($attr =~ /FREQ/i){
my @freq = split(",",$value);
if ($freq[0] !~ /\d+/){ #a letter provided (sets frequencies equally to 0.25)
$param_string .=$menu{'FREQ'}.$freq[0]."\n";
}
elsif ($#freq == 3) {#must have 4 digits for each base
$param_string .=$menu{'FREQ'};
foreach my $f (@freq){
$param_string.="$f\n";
}
}
else {
$self->throw("Unallowed value for base frequencies");
}
}
}
}
#set multiple option is not set and there are more than one sequence
if (($param_string !~ $menu{'MULTIPLE'}) && (defined ($self->_input_nbr) &&($self->_input_nbr > 1))){
$param_string.=$menu{'MULTIPLE'}.$self->_input_nbr."\n";
}
$param_string .=$menu{'SUBMIT'};
( run in 1.261 second using v1.01-cache-2.11-cpan-39bf76dae61 )