Bio-ViennaNGS
view release on metacpan or search on metacpan
lib/Bio/ViennaNGS/Bed.pm view on Meta::CPAN
use Bio::ViennaNGS;
use Carp;
use Moose;
use namespace::autoclean;
use Data::Dumper;
use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");
extends 'Bio::ViennaNGS::Feature';
has '+strand' => (
required => 1,
);
has 'thickStart' => (
is => 'rw',
isa => 'Int',
predicate => 'has_thickStart',
);
has 'thickEnd' => (
is => 'rw',
isa => 'Int',
predicate => 'has_thickEnd',
);
has 'itemRgb' => (
is => 'rw',
isa => 'Str',
lazy => 1,
default => '0',
);
has 'blockCount' => (
is => 'rw',
isa => 'Int',
predicate => 'has_blockCount',
);
has 'blockSizes' => (
is => 'rw',
isa => 'Value',
);
has 'blockStarts' => (
is => 'rw',
isa => 'Value',
);
has 'length' => (
is => 'rw',
isa => 'Int',
builder => '_build_length',
lazy => 1,
predicate => 'has_length',
);
sub _build_length {
my ($self) = @_;
my ($i,$len) = (0)x2;
my $this_function = (caller(0))[3];
my @blockSizes = split (/,/ ,$self->blockSizes);
my $bc = scalar @blockSizes;
croak "ERROR [$this_function] invalid blockSount in BED12 line"
unless ($bc == $self->blockCount);
for ($i=0;$i<$bc;$i++){
$len += $blockSizes[$i];
}
$self->length($len);
}
sub as_bed_line {
my ($self,$n) = @_;
my $this_function = (caller(0))[3];
croak "ERROR [$this_function] no argument provided"
unless (defined $n);
croak "ERROR [$this_function] argument of as_bed_line() must be 6 or 12"
unless ( ($n == 6) | ($n == 12) );
my $bed6= join ("\t",
$self->chromosome,
$self->start,
$self->end,
$self->name,
$self->score,
$self->strand,
);
my $bed12 = join ("\t", $bed6,
$self->thickStart,
$self->thickEnd,
$self->itemRgb,
$self->blockCount,
$self->blockSizes,
$self->blockStarts,
);
if ($n ==6){
return $bed6;
}
else{
return $bed12;
}
}
# TODO:
# sub from_FeatureLine()
# sub to_FeatureLine()
__PACKAGE__->meta->make_immutable;
1;
__END__
=head1 NAME
Bio::ViennaNGS::Bed - Object-oriented interface for manipulation of
genomic interval data in BED format
=head1 SYNOPSIS
use Bio::ViennaNGS::Bed;
my $bedobject = Bio::ViennaNGS::Bed->new();
# compute the length of a BED12 block
$bedobject->_build_length();
# dump an object as BED12 line
$bedobject->as_bed_line(12);
=head1 DESCRIPTION
This module provides a L<Moose> interface for storage and manipulation
of genomic interval data. It is primarily used as a convenience
wrapper for BED data with more generic L<Bio::ViennaNGS> classes for
( run in 1.132 second using v1.01-cache-2.11-cpan-6de40a662fe )