| 1 |
|
| 2 |
=head1 LICENSE |
| 3 |
|
| 4 |
Copyright [2015-2024] EMBL-European Bioinformatics Institute |
| 5 |
|
| 6 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
you may not use this file except in compliance with the License. |
| 8 |
You may obtain a copy of the License at |
| 9 |
|
| 10 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
|
| 12 |
Unless required by applicable law or agreed to in writing, software |
| 13 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
See the License for the specific language governing permissions and |
| 16 |
limitations under the License. |
| 17 |
|
| 18 |
=head1 AUTHOR |
| 19 |
|
| 20 |
Rishi Nag E<lt>[email protected]<gt> |
| 21 |
|
| 22 |
=cut |
| 23 |
|
| 24 |
package Bio::DB::HTS::Segment; |
| 25 |
$Bio::DB::HTS::Segment::VERSION = '3.02'; |
| 26 |
|
| 27 |
use strict; |
| 28 |
use warnings; |
| 29 |
|
| 30 |
sub new { |
| 31 |
my $class = shift; |
| 32 |
my ( $db, $seqid, $start, $end ) = @_; |
| 33 |
return bless { db => $db, seqid => $seqid, start => $start, end => $end }, |
| 34 |
ref $class || $class; |
| 35 |
} |
| 36 |
|
| 37 |
sub db { shift->{db} } |
| 38 |
|
| 39 |
sub features { |
| 40 |
my $self = shift; |
| 41 |
my $db = $self->db; |
| 42 |
my @args; |
| 43 |
|
| 44 |
if ( @_ && $_[0] !~ /^-/ ) { # type list |
| 45 |
@args = ( -types => \@_ ); |
| 46 |
} |
| 47 |
else { |
| 48 |
@args = @_; |
| 49 |
} |
| 50 |
return |
| 51 |
$db->features( -seq_id => $self->seq_id, |
| 52 |
-start => $self->start, |
| 53 |
-end => $self->end, |
| 54 |
@args ); |
| 55 |
} |
| 56 |
|
| 57 |
#required by GBrowse1 |
| 58 |
sub get_feature_stream { |
| 59 |
my $self = shift; |
| 60 |
my @args = @_; |
| 61 |
|
| 62 |
my @features = $self->features(@args); |
| 63 |
|
| 64 |
return Bio::DB::HTS::Segment::Iterator->new( \@features ); |
| 65 |
} |
| 66 |
|
| 67 |
# required by api |
| 68 |
sub seq_id { shift->{seqid} } |
| 69 |
# required by GBrowse1 |
| 70 |
*ref = *abs_ref = *sourceseq = \&seq_id; |
| 71 |
# required by api |
| 72 |
sub start { shift->{start} } |
| 73 |
# required by api |
| 74 |
sub end { shift->{end} } |
| 75 |
# required by api |
| 76 |
sub strand { 0 } |
| 77 |
# required by api |
| 78 |
sub length { |
| 79 |
my $self = shift; |
| 80 |
return $self->end - $self->start + 1; |
| 81 |
} |
| 82 |
# required by api |
| 83 |
sub seq { |
| 84 |
my $self = shift; |
| 85 |
return Bio::PrimarySeq->new( -seq => $self->dna, -id => $self->seq_id ); |
| 86 |
} |
| 87 |
|
| 88 |
sub primary_id { |
| 89 |
shift->seq_id; |
| 90 |
} |
| 91 |
# required by api |
| 92 |
sub primary_tag { |
| 93 |
my $self = shift; |
| 94 |
return 'region'; |
| 95 |
} |
| 96 |
|
| 97 |
sub dna { |
| 98 |
my $self = shift; |
| 99 |
my $db = $self->db; |
| 100 |
$db->seq( $self->seq_id, $self->start, $self->end ); |
| 101 |
} |
| 102 |
# required by api |
| 103 |
sub source_tag { return 'sam/bam' } |
| 104 |
# required by api |
| 105 |
sub name { shift->seq_id } |
| 106 |
# required by api |
| 107 |
sub display_name { shift->seq_id } |
| 108 |
# required by api |
| 109 |
sub factory { shift->db } |
| 110 |
# required by api |
| 111 |
sub get_SeqFeatures { return; } |
| 112 |
# required by api |
| 113 |
sub method { shift->primary_tag } |
| 114 |
# required by GBrowse1 |
| 115 |
sub type { shift->primary_tag } |
| 116 |
# required by api |
| 117 |
sub get_tag_values { return; } |
| 118 |
# required by api |
| 119 |
sub score { return; } |
| 120 |
# required by api |
| 121 |
sub class { 'sequence' } |
| 122 |
|
| 123 |
package Bio::DB::HTS::Segment::Iterator; |
| 124 |
|
| 125 |
$Bio::DB::HTS::Segment::Iterator::VERSION = '3.02'; |
| 126 |
|
| 127 |
sub new { |
| 128 |
my $package = shift; |
| 129 |
my $features = shift; |
| 130 |
return bless $features, $package; |
| 131 |
} |
| 132 |
|
| 133 |
sub next_seq { |
| 134 |
my $self = shift; |
| 135 |
return unless @$self; |
| 136 |
my $next_feature = shift @$self; |
| 137 |
return $next_feature; |
| 138 |
} |
| 139 |
|
| 140 |
1; |