Skip to content

Commit

Permalink
add tree in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed May 20, 2017
1 parent fab7e90 commit 48f388f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
4 changes: 2 additions & 2 deletions PASSAnnotator.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@



# my $obj = BedParser->new($queryFile);
# $obj->parse();
#my $obj = BedParser->new($queryBedFile);
#$obj->parse();


my $obj = PassParser->new($queryPassFile, $queryBedFile);
Expand Down
2 changes: 0 additions & 2 deletions PASSAnnotator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
B179B9361EC676A1006FA542 /* PASSAnnotator.pl */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; path = PASSAnnotator.pl; sourceTree = "<group>"; };
B1BE38C01ECDA7FF0017F94D /* Bed.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = Bed.pm; path = lib/Record/Bed.pm; sourceTree = "<group>"; };
B1BE38C11ECDA7FF0017F94D /* Pass.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = Pass.pm; path = lib/Record/Pass.pm; sourceTree = "<group>"; };
B1BE38C71ECDC2B20017F94D /* BedTree.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = BedTree.pm; path = lib/Tests/BedTree.pm; sourceTree = "<group>"; };
B1BE38C81ECDC5380017F94D /* BedParser.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = BedParser.pm; path = lib/Tests/BedParser.pm; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -37,7 +36,6 @@
B1BE38C51ECDC20F0017F94D /* Tests */ = {
isa = PBXGroup;
children = (
B1BE38C71ECDC2B20017F94D /* BedTree.pm */,
B1BE38C81ECDC5380017F94D /* BedParser.pm */,
B16A7F0C1ECF1D9E004F1B12 /* PassParser.pm */,
);
Expand Down
39 changes: 24 additions & 15 deletions lib/Record/Bed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = '<unknown>';

# 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')
Expand All @@ -197,11 +208,9 @@ sub closest
$feature =~ tr/53/35/;
}

return ($hitBase, $feature);
return ($baseNode, $feature);
}





1; # return true
11 changes: 10 additions & 1 deletion lib/Record/Pass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ sub ischrom
return $ischrom;
}

sub region
sub window
{
my $self = shift;
my $window_upstream = shift;
Expand All @@ -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
5 changes: 4 additions & 1 deletion lib/Tests/BedParser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions lib/Tests/PassParser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++;

Expand Down

0 comments on commit 48f388f

Please sign in to comment.