| 1 | package Bio::Gonzales::Range::Cluster; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Bio::Gonzales::Range::Util qw/overlaps/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.058'; # VERSION | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | has clusters => ( is => 'rw', default => sub { [] }, clearer => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | has _current_cluster => ( is => 'rw', default => sub { [] }, clearer => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | has _last_range => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 17 | 1 | has overlap_config => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 18 | 1 | has _current_max_end => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub add_next_range { | ||||||||||||||||||||||||||||
| 21 | 35 | ▶ | my ( $self, $next_range ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add_next_range: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 35 | ▶ | confess 'supplied range has not start and end coordinates' unless ( @$next_range >= 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 34 | ▶ | confess 'supplied range\'s start is bigger than end coordinate' if ( $next_range->[0] > $next_range->[1] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 33 | my $current_cluster = $self->_current_cluster; | |||||||||||||||||||||||||||
| 27 | 33 | ▶ | unless ( $self->_last_range ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 3 | $self->_current_cluster( [$next_range] ); | |||||||||||||||||||||||||||
| 29 | 3 | $self->_last_range($next_range); | |||||||||||||||||||||||||||
| 30 | 3 | return $self; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 30 | my $range = $self->_last_range; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 30 | my $max_end = $self->_current_max_end; | |||||||||||||||||||||||||||
| 36 | 30 | ▶ | unless ( defined $max_end ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 2 | $max_end = $range->[1]; | |||||||||||||||||||||||||||
| 38 | 2 | $self->_current_max_end($max_end); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 30 | ▶ | if ( $next_range->[0] <= $max_end | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next_range->[0] <= $max_end or overlaps($range, $next_range, $self->overlap_config)
MC/DC100%2/2
$next_range->[0] <= $max_end or overlaps($range, $next_range, $self->overlap_config)
$next_range->[0] <= $max_end
overlaps($range, $next_range, $self->overlap_config)
Truth table100%3/3
A or B
A= $next_range->[0] <= $max_endB= overlaps($range, $next_range, $self->overlap_config)
| |||||||||||||||||||||||||||||
| 41 | || overlaps( $range, $next_range, $self->overlap_config ) ) | ||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 25 | push @$current_cluster, $next_range; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 25 | ▶ | $self->_current_max_end( $next_range->[1] ) if ( $next_range->[1] > $max_end ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 25 | $self->_last_range($next_range); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 5 | push @{ $self->clusters }, $current_cluster; | |||||||||||||||||||||||||||
| 50 | 5 | $self->_current_cluster( [$next_range] ); | |||||||||||||||||||||||||||
| 51 | 5 | $self->_last_range($next_range); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 30 | return $self; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub pick_up_clusters { | ||||||||||||||||||||||||||||
| 58 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
pick_up_clusters: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | my $clusters = $self->clusters; | |||||||||||||||||||||||||||
| 61 | 2 | ▶ | if ( @$clusters > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 2 | $self->clusters( [] ); | |||||||||||||||||||||||||||
| 63 | 2 | return $clusters; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub finish { | ||||||||||||||||||||||||||||
| 69 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
finish: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | #add the current cluster, but only if it has elements | ||||||||||||||||||||||||||||
| 72 | #special case is a new object with finish called immediately | ||||||||||||||||||||||||||||
| 73 | 2 | push @{ $self->clusters }, $self->_current_cluster | |||||||||||||||||||||||||||
| 74 | 3 | ▶ | if ( @{ $self->_current_cluster } > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 3 | return $self; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 NAME | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Bio::Gonzales::Range::Cluster - cluster sorted ranges iteratively | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | my $cr = Bio::Gonzales::Range::Cluster->new; | ||||||||||||||||||||||||||||
| 89 | my @ranges = ( [ 417, '575', 7991 ], [ 537, '829', 7992 ], [ 839, '901', 7993 ], ); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | my @sorted_ranges = sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } @ranges; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | for my $r (@sorted_ranges) { | ||||||||||||||||||||||||||||
| 94 | $cr->add_next_range($r); | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | my $result = $cr->finish->clusters; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 METHODS | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =over 4 | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =item B<< $cr = $cr->finish() >> | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =item B<< $cr->overlap_config >> | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =item B<< $cr->clusters >> | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item B<< $clusters_array_ref = $cr->pick_up_clusters() >> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =item B<< $cr->add_next_range([ $from, $to, @whatever]) >> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =back | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | jw bargsten, C<< <jwb at cpan dot org> >> | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||||