Debian Codegraph @

blib/lib/TFBS/_Iterator/_MatrixSetIterator.pm

raw
1 package TFBS::_Iterator::_MatrixSetIterator;
2
3 use vars '@ISA';
4 use strict;
5 use Carp;
6 use TFBS::_Iterator;
7
8 @ISA = qw(TFBS::_Iterator);
9
10
11 sub _sort {
12 my ($self, $sort_by) = @_;
13 $sort_by or $sort_by = $self->{_sort_by} or $sort_by = 'name';
14
15 # we can sort by name, start, end, score
16
17 my %sort_fn =
18 (class => sub { $a->class() cmp $b->class()
19 ||
20 $a->name() cmp $b->name()
21 ||
22 $a->ID() cmp $b->ID()
23 },
24
25 id => sub { $a->ID() cmp $b->ID()
26 },
27 ID => sub { $a->ID() cmp $b->ID()
28 },
29
30 name => sub { $a->name() cmp $b->name() ||
31 $a->class() cmp $b->class() ||
32 $a->ID() cmp $b->ID()
33 },
34
35 species => sub { $a->tag('species') cmp $b->tag('species') ||
36 $a->class() cmp $b->class() ||
37 $a->ID() cmp $b->ID()
38 },
39
40
41 total_ic => sub { $b->total_ic() <=> $a->total_ic()
42 ||
43 $a->name() cmp $b->name()
44 }
45 );
46
47 if (defined (my $sort_function = $sort_fn{lc $sort_by})) {
48 $self->{'_iterator_array_ref'} =
49 [ sort $sort_function @{$self->{'_orig_array_ref'}} ];
50 }
51 else {
52 #order by tag derived value
53 $self->{'_iterator_array_ref'}= [ sort { $a->tag($self->{_sort_by}) cmp $b->tag( $self->{_sort_by}) ||
54 $a->class() cmp $b->class() ||
55 $a->ID() cmp $b->ID()
56 } @{$self->{'_orig_array_ref'}} ] || $self->throw("Cannot sort ".ref($self)." object by '$sort_by'.");
57 }
58 }