Debian Codegraph @

TFBS/_Iterator/_MatrixSetIterator.pm

raw symbols SCIP
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 #
12 # Changed name field sorts to case insensitive which results in a more
13 # intuitive name sort order, at least for the JASPAR Web site
14 # DJA 2015/09/16
15 #
16 sub _sort {
17 my ($self, $sort_by) = @_;
18 $sort_by or $sort_by = $self->{_sort_by} or $sort_by = 'name';
19
20 # we can sort by name, start, end, score
21
22 my %sort_fn =
23 (class => sub {
24 $a->class() cmp $b->class()
25 || uc $a->name() cmp uc $b->name()
26 || $a->ID() cmp $b->ID()
27 },
28
29 id => sub {
30 $a->ID() cmp $b->ID()
31 },
32 ID => sub {
33 $a->ID() cmp $b->ID()
34 },
35
36 name => sub {
37 uc $a->name() cmp uc $b->name()
38 || $a->class() cmp $b->class()
39 || $a->ID() cmp $b->ID()
40 },
41
42 species => sub {
43 $a->tag('species') cmp $b->tag('species')
44 || $a->class() cmp $b->class()
45 || $a->ID() cmp $b->ID()
46 },
47
48
49 total_ic => sub {
50 $b->total_ic() <=> $a->total_ic()
51 || uc $a->name() cmp uc $b->name()
52 }
53 );
54
55 if (defined (my $sort_function = $sort_fn{lc $sort_by})) {
56 $self->{'_iterator_array_ref'} =
57 [ sort $sort_function @{$self->{'_orig_array_ref'}} ];
58 }
59 else {
60 #order by tag derived value
61 $self->{'_iterator_array_ref'}= [ sort { $a->tag($self->{_sort_by}) cmp $b->tag( $self->{_sort_by}) ||
62 $a->class() cmp $b->class() ||
63 $a->ID() cmp $b->ID()
64 } @{$self->{'_orig_array_ref'}} ] || $self->throw("Cannot sort ".ref($self)." object by '$sort_by'.");
65 }
66 }