BioPerl-Run

 view release on metacpan or  search on metacpan

lib/Bio/Tools/Run/Phylo/Phylip/Consense.pm  view on Meta::CPAN

                It is in effect only if the Rooted option selection is not in effect.
                The trees will be re-rooted with a species of your choosing.

                usage  my $factory = Bio::Tools::Run::Phylo::Phylip::Consense->new(-outgroup=>2);

                Defaults to first species encountered. 

=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::Consense;

use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR $PROGRAMNAME
	    @CONSENSE_PARAMS @OTHER_SWITCHES
	    %OK_FIELD);
use strict;
use Bio::SimpleAlign;
use Bio::TreeIO;
use Bio::Tools::Run::Phylo::Phylip::Base;
use Bio::Tools::Run::Phylo::Phylip::PhylipConf qw(%Menu);
use IO::String;
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 Consense 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 Consense.pm.
# $ENV{PHYLIPDIR} = '/home/shawnh/PHYLIP/bin';
#
# 3. You can set the path to the program through doing:
# my @params('executable'=>'/usr/local/bin/consense');
# my $Consense_factory = Bio::Tools::Run::Phylo::Phylip::Consense->new(@params);
# 


BEGIN {
	@CONSENSE_PARAMS = qw(TYPE OUTGROUP ROOTED);
	@OTHER_SWITCHES = qw(QUIET);
	foreach my $attr(@CONSENSE_PARAMS,@OTHER_SWITCHES) {
	    $OK_FIELD{$attr}++;
	}
}

=head2 program_name

 Title   : program_name
 Usage   : $obj->program_name()
 Function: holds the program name
 Returns:  string
 Args    : None

=cut

sub program_name {
        return 'consense';
}

=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/Consense.pm  view on Meta::CPAN

    #  $input may be a SimpleAlign Object
    my @input = ref($input) eq "ARRAY" ? @{$input} : ($input);
    ($tfh,$alnfilename) = $self->io->tempfile(-dir=>$self->tempdir);
    my $treeIO = Bio::TreeIO->new(-fh => $tfh, 
				  -format=>'newick');

    foreach my $tree(@input){
	$tree->isa('Bio::Tree::TreeI') || $self->throw('Expected a Bio::TreeI object');
	$treeIO->write_tree($tree);
    }
    #get the species names in order, using the first one
    $self->_set_names_from_tree($input[0]);
    $treeIO->close();
    close($tfh);
    undef $tfh;
    return $alnfilename;		
}

=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 Consense program
 Example :
 Returns : parameter string to be passed to Consense
 Args    : name of calling object

=cut

sub _setparams {
    my ($attr, $value, $self);

    #do nothing for now
    $self = shift;
    my $param_string = "";
    my $rooted = 0;

    #for case where type is Ml
    my $Ml = 0;
    my $frac = 0.5;
    my %menu = %{$Menu{$self->version}->{'CONSENSE'}};

    foreach  my $attr ( @CONSENSE_PARAMS) {
    	$value = $self->$attr();
    	next unless (defined $value);
    	if ($attr =~/ROOTED/i){
        $rooted = 1;
        $param_string .= $menu{'ROOTED'};
      }
      elsif($attr =~/OUTGROUP/i){
          if($rooted == 1){
              $self->warn("Outgroup option cannot be used with a rooted tree");
              next;
          }
          if($value !~/^\d+$/){ # is a name
              my %names = %{$self->names};
              $names{$value} || $self->throw("Outgroup $value not found");
              $value = $names{$value};
          }
          $param_string .=$menu{'OUTGROUP'}."$value\n";
      }
      elsif($attr=~/TYPE/i){
          if($value=~/Ml/i){
              ($value,$frac) = split(/\s+/,$value);
              #default if not given
              $frac ||= 0.5;
              if($frac <= 0.5 || $frac > 1){
                  $self->warn("fraction given is out of range 0.5<frac<1, setting to 0.5");
                  $frac = 0.5;
              }
              $Ml=1;
          }
          $param_string.=$menu{'TYPE'}{uc $value};
      }
      else {
          $param_string.=$menu{uc $attr};
      }
	  }
    $param_string .= $menu{'SUBMIT'};
    if($Ml){
        $param_string.=$frac."\n";
    }

    return $param_string;
}



=head1 Bio::Tools::Run::Wrapper methods

=cut

=head2 no_param_checks

 Title   : no_param_checks
 Usage   : $obj->no_param_checks($newval)
 Function: Boolean flag as to whether or not we should
           trust the sanity checks for parameter values  
 Returns : value of no_param_checks
 Args    : newvalue (optional)



( run in 0.933 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )