Bio::DOOP::Util::Sort - Sort an array of arrays


Bio-DOOP-DOOP documentation Contained in the Bio-DOOP-DOOP distribution.

Index


Code Index:

NAME

Top

Bio::DOOP::Util::Sort - Sort an array of arrays

VERSION

Top

Version 0.3

SYNOPSIS

Top

  @result = $mofext->get_results;
  $sorting = Bio::DOOP::Util::Sort->new($db,\results);
  @sorted_result = $sorting->sort_by_column(1,"asc"); 

DESCRIPTION

Top

This class can sort any type of array of arrays. It can be used to sort the mofext or fuzznuc results, but can sort other data.

AUTHORS

Top

Tibor Nagy, Godollo, Hungary and Endre Sebestyen, Martonvasar, Hungary

METHODS

Top

new

Creates a Sort class from an array of arrays type data structure.

  $mofext_sort = Bio::DOOP::Util::Sort->new($db,\@mofext_result);

sort_by_column

Sort a given array by column. (Warning, the first column is zero!)

Return type: sorted array of arrays

  @ret = $mofext_sort->sort_by_column(0,"asc");


Bio-DOOP-DOOP documentation Contained in the Bio-DOOP-DOOP distribution.
package Bio::DOOP::Util::Sort;

use strict;
use warnings;

our $VERSION = '0.3';

sub new {
   my $self                = {};
   my $dummy               = shift;
   my $db                  = shift;
   my $array               = shift;

   $self->{ARRAY}          = $array;
   $self->{DB}             = $db;

   bless $self;
   return($self);
}

sub sort_by_column {
   my $self                = shift;
   my $column              = shift;
   my $orient              = shift;
   my @ret;
   
   if( ($orient eq "1") || ($orient eq "asc") || ($orient eq "ascending")){
       @ret = sort { $$a[$column] <=> $$b[$column] } @{$self->{ARRAY}};
   }
   else{
       @ret = sort { $$b[$column] <=> $$a[$column] } @{$self->{ARRAY}};
   }

   
}
1;