diff --git a/PASSAnnotator.pl b/PASSAnnotator.pl index 99194f4..fa43f1d 100644 --- a/PASSAnnotator.pl +++ b/PASSAnnotator.pl @@ -24,8 +24,8 @@ -# my $obj = BedParser->new($queryFile); -# $obj->parse(); +#my $obj = BedParser->new($queryBedFile); +#$obj->parse(); my $obj = PassParser->new($queryPassFile, $queryBedFile); diff --git a/PASSAnnotator.xcodeproj/project.pbxproj b/PASSAnnotator.xcodeproj/project.pbxproj index be8f606..8d14846 100644 --- a/PASSAnnotator.xcodeproj/project.pbxproj +++ b/PASSAnnotator.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ B179B9361EC676A1006FA542 /* PASSAnnotator.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = PASSAnnotator.pl; sourceTree = ""; }; B1BE38C01ECDA7FF0017F94D /* Bed.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = Bed.pm; path = lib/Record/Bed.pm; sourceTree = ""; }; B1BE38C11ECDA7FF0017F94D /* Pass.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = Pass.pm; path = lib/Record/Pass.pm; sourceTree = ""; }; - B1BE38C71ECDC2B20017F94D /* BedTree.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = BedTree.pm; path = lib/Tests/BedTree.pm; sourceTree = ""; }; B1BE38C81ECDC5380017F94D /* BedParser.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = BedParser.pm; path = lib/Tests/BedParser.pm; sourceTree = ""; }; /* End PBXFileReference section */ @@ -37,7 +36,6 @@ B1BE38C51ECDC20F0017F94D /* Tests */ = { isa = PBXGroup; children = ( - B1BE38C71ECDC2B20017F94D /* BedTree.pm */, B1BE38C81ECDC5380017F94D /* BedParser.pm */, B16A7F0C1ECF1D9E004F1B12 /* PassParser.pm */, ); diff --git a/lib/Record/Bed.pm b/lib/Record/Bed.pm index 7b41eeb..137ee9a 100644 --- a/lib/Record/Bed.pm +++ b/lib/Record/Bed.pm @@ -30,10 +30,15 @@ sub new $self->{blockStarts} = $bed_vals[11]; $self->{exons} = (); $self->{introns} = (); + $self->{tree} = (); + $self->{thickStartNode} = (); + $self->{thickEndNode} = (); # assign features $self->getExons(); $self->getIntrons(); + $self->getFeaturesTree(); + $self->getTickNodes(); return $self; @@ -129,48 +134,54 @@ sub getIntrons $self->{introns} = \@introns; } -# BEDTREE -sub bedTree +# Red-Black Features Tree +sub getFeaturesTree { my $self = shift; # allocate tree - my $btree = Tree::Interval->new(); + $self->{tree} = Tree::Interval->new(); # insert exons my $exons_cnt = scalar(@{$self->{exons}}); for(my $ex = 0; $ex < $exons_cnt; $ex++) { - $btree->insert($self->{exons}->[$ex][0], $self->{exons}->[$ex][1], ['exon', $self->{exons}->[$ex][2], $exons_cnt]); + $self->{tree}->insert($self->{exons}->[$ex][0], $self->{exons}->[$ex][1], ['exon', $self->{exons}->[$ex][2], $exons_cnt]); } # insert introns my $introns_cnt = scalar(@{$self->{introns}}); for (my $in = 0; $in < $introns_cnt; $in++) { - $btree->insert($self->{introns}->[$in][0], $self->{introns}->[$in][1], ['intron', $self->{introns}->[$in][2], $introns_cnt]); + $self->{tree}->insert($self->{introns}->[$in][0], $self->{introns}->[$in][1], ['intron', $self->{introns}->[$in][2], $introns_cnt]); } - # return tree reference - return $btree; } +# Nodes for thicks Start and End +sub getTickNodes +{ + my $self = shift; + + $self->{thickStartNode} = $self->{tree}->find($self->{thickStart}); + $self->{thickEndNode} = $self->{tree}->find($self->{thickEnd}); + +} + + sub closest { my $self = shift; my $base = shift; - # generate bed tree - my $btree = $self->bedTree(); - # check base - my $hitBase = $btree->find($base); + my $baseNode = $self->{tree}->find($base); # allocate feature my $feature = ''; # root condition - my $cond_hit = defined($hitBase) ? $hitBase->[0] : 'intergenic'; + my $cond_hit = defined($baseNode) ? $baseNode->[0] : 'intergenic'; # decision tree if ($cond_hit eq 'exon') @@ -197,11 +208,9 @@ sub closest $feature =~ tr/53/35/; } - return ($hitBase, $feature); + return ($baseNode, $feature); } - - 1; # return true \ No newline at end of file diff --git a/lib/Record/Pass.pm b/lib/Record/Pass.pm index da4902e..ef3f844 100644 --- a/lib/Record/Pass.pm +++ b/lib/Record/Pass.pm @@ -52,7 +52,7 @@ sub ischrom return $ischrom; } -sub region +sub window { my $self = shift; my $window_upstream = shift; @@ -75,4 +75,13 @@ sub region return $self->{chrom} . ":" . $queryLeft . "-" . $queryRight; } +sub regions +{ + my $self = shift; + my $bed = shift; + my $baseNode = shift; + my $feature = shift; + +} + 1; # return true \ No newline at end of file diff --git a/lib/Tests/BedParser.pm b/lib/Tests/BedParser.pm index ea720bf..92eab5c 100644 --- a/lib/Tests/BedParser.pm +++ b/lib/Tests/BedParser.pm @@ -78,10 +78,13 @@ sub parse # process bed hit my ($hit, $feature) = $bed->closest($randomBase); - #print $bed->{name},"\t",$feature,"\n"; + # pass regions + + print $bed->{name},"\t",$feature,"\t",$bed->{thickEndNode}[0],"\n"; $count++; + last if($count == 100); } my $t1 = Benchmark->new(); my $td = timediff($t1, $t0); diff --git a/lib/Tests/PassParser.pm b/lib/Tests/PassParser.pm index 45d0b87..a9d08f1 100644 --- a/lib/Tests/PassParser.pm +++ b/lib/Tests/PassParser.pm @@ -115,7 +115,7 @@ sub parse } else { - my $iter = $self->{annotation}->query($pass->region($window_upstream)); + my $iter = $self->{annotation}->query($pass->window($window_upstream)); my $prevFeatureScore = $featureScores{'notail'}; my $hits = 0; @@ -128,8 +128,13 @@ sub parse next if($bed->{strand} ne $pass->{strand}); # process bed hit - (my $tmp, $feature) = $bed->closest($pass->{tailsBestBase}); + (my $bnode, $feature) = $bed->closest($pass->{tailsBestBase}); + # export features + $pass->regions($bed, $bnode, $feature); + + + # increment hits $hits++;