Bio::Matrix::IO phylip
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::Matrix::IO::phylip - A parser for PHYLIP distance matricies
Package variables
No package variables defined.
Included modules
Bio::Matrix::IO
Bio::Matrix::PhylipDist
Inherit
Bio::Matrix::IO
Synopsis
  use Bio::Matrix::IO;
  my $parser = new Bio::Matrix::IO(-format   => 'phylip'
                                   -file     => 't/data/phylipdist.out');
  my $matrix = $parser->next_matrix;
Description
This is a parser for PHYLIP distance matrix output.
Methods
newDescriptionCode
next_matrixDescriptionCode
write_matrixDescriptionCode
Methods description
newcode    nextTop
 Title   : new
 Usage   : my $obj = new Bio::Matrix::IO::phylip();
 Function: Builds a new Bio::Matrix::IO::phylip object 
 Returns : an instance of Bio::Matrix::IO::phylip
 Args    :
next_matrixcodeprevnextTop
 Title   : next_matrix
 Usage   : my $matrix = $parser->next_matrix
 Function: Get the next result set from parser data
 Returns : Bio::Matrix::PhylipDist
Args : none
write_matrixcodeprevnextTop
 Title   : write_matrix
 Usage   : $matio->write_matrix($matrix)
 Function: Write out a matrix in the phylip distance format
 Returns : none
 Args    : Bio::Matrix::PhylipDist
Methods code
newdescriptionprevnextTop
sub new {
  my($class,@args) = @_;

  my $self = $class->SUPER::new(@args);
  my ($prog) = $self->_rearrange([qw(PROGRAM)], @args);
  $self->{'_program'} = $prog || $DEFAULTPROGRAM;
  return $self;
}
next_matrixdescriptionprevnextTop
sub next_matrix {
   my ($self) = @_;
   my @names;
   my @values;
   my $entry;
   my $size = 0;
   while ($entry=$self->_readline) {
       if($#names >=0 && $entry =~/^\s+\d+\n$/){
	   $self->_pushback($_);
	   last;
       } elsif($entry=~/^\s+(\d+)\n$/){	   
	   $size = $1;
	   next;
       } elsif( $entry =~ s/^\s+(\-?\d+\.\d+)/$1/ ) {
	   my (@line) = split( /\s+/,$entry);
	   push @{$values[-1]}, @line;
	   next;
       }
       my ($n,@line) = split( /\s+/,$entry);
       
       push @names, $n;
       push @values, [@line];
   }
   if( scalar @names != $size ) {
       $self->warn("The number of entries ".(scalar @names).
		   " is not the same $size");
   }
   $#names>=0 || return;
   my %dist;
   my $i=0;
   foreach my $name(@names){
       my $j=0;
       foreach my $n(@names) {
	   $dist{$name}{$n} = [$i,$j];
	   $j++;
       }
       $i++;
   }
   my $matrix = Bio::Matrix::PhylipDist->new
       (-matrix_name => $self->{'_program'},
	-matrix      =>\% dist,
	-names       =>\@ names,
	-values      =>\@ values);
    return $matrix;
}
write_matrixdescriptionprevnextTop
sub write_matrix {
    my ($self,@matricies) = @_;
    foreach my $matrix ( @matricies ) {
	my @names = @{$matrix->names};
	my @values = @{$matrix->_values};
	my %matrix = %{$matrix->_matrix};
	my $str;
	$str.= (" "x 4). scalar(@names)."\n";
	foreach my $name (@names){
	    my $newname = $name. (" " x (15-length($name)));
	    if( length($name) >= 15 ) { $newname .= " " }
	    $str.=$newname;
	    my $count = 0;
	    foreach my $n (@names){
		my ($i,$j) = @{$matrix{$name}{$n}};
		if($count < $#names){
		    $str.= $values[$i][$j]. "  ";
		}
		else {
		    $str.= $values[$i][$j];
		}
		$count++;
	    }
	    $str.="\n";
	}
	$self->_print($str);
    }
}
General documentation
FEEDBACKTop
Mailing ListsTop
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.
  bioperl-l@bioperl.org              - General discussion
  http://bioperl.org/MailList.shtml  - About the mailing lists
Reporting BugsTop
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:
  http://bugzilla.bioperl.org/
AUTHOR - Jason StajichTop
Email jason-at-bioperl-dot.org
Describe contact details here
CONTRIBUTORSTop
Additional contributors names and emails here
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _