Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
MetaGeneView/BedLine.pm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
130 lines (110 sloc)
3.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package BedLine; | |
use Moose; | |
use MooseX::ClassAttribute; | |
has 'chrom' => (is => 'rw', isa => 'Str'); | |
has 'chromStart' => (is => 'rw', isa => 'Int'); | |
has 'chromEnd' => (is => 'rw', isa => 'Int'); | |
has 'name' => (is => 'rw', isa => 'Str'); | |
has 'score' => (is => 'rw', isa => 'Int'); | |
has 'strand' => (is => 'rw', isa => 'Str'); | |
has 'thickStart' => (is => 'rw', isa => 'Int'); | |
has 'thickEnd' => (is => 'rw', isa => 'Int'); | |
has 'itemRgb' => (is => 'rw', isa => 'Str'); | |
has 'blocks' => (is => 'rw', isa => 'Int'); | |
has 'blockSizes' => (is => 'rw', isa => 'ArrayRef'); | |
has 'blockStarts' => (is => 'rw', isa => 'ArrayRef'); | |
has 'cdsStart' => (is => 'rw', isa => 'Int'); | |
has 'cdsEnd' => (is => 'rw', isa => 'Int'); | |
has 'cdsSpan' => (is => 'rw', isa => 'Int'); | |
has 'geneSpan' => (is => 'rw', isa => 'Int'); | |
has 'exonStart' => (is => 'rw', isa => 'ArrayRef'); | |
has 'exonEnd' => (is => 'rw', isa => 'ArrayRef'); | |
sub parse | |
{ | |
my $self = $_[0]; | |
my $line = $_[1]; | |
my @bedLine = split("\t", $_, 12); | |
$self->chrom($bedLine[0]); | |
$self->chromStart($bedLine[1]); | |
$self->chromEnd($bedLine[2]); | |
$self->name($bedLine[3]); | |
$self->score($bedLine[4]); | |
$self->strand($bedLine[5]); | |
$self->thickStart($bedLine[6]); | |
$self->thickEnd($bedLine[7]); | |
$self->itemRgb($bedLine[8]); | |
$self->blocks($bedLine[9]); | |
my @blockSizes = split(",", $bedLine[10]); | |
my @blockStarts = split(",", $bedLine[11]); | |
$self->blockSizes(\@blockSizes); | |
$self->blockStarts(\@blockStarts); | |
$self->exons(); | |
} | |
sub exons | |
{ | |
my $self = $_[0]; | |
my $offset = 0; | |
my @listExonStart = (); | |
my @listExonEnd = (); | |
for (my $e = 0; $e < $self->blocks; $e++) | |
{ | |
my $exonStart = $self->chromStart + $self->blockStarts->[$e]; | |
my $exonEnd = $exonStart + $self->blockSizes->[$e]; | |
push(@listExonStart, $exonStart); | |
push(@listExonEnd, $exonEnd); | |
if (($exonStart <= $self->thickStart) && ($self->thickStart <= $exonEnd)) | |
{ | |
$self->cdsStart($self->thickStart - $exonStart + $offset); | |
} | |
if (($exonStart <= $self->thickEnd) && ($self->thickEnd <= $exonEnd)) | |
{ | |
$self->cdsEnd($self->thickEnd - $exonStart + $offset); | |
} | |
$offset += $self->blockSizes->[$e]; | |
} | |
$self->geneSpan($offset); | |
$self->cdsSpan($self->cdsEnd - $self->cdsStart); | |
$self->exonStart(\@listExonStart); | |
$self->exonEnd(\@listExonEnd); | |
} | |
sub find | |
{ | |
my $self = $_[0]; | |
my $rangeStart = $_[1]; | |
my $rangeEnd = $_[2]; | |
my $offset = 0; | |
my @result = (); | |
for (my $e = 0; $e < $self->blocks; $e++) | |
{ | |
# current exon | |
my $exonStart = $self->chromStart + $self->blockStarts->[$e]; | |
my $exonEnd = $exonStart + $self->blockSizes->[$e]; | |
# check for overlap | |
if(($rangeStart <= $exonEnd) && ($exonStart <= $rangeEnd)) | |
{ | |
# intersect between region and exon | |
my $isectStart = max($rangeStart, $exonStart); | |
my $isectEnd = min($rangeEnd, $exonEnd); | |
# convert to linear coordinates | |
my $linearStart = $isectStart - $exonStart + $offset; | |
my $linearEnd = $isectEnd - $exonStart + $offset; | |
push(@result, [$linearStart, $linearEnd]); | |
} | |
# update offset from chromStart | |
$offset += $self->blockSizes->[$e]; | |
} | |
return \@result; | |
} | |
sub min | |
{ | |
my $x = $_[0]; | |
my $y = $_[1]; | |
return ($x <= $y) ? $x : $y; | |
} | |
sub max | |
{ | |
my $x = $_[0]; | |
my $y = $_[1]; | |
return ($x <= $y) ? $y : $x; | |
} | |
1; |