Bio
Range
Summary
Bio::Range - Pure perl RangeI implementation
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
$range = new Bio::Range(-start=>10, -end=>30, -strand=>+1);
$r2 = new Bio::Range(-start=>15, -end=>200, -strand=>+1);
print join(', ', $range->union($r2)), "\n";
print join(', ', $range->intersection($r2)), "\n";
print $range->overlaps($r2), "\n";
print $range->contains($r2), "\n";
Description
This provides a pure perl implementation of the BioPerl range
interface.
Ranges are modeled as having (start, end, length, strand). They use
Bio-coordinates - all points >= start and <= end are within the
range. End is always greater-than or equal-to start, and length is
greather than or equal to 1. The behaviour of a range is undefined if
ranges with negative numbers or zero are used.
So, in summary:
length = end - start + 1
end >= start
strand = (-1 | 0 | +1)
Methods
Methods description
Title : new Usage : $range = Bio::Range->new(-start => 100, -end=> 200, -strand = +1); Function: generates a new Bio::Range Returns : a new range Args : -strand (defaults to 0) and any two of (-start, -end, -length), the third will be calculated |
Title : unions Usage : @unions = Bio::Range->unions(@ranges); Function: generate a list of non-intersecting Bio::Range objects from a list of Bio::Range objects which may intersect Returns : a list of Bio::Range objects Args : a list of Bio::Range objects |
Title : start Function : return or set the start co-ordinate Example : $s = $range->start(); $range->start(7); Returns : the value of the start co-ordinate Args : optionally, the new start co-ordinate Overrides: Bio::RangeI::start |
Title : end Function : return or set the end co-ordinate Example : $e = $range->end(); $range->end(2000); Returns : the value of the end co-ordinate Args : optionally, the new end co-ordinate Overrides: Bio::RangeI::end |
Title : strand Function : return or set the strandedness Example : $st = $range->strand(); $range->strand(-1); Returns : the value of the strandedness (-1, 0 or 1) Args : optionally, the new strand - (-1, 0, 1) or (-, ., +). Overrides: Bio::RangeI::Strand |
Title : length Function : returns the length of this range Example : $length = $range->length(); Returns : the length of this range, equal to end - start + 1 Args : if you attempt to set the length an exception will be thrown Overrides: Bio::RangeI::Length |
Title : toString Function: stringifies this range Example : print $range->toString(), "\n"; Returns : a string representation of this range |
Methods code
sub new
{ my ($caller, @args) = @_;
my $self = $caller->SUPER::new(@args);
my ($strand, $start, $end, $length) =
$self->_rearrange([qw(STRAND
START
END
LENGTH
)],@args);
$self->strand($strand || 0);
if(defined $start ) {
$self->start($start);
if(defined $end) {
$self->end($end);
} elsif(defined $length) {
$self->end($self->start()+ $length - 1);
}
} elsif(defined $end && defined $length ) {
$self->end($end);
$self->start($self->end() - $length + 1);
}
return $self;} |
sub unions
{ my ($class,@i) = @_;
my $i = 0;
my %i = map { $i++ => $_ } @i;
my $lastsize = scalar(keys %i);
do {
foreach my $j (sort { $i{$a}->start <=> $i{$b}->start } keys %i){
foreach my $k (sort { $i{$a}->start <=> $i{$b}->start } keys %i){
next unless $i{$j};
next if $i{$k}->end < $i{$j}->start;
last if $i{$k}->start > $i{$j}->end;
if($i{$j}->overlaps($i{$k})){
my($start,$end,$strand) = $i{$j}->union($i{$k});
delete($i{$k});
$i{$j} = Bio::Range->new( -start => $start , -end => $end , -strand => $strand );
}
}
}
goto DONE if scalar(keys %i) == $lastsize;
$lastsize = scalar(keys %i);
} while(1);
DONE:
return values %i;} |
sub start
{ my ($self,$value) = @_;
if( defined $value) {
$self->throw("'$value' is not an integer.\n")
unless $value =~ /^[-+]?\d+$/;
$self->{'start'} = $value;
}
return $self->{'start'};} |
sub end
{
my ($self,$value) = @_;
if( defined $value) {
$self->throw("'$value' is not an integer.\n")
unless $value =~ /^[-+]?\d+$/;
$self->{'end'} = $value;
}
return $self->{'end'};} |
sub strand
{ my $self = shift;
if(@_) {
my $val = shift;
$val =~ tr/+/1/;
$val =~ tr/-/-1/;
$val =~ tr/./0/;
if($val == -1 || $val == 0 || $val == 1 ) {
$self->{'strand'} = $val;
}
}
return $self->{'strand'};} |
sub length
{ my $self = shift;
if(@_) {
confess ref($self), "->length() is read-only";
}
return $self->end() - $self->start() + 1;} |
sub toString
{ my $self = shift;
return "(${\$self->start}, ${\$self->end}) strand=${\$self->strand}";} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the web:
http://bugzilla.open-bio.org/
| AUTHOR - Heikki Lehvaslaiho | Top |
Email heikki-at-bioperl-dot-org
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
| Member variable access | Top |
These methods let you get at and set the member variables
These methods return true or false.
$range->overlaps($otherRange) && print "Ranges overlap\n";
Title : overlaps
Usage : if($r1->overlaps($r2)) { do stuff }
Function : tests if $r2 overlaps $r1
Args : a range to test for overlap with
Returns : true if the ranges overlap, false otherwise
Inherited: Bio::RangeI
Title : contains
Usage : if($r1->contains($r2) { do stuff }
Function : tests wether $r1 totally contains $r2
Args : a range to test for being contained
Returns : true if the argument is totally contained within this range
Inherited: Bio::RangeI
Title : equals
Usage : if($r1->equals($r2))
Function : test whether $r1 has the same start, end, length as $r2
Args : a range to test for equality
Returns : true if they are describing the same range
Inherited: Bio::RangeI
These methods do things to the geometry of ranges, and return
triplets (start, end, strand) from which new ranges could be built.
Title : intersection
Usage : ($start, $stop, $strand) = $r1->intersection($r2)
Function : gives the range that is contained by both ranges
Args : a range to compare this one to
Returns : nothing if they do not overlap, or the range that they do overlap
Inherited: Bio::RangeI::intersection
Title : union
Usage : ($start, $stop, $strand) = $r1->union($r2);
: ($start, $stop, $strand) = Bio::Range->union(@ranges);
Function : finds the minimal range that contains all of the ranges
Args : a range or list of ranges
Returns : the range containing all of the ranges
Inherited: Bio::RangeI::union