File: _MatrixSetIterator.pm

package info (click to toggle)
libtfbs-perl 0.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,608 kB
  • ctags: 725
  • sloc: perl: 6,980; ansic: 699; makefile: 557; sh: 9
file content (58 lines) | stat: -rwxr-xr-x 1,514 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package TFBS::_Iterator::_MatrixSetIterator;

use vars '@ISA';
use strict;
use Carp;
use TFBS::_Iterator;

@ISA = qw(TFBS::_Iterator);


sub _sort  {
    my ($self, $sort_by) = @_;
    $sort_by or $sort_by = $self->{_sort_by} or  $sort_by = 'name';

    # we can sort by name, start, end, score
    
    my %sort_fn = 
	(class => sub  { $a->class() cmp $b->class() 
			     ||
			 $a->name()  cmp $b->name()
			     ||
			 $a->ID()    cmp $b->ID()   
		       },

	 id   => sub  { $a->ID() cmp $b->ID()   
		       },
	 ID   => sub  { $a->ID() cmp $b->ID()   
		       },

	 name  => sub  { $a->name() cmp $b->name() ||
			 $a->class() cmp $b->class()     ||
			 $a->ID()    cmp $b->ID()   
		       },

        species  => sub  { $a->tag('species') cmp $b->tag('species') ||
			 $a->class() cmp $b->class()     ||
			 $a->ID()    cmp $b->ID()   
		       },

        
	 total_ic => sub {  $b->total_ic()   <=> $a->total_ic()
			     ||
			  $a->name() cmp $b->name()
		      }
	);
			 
    if (defined (my $sort_function = $sort_fn{lc $sort_by})) {
	$self->{'_iterator_array_ref'} =
	    [ sort $sort_function @{$self->{'_orig_array_ref'}} ];
    }
    else  {
            #order by tag derived value
                $self->{'_iterator_array_ref'}=   [ sort { $a->tag($self->{_sort_by}) cmp $b->tag( $self->{_sort_by}) ||
			 $a->class() cmp $b->class()     ||
			 $a->ID()    cmp $b->ID()   
		       } @{$self->{'_orig_array_ref'}} ] || $self->throw("Cannot sort ".ref($self)." object by '$sort_by'.");
    }
}