Bio::Matrix PhylipDist
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::Matrix::PhylipDist - A Phylip Distance Matrix object
Package variables
No package variables defined.
Included modules
Bio::Matrix::MatrixI
Bio::Root::Root
Inherit
Bio::Matrix::MatrixI Bio::Root::Root
Synopsis
  use Bio::Tools::Phylo::Phylip::ProtDist;
  my $dist = Bio::Tools::Phylo::Phylip::ProtDist->new(
    -file=>"protdist.out",
    -program=>"ProtDist");
  #or
   my $dist = Bio::Tools::Phylo::Phylip::ProtDist->new(
    -fh=>"protdist.out",
    -program=>"ProtDist");

  #get specific entries
  my $distance_value = $dist->get_entry('ALPHA','BETA');
  my @columns        = $dist->get_column('ALPHA');
  my @rows           = $dist->get_row('BETA');
  my @diagonal       = $dist->get_diagonal();

  #print the matrix in phylip numerical format
  print $dist->print_matrix;
Description
Simple object for holding Distance Matrices generated by the following Phylip programs:
1) dnadist
2) protdist
3) restdist
It currently handles parsing of the matrix without the data output option.
    5
Alpha          0.00000  4.23419  3.63330  6.20865  3.45431
Beta           4.23419  0.00000  3.49289  3.36540  4.29179
Gamma          3.63330  3.49289  0.00000  3.68733  5.84929
Delta          6.20865  3.36540  3.68733  0.00000  4.43345
Epsilon        3.45431  4.29179  5.84929  4.43345  0.00000
Methods
newDescriptionCode
get_entryDescriptionCode
get_rowDescriptionCode
get_columnDescriptionCode
get_diagonalDescriptionCode
print_matrixDescriptionCode
_matrixDescriptionCode
namesDescriptionCode
programDescriptionCode
_valuesDescriptionCode
matrix_idDescriptionCode
matrix_nameDescriptionCode
column_headerDescriptionCode
row_headerDescriptionCode
column_num_for_nameDescriptionCode
row_num_for_nameDescriptionCode
num_rowsDescriptionCode
num_columnsDescriptionCode
row_namesDescriptionCode
column_namesDescriptionCode
Methods description
newcode    nextTop
 Title   : new
 Usage   : my $family = Bio::Matrix::PhylipDist->new(-file=>"protdist.out",
                                                     -program=>"protdist");
 Function: Constructor for PhylipDist Object
 Returns : Bio::Matrix::PhylipDist
get_entrycodeprevnextTop
 Title   : get_entry
 Usage   : $matrix->get_entry();
 Function: returns a particular entry 
 Returns : a float
 Arguments:  string id1, string id2
get_rowcodeprevnextTop
 Title   : get_row
 Usage   : $matrix->get_row('ALPHA');
 Function: returns a particular row 
 Returns : an array of float
 Arguments:  string id1
get_columncodeprevnextTop
 Title   : get_column
 Usage   : $matrix->get_column('ALPHA');
 Function: returns a particular column 
 Returns : an array of floats 
 Arguments:  string id1
get_diagonalcodeprevnextTop
 Title   : get_diagonal
 Usage   : $matrix->get_diagonal();
 Function: returns the diagonal of the matrix
 Returns : an array of float
 Arguments:  string id1
print_matrixcodeprevnextTop
 Title   : print_matrix
 Usage   : $matrix->print_matrix();
 Function: returns a string of the matrix in phylip format 
 Returns : a string
 Arguments:
_matrixcodeprevnextTop
 Title   : _matrix
 Usage   : $matrix->_matrix();
 Function: get/set for hash reference of the pointers
           to the value matrix 
 Returns : hash reference 
 Arguments: hash reference
namescodeprevnextTop
 Title   : names
 Usage   : $matrix->names();
 Function: get/set for array ref of names of sequences
 Returns : an array reference 
 Arguments: an array reference
programcodeprevnextTop
 Title   : program
 Usage   : $matrix->program();
 Function: get/set for the program name generating this 
           matrix
 Returns : string
 Arguments: string
_valuescodeprevnextTop
 Title   : _values
 Usage   : $matrix->_values();
 Function: get/set for array ref of the matrix containing
           distance values 
 Returns : an array reference 
 Arguments: an array reference
matrix_idcodeprevnextTop
 Title   : matrix_id
 Usage   : my $id = $matrix->matrix_id
 Function: Get/Set the matrix ID
 Returns : scalar value
 Args    : [optional] new id value to store
matrix_namecodeprevnextTop
 Title   : matrix_name
 Usage   : my $name = $matrix->matrix_name();
 Function: Get/Set the matrix name
 Returns : scalar value
 Args    : [optional] new matrix name value
column_headercodeprevnextTop
 Title   : column_header
 Usage   : my $name = $matrix->column_header(0)
 Function: Gets the column header for a particular column number
 Returns : string
 Args    : integer
row_headercodeprevnextTop
 Title   : row_header
 Usage   : my $name = $matrix->row_header(0)
 Function: Gets the row header for a particular row number
 Returns : string
 Args    : integer
column_num_for_namecodeprevnextTop
 Title   : column_num_for_name
 Usage   : my $num = $matrix->column_num_for_name($name)
 Function: Gets the column number for a particular column name
 Returns : integer
 Args    : string
row_num_for_namecodeprevnextTop
 Title   : row_num_for_name
 Usage   : my $num = $matrix->row_num_for_name($name)
 Function: Gets the row number for a particular row name
 Returns : integer
 Args    : string
num_rowscodeprevnextTop
 Title   : num_rows
 Usage   : my $rowcount = $matrix->num_rows;
 Function: Get the number of rows
 Returns : integer
 Args    : none
num_columnscodeprevnextTop
 Title   : num_columns
 Usage   : my $colcount = $matrix->num_columns
 Function: Get the number of columns
 Returns : integer
 Args    : none
row_namescodeprevnextTop
 Title   : row_names
 Usage   : my @rows = $matrix->row_names
 Function: The names of all the rows
 Returns : array in array context, arrayref in scalar context
 Args    : none
column_namescodeprevnextTop
 Title   : column_names
 Usage   : my @columns = $matrix->column_names
 Function: The names of all the columns
 Returns : array in array context, arrayref in scalar context
 Args    : none
Methods code
newdescriptionprevnextTop
sub new {
    my ($class,@args) = @_;
    my $self = $class->SUPER::new(@args);
    my ($matrix,$values, $names,
	$program,$matname,
	$matid) = $self->_rearrange([qw(MATRIX VALUES 
					NAMES PROGRAM
					MATRIX_NAME
					MATRIX_ID
					  )],@args);
    
    ($matrix && $values && $names) || 
	$self->throw("Need matrix, values, and names fields all provided!");

    $program && $self->matrix_name($program) if defined $program;
    
    $self->_matrix($matrix) if ref($matrix) =~ /HASH/i;
    $self->_values($values) if ref($values) =~ /ARRAY/i;
    $self->names($names) if ref($names) =~ /ARRAY/i;

    $self->matrix_name($matname) if defined $matname;
    $self->matrix_id  ($matid)   if defined $matid;

    return $self;
}
get_entrydescriptionprevnextTop
sub get_entry {
  my ($self,$row,$column) = @_;
  $row && $column || $self->throw("Need at least 2 ids");
  my %matrix = %{$self->_matrix};
  my @values = @{$self->_values};
  if(ref $matrix{$row}{$column}){
      my ($i,$j) = @{$matrix{$row}{$column}};
      return $values[$i][$j];
  }
  return;
}
get_rowdescriptionprevnextTop
sub get_row {
    my ($self,$row) = @_;
    $row || $self->throw("Need at least a row id");

    my %matrix = %{$self->_matrix};
    my @values = @{$self->_values};
    my @names = @{$self->names};
    $matrix{$row} || return;
    my ($val) = values %{$matrix{$row}};
    my $row_pointer = $val->[0];
    my $index = scalar(@names)-1;
    return @{$values[$row_pointer]}[0..$index];
}
get_columndescriptionprevnextTop
sub get_column {
    my ($self,$column) = @_;
    $column || $self->throw("Need at least a column id");

    my %matrix = %{$self->_matrix};
    my @values = @{$self->_values};
    my @names = @{$self->names}; 
    $matrix{$column} || return ();
    my ($val) = values %{$matrix{$column}};
    my $row_pointer = $val->[0];
    my @ret;
    for(my $i=0; $i < scalar(@names); $i++) {
	push @ret, $values[$i][$row_pointer];
    }
    return @ret;
}
get_diagonaldescriptionprevnextTop
sub get_diagonal {
  my ($self) = @_;
  my %matrix = %{$self->_matrix};
  my @values = @{$self->_values};
  my @return;
  foreach my $name (@{$self->names}){
    my ($i,$j) = @{$matrix{$name}{$name}};
    push @return,$values[$i][$j];
  }
  return @return;
}
print_matrixdescriptionprevnextTop
sub print_matrix {
  my ($self) = @_;
  my @names = @{$self->names};
  my @values = @{$self->_values};
  my %matrix = %{$self->_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";
  }
  return $str;
}
_matrixdescriptionprevnextTop
sub _matrix {
  my ($self,$val) = @_;
  if($val){
    $self->{'_matrix'} = $val;
  }
  return $self->{'_matrix'};
}
namesdescriptionprevnextTop
sub names {
  my ($self,$val) = @_;
  if($val){
    $self->{'_names'} = $val;
  }
  return $self->{'_names'};
}
programdescriptionprevnextTop
sub program {
  my ($self) = shift;
  return $self->matrix_name(@_);
}
_valuesdescriptionprevnextTop
sub _values {
  my ($self,$val) = @_;
  if($val){
    $self->{'_values'} = $val;
  }
  return $self->{'_values'};
}
matrix_iddescriptionprevnextTop
sub matrix_id {
   my $self = shift;
   return $self->{'_matid'} = shift if @_;
   return $self->{'_matid'};
}
matrix_namedescriptionprevnextTop
sub matrix_name {
   my $self = shift;
   return $self->{'_matname'} = shift if @_;
   return $self->{'_matname'};
}
column_headerdescriptionprevnextTop
sub column_header {
    my ($self,$num) = @_;
    my @coln = $self->column_names;
    return $coln[$num];
}
row_headerdescriptionprevnextTop
sub row_header {
    my ($self,$num) = @_;
    my @rown = $self->row_names;
   return $rown[$num];
}
column_num_for_namedescriptionprevnextTop
sub column_num_for_name {
   my ($self,$name) = @_;
   my $ct = 0;
   foreach my $n ( $self->column_names ) {
       return $ct if $n eq $name;
       $ct++;
   }
   return undef;
}
row_num_for_namedescriptionprevnextTop
sub row_num_for_name {
   my ($self,$name) = @_;
   my $ct = 0;
   foreach my $n ( $self->row_names ) {
       return $ct if $n eq $name;
       $ct++;
   }
}
num_rowsdescriptionprevnextTop
sub num_rows {
return scalar @{shift->names}
}
num_columnsdescriptionprevnextTop
sub num_columns {
   return scalar @{shift->names};
}
row_namesdescriptionprevnextTop
sub row_names {
return @{shift->names}
}
column_namesdescriptionprevnextTop
sub column_names {
return @{shift->names}
}
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 one
of the Bioperl mailing lists. Your participation is much appreciated.
  bioperl-l@bioperl.org              - General discussion
  http://bio.perl.org/MailList.html  - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via email
or the web:
  bioperl-bugs@bioperl.org
  http://bugzilla.bioperl.org/
AUTHOR - Shawn HoonTop
Email shawnh@fugu-sg.org
CONTRIBUTORSTop
Jason Stajich, jason-at-bioperl-dot-org
APPENDIXTop
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a "_".
Bio::Matrix::MatrixI implementationTop