Bio-ViennaNGS

 view release on metacpan or  search on metacpan

lib/Bio/ViennaNGS/FeatureInterval.pm  view on Meta::CPAN

# -*-CPerl-*-
# Last changed Time-stamp: <2018-11-25 21:40:36 mtw>

package Bio::ViennaNGS::FeatureInterval;

use Bio::ViennaNGS;
use namespace::autoclean;
use Carp;
use Moose;
use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");

has 'chromosome' => (
		     is  => 'rw',
		     isa => 'Str',
		     required => 1,
		     predicate => 'has_chromosome',
		    );

has 'start' => (
		is      => 'rw',
		isa     => 'Int',
		required => 1,
		predicate => 'has_start',
	       );

has 'end' => (
	      is      => 'rw',
	      isa     => 'Int',
	      required => 1,
	      predicate => 'has_end',
	     );

has '_length' => ( # length of interval
		  is => 'rw',
		  isa => 'Int',
		  predicate => 'length',
		  init_arg => undef, # make this unsettable via constructor
		 );

with 'Bio::ViennaNGS::FeatureBase';

sub BUILD { # call a parser method, depending on $self->instanceOf
  my $self = shift;
  my $this_function = (caller(0))[3];
  my $len = undef;

  if ($self->base == 0){
    confess "ERROR [$this_function] \$self->end must be > than \$self->start for 0-based start coordinates [==> start ".eval($self->start)." end ".eval($self->end)." <==]"
      unless ($self->end > $self->start);
    $len = eval($self->end)-eval($self->start)-1;
    $self->_length($len);
  }
  else {
    confess "ERROR [$this_function] \$self->end must be >= than \$self->start for 0-based start coordinates [==> start ".eval($self->start)." end ".eval($self->end)." <==]"
      unless ($self->end >= $self->start);
    $len = $self->end-$self->start;
    $self->_length($len);
  }
}

sub dump {
  my $self = shift;
  print join("\t",
	     $self->chromosome,
	     $self->start,
	     $self->end),
	       "\n";
}

no Moose;

1;

__END__

=head1 NAME

Bio::ViennaNGS::FeatureInterval - A Moose class for unstranded, elementary
genomic intervals.

=head1 SYNOPSIS

  use Bio::ViennaNGS::FeatureInterval;

  my $obj = Bio::ViennaNGS::FeatureInterval->new(chromosome => "chr1",
                                                 start => "1200",
                                                 end => "4300",
                                                );
  my $len = $obj->_length();
  $obj->dump();

=head1 DESCRIPTION

This module provides an object-oriented interface for storing
unstranded, elementary genomic intervals characterized via chromosome,
start and end position. As such, it can be regarded a simple wrapper
for BED3 elements.

This is the base class for L<Bio::ViennaNGS::MinimalFeature>.

=head1 METHODS

=over



( run in 2.165 seconds using v1.01-cache-2.11-cpan-df04353d9ac )