Commit e1cb18fe authored by Felix Kokocinski's avatar Felix Kokocinski
Browse files

added ditag object to ditag_feature properties, replaced fetch_ditag() with...

added ditag object to ditag_feature properties, replaced fetch_ditag() with ditag() for lazy loading ditag object
parent 3b4599f9
......@@ -68,6 +68,7 @@ use Bio::EnsEMBL::Utils::Argument qw( rearrange );
Arg [15] : (optional) int tag_count, only used for imported mappings where
identical positions where collapsed into into one feature.
Default: 1
Arg [16] : (optional) ditag object
Example : $ditag = Bio::EnsEMBL::Map::DitagFeature->new
(-dbID => 123, -adaptor => $adaptor, ...);
......@@ -80,9 +81,9 @@ use Bio::EnsEMBL::Utils::Argument qw( rearrange );
sub new {
my ($caller, @args) = @_;
my ( $dbID, $adaptor, $start, $end, $strand, $slice, $analysis, $hit_start, $hit_end,
$hit_strand, $ditag_id, $ditag_side, $cigar_line, $ditag_pair_id, $tag_count ) = rearrange(
$hit_strand, $ditag_id, $ditag_side, $cigar_line, $ditag_pair_id, $tag_count, $ditag ) = rearrange(
[ 'dbid', 'adaptor' ,'start', 'end', 'strand', 'slice', 'analysis', 'hit_start',
'hit_end', 'hit_strand', 'ditag_id', 'ditag_side', 'cigar_line', 'ditag_pair_id' ,'tag_count'],
'hit_end', 'hit_strand', 'ditag_id', 'ditag_side', 'cigar_line', 'ditag_pair_id' ,'tag_count', 'ditag'],
@args );
my $class = ref($caller) || $caller;
......@@ -132,31 +133,37 @@ sub new {
'ditag_side' => $ditag_side,
'cigar_line' => $cigar_line,
'tag_count' => $tag_count,
'ditag' => $ditag,
}, $class);
return $self;
}
=head2 fetch_ditag
=head2 ditag
Arg [1] : none
Description: Get the ditag object of this DitagFeature
Arg [1] : (optional) ditag object
Description: Get/Set the ditag object of this DitagFeature
Returntype : Bio::EnsEMBL::Map::Ditag
Exceptions : none
Caller : general
=cut
sub fetch_ditag {
sub ditag {
my $self = shift;
my $ditag_adaptor = $self->adaptor->db->get_DitagAdaptor;
my $ditag = $ditag_adaptor->fetch_by_dbID($self->ditag_id);
if(@_) {
$self->{'ditag'} = shift;
} elsif(!$self->{'ditag'} && $self->{'adaptor'} && $self->{'ditag_id'}) {
#lazy load the ditag
my $ditag_adaptor = $self->adaptor->db->get_DitagAdaptor;
$self->{'ditag'} = $ditag_adaptor->fetch_by_dbID($self->ditag_id);
}
return $ditag;
}
return $self->{'ditag'};
}
=head2 get_ditag_location
......@@ -181,25 +188,29 @@ sub get_ditag_location {
$end = $self->end;
}
else{
my ($ditag_a, $ditag_b);
my ($ditag_a, $ditag_b, $more);
eval{
($ditag_a, $ditag_b) = @{$self->adaptor->fetch_all_by_ditagID($self->ditag_id, $self->ditag_pair_id)};
($ditag_a, $ditag_b, $more) = @{$self->adaptor->fetch_all_by_ditagID($self->ditag_id, $self->ditag_pair_id, $self->analysis->dbID)};
};
if($@ or !defined($ditag_b)){
throw("Cannot find 2nd tag of pair (".$self->dbID.", ".$self->ditag_id.", ".$self->ditag_pair_id.")");
if($@ or !defined($ditag_a) or !defined($ditag_b)){
throw("Cannot find 2nd tag of pair (".$self->dbID.", ".$self->ditag_id.", ".$self->ditag_pair_id.", ".$self->analysis->dbID.")");
}
($ditag_a->start < $ditag_b->start) ? ($start = $ditag_a->start) : ($start = $ditag_b->start);
($ditag_a->end > $ditag_b->end) ? ($end = $ditag_a->end) : ($end = $ditag_b->end);
if($self->strand != $ditag_b->strand){
throw('the strand of the two ditagFeatures are different! '.$ditag_a->strand.'/'.$ditag_b->strand);
else{
if(defined $more){
throw("More than two DitagFeatures were returned for ".$self->dbID.", ".$self->ditag_id.", ".$self->ditag_pair_id);
}
($ditag_a->start < $ditag_b->start) ? ($start = $ditag_a->start) : ($start = $ditag_b->start);
($ditag_a->end > $ditag_b->end) ? ($end = $ditag_a->end) : ($end = $ditag_b->end);
if($ditag_a->strand != $ditag_b->strand){
throw('the strand of the two ditagFeatures are different! '.$ditag_a->strand.'/'.$ditag_b->strand);
}
}
}
return($start, $end, $self->strand);
}
=head2 property functions
Arg [1] : (optional) value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment