BioPerl-Run
view release on metacpan or search on metacpan
lib/Bio/Tools/Run/Phylo/Phylip/Neighbor.pm view on Meta::CPAN
=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 CONTRIBUTORS
Email:jason-at-bioperl.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::Neighbor;
use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
@NEIGHBOR_PARAMS @OTHER_SWITCHES
%OK_FIELD);
use strict;
use Bio::SimpleAlign;
use Bio::AlignIO;
use Bio::TreeIO;
use Bio::Root::Root;
use Bio::Root::IO;
use Bio::Tools::Run::Phylo::Phylip::Base;
use Bio::Tools::Run::Phylo::Phylip::PhylipConf qw(%Menu);
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 neighbor 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 PHYLIPDIR in
# every script that will use Neighbor.pm.
# $ENV{PHYLIPDIR} = '/home/shawnh/PHYLIP/bin';
#
# 3. You can set the path to the program through doing:
# my @params('program'=>'/usr/local/bin/neighbor');
# my $neighbor_factory = Bio::Tools::Run::Phylo::Phylip::Neighbor->new(@params);
#
BEGIN {
$PROGRAMNAME="neighbor";
if (defined $ENV{PHYLIPDIR}) {
$PROGRAMDIR = $ENV{PHYLIPDIR} || '';
$PROGRAM = Bio::Root::IO->catfile($PROGRAMDIR,
$PROGRAMNAME.($^O =~ /mswin/i ?'.exe':''));
}
else {
$PROGRAM = $PROGRAMNAME;
}
@NEIGHBOR_PARAMS = qw(TYPE OUTGROUP LOWTRI UPPTRI SUBREP JUMBLE MULTIPLE);
@OTHER_SWITCHES = qw(QUIET);
foreach my $attr(@NEIGHBOR_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 'neighbor';
}
=head2 program_dir
Title : program_dir
Usage : ->program_dir()
Function: returns the program directory, obtained from ENV variable.
lib/Bio/Tools/Run/Phylo/Phylip/Neighbor.pm view on Meta::CPAN
$self->_input_nbr($input_count);
close($tfh);
#get names from the first matrix, to be used in outgroup ordering
my %names;
$input = shift @input;
#set the species names
my @names = @{$input->names};
for(my $i=0; $i<= $#names; $i++){
$names{$names[$i]} = $i+1;
}
$self->names(\%names);
return $alnfilename;
}
sub _input_nbr {
my ($self,$val) = @_;
if($val){
$self->{'_input_nbr'} = $val;
} return $self->{'_input_nbr'};
}
=head2 names()
Title : names
Usage : $tree->names(\%names)
Function: get/set for a hash ref for storing names in matrix
with rank as values.
Example :
Returns : hash reference
Args : hash reference
=cut
sub names {
my ($self,$name) = @_;
if($name){
$self->{'_names'} = $name;
}
return $self->{'_names'};
}
=head2 _setparams()
Title : _setparams
Usage : Internal function, not to be called directly
Function: Create parameter inputs for neighbor program
Example :
Returns : parameter string to be passed to neighbor
Args : name of calling object
=cut
sub _setparams {
my ($attr, $value, $self);
#do nothing for now
$self = shift;
my $param_string = "";
my $type ="";
my $version = $self->version;
my %menu = %{$Menu{$version}->{'NEIGHBOR'}};
foreach my $attr ( @NEIGHBOR_PARAMS) {
$value = $self->$attr();
next unless (defined $value && $value);
if ($attr =~/TYPE/i){
if ($value=~/UPGMA/i){
$type = "UPGMA";
$param_string .= $menu{'TYPE'}{'UPGMA'};
}
}
elsif($attr =~ /OUTGROUP/i){
if ($type ne "UPGMA"){
if($value !~/^\d+$/){ # is a name so find the rank
my %names = %{$self->names};
$names{$value} || $self->throw("Outgroup $value not found");
$value = $names{$value};
}
$param_string .= $menu{'OUTGROUP'}."$value\n";
}
else {
$self->throw("Can't set outgroup using UPGMA. Use Neighbor-Joining instead");
}
}
elsif ($attr =~ /JUMBLE/i){
$self->throw("Unallowed value for random seed, need odd number") unless ($value =~ /\d+/ && ($value % 2 == 1));
$param_string .=$menu{'JUMBLE'}."$value\n";
}
elsif($attr=~/MULTIPLE/i){
$param_string.=$menu{'MULTIPLE'}."$value\n";
#version 3.6 needs a random seed
if($version eq "3.6"){
$param_string .= (2 * int(rand(10000)) + 1)."\n";
}
}
else{
$param_string .= $menu{uc $attr};
}
}
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'};
return $param_string;
}
=head2 outfile
Title : outfile
Usage : $obj->outfile($newval)
Function: Get/Set default PHYLIP outfile name ('outfile' usually)
Returns : value of outfile
Args : newvalue (optional)
=cut
=head2 treefile
( run in 3.170 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )