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