GenOO

 view release on metacpan or  search on metacpan

lib/GenOO/Region.pm  view on Meta::CPAN

# POD documentation - main docs before the code

=head1 NAME

GenOO::Region - Role that represents a region on a reference sequence

=head1 SYNOPSIS

    This role when consumed requires specific attributes and provides
    methods that correspond to a region on a reference sequence.

=head1 DESCRIPTION

    A region object is an area on another reference sequence. It has a
    specific start and stop position on the reference and a specific 
    direction (strand). It has methods that combine the direction with
    the positional information a give positions for the head or the tail
    of the region. It also offers methods that calculate distances or
    overlaps with other object that also consume the role.

=head1 EXAMPLES

    # Get the location information on the reference sequence
    $obj_with_role->start;   # 10
    $obj_with_role->stop;    # 20
    $obj_with_role->strand;  # -1
    
    # Get the head position on the reference sequence
    $obj_with_role->head_position;  # 20

=cut

# Let the code begin...

package GenOO::Region;
$GenOO::Region::VERSION = '1.5.2';

#######################################################################
#######################   Load External modules   #####################
#######################################################################
use Modern::Perl;
use Moose::Role;


#######################################################################
#######################   Required attributes   #######################
#######################################################################
requires qw(strand rname start stop copy_number);


#######################################################################
#######################   Interface attributes   ######################
#######################################################################
has 'length' => (
	is        => 'ro',
	builder   => '_calculate_length',
	init_arg  => undef,
	lazy      => 1,
);


#######################################################################
########################   Interface Methods   ########################
#######################################################################
sub location {
	my ($self) = @_;
	
	return $self->rname . ':' . $self->start . '-' . $self->stop . ':' . $self->strand;
}

sub strand_symbol {
	my ($self) = @_;
	
	return undef if !defined $self->strand;
	
	if ($self->strand == 1) {
		return '+';
	}
	elsif ($self->strand == -1) {
		return '-';
	}
	return undef;
}

sub head_position {
	my ($self) = @_;
	
	if ($self->strand == 1) {
		return $self->start;
	}
	elsif ($self->strand == -1) {
		return $self->stop;
	}
	else {
		return undef;
	}
}

sub tail_position {
	my ($self) = @_;
	



( run in 0.707 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )