KaryotypeBandAdaptor.pm 5.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#
# Ensembl module for Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
#
#
# Copyright James Stalker
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor

=head1 SYNOPSIS

Graham McVicker's avatar
Graham McVicker committed
17
$kary_adaptor = $db_adaptor->get_KaryotypeBandAdaptor();
18
foreach $band ( @{$kary_adaptor->fetch_all_by_Slice($slice)} ) {
19
20
  #do something with band
}
21

22
23
24
25
26
27
28
$band = $kary_adaptor->fetch_by_dbID($id);

my @bands = @{$kary_adaptor->fetch_all_by_chr_name('X')};

my $band = $kary_adaptor->fetch_by_chr_band('4','q23');


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
=head1 DESCRIPTION

Database adaptor to provide access to KaryotypeBand objects

=head1 AUTHOR

James Stalker

This modules is part of the Ensembl project http://www.ensembl.org

=head1 CONTACT

Email jws@sanger.ac.uk

=head1 APPENDIX

45
46
The rest of the documentation details each of the object methods. Internal 
methods are usually preceded with a _
47
48
49
50

=cut


51
package Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor;
52

53
use strict;
54
55

use vars qw(@ISA);
56

Web Admin's avatar
Web Admin committed
57
use Bio::EnsEMBL::KaryotypeBand;
58
59
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
60

61
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
62

63
64
65
66
67
68
69
70
71
#_tables
#
#  Arg [1]    : none
#  Example    : none
#  Description: PROTECTED Implementation of abstract superclass method to
#               provide the name of the tables to query
#  Returntype : string
#  Exceptions : none
#  Caller     : internal
72
73


74
75
sub _tables {
  my $self = shift;
76

77
78
  return (['karyotype','k'])
}
79

Graham McVicker's avatar
Graham McVicker committed
80

81
#_columns
82

83
84
85
86
87
88
89
#  Arg [1]    : none
#  Example    : none
#  Description: PROTECTED Implementation of abstract superclass method to 
#               provide the name of the columns to query 
#  Returntype : list of strings
#  Exceptions : none
#  Caller     : internal
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
sub _columns {
  my $self = shift;

  #warning _objs_from_sth implementation depends on ordering
  return qw (
       k.karyotype_id
       k.seq_region_id
       k.seq_region_start
       k.seq_region_end
       k.band
       k.stain );
}


sub _objs_from_sth {
  my ($self, $sth) = @_;
  my $db = $self->db();
  my $slice_adaptor = $db->get_SliceAdaptor();

  my @features;
  my %slice_cache;
112

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  my($karyotype_id,$seq_region_id,$seq_region_start,$seq_region_end,
     $band,$stain);

  $sth->bind_columns(\$karyotype_id, \$seq_region_id, \$seq_region_start,
                     \$seq_region_end, \$band, \$stain);

  while($sth->fetch()) {
    my $slice = $slice_cache{$seq_region_id} ||=
      $slice_adaptor->fetch_by_seq_region_id($seq_region_id);

    push @features, Bio::EnsEMBL::KaryotypeBand->new
      (-START   => $seq_region_start,
       -END     => $seq_region_end,
       -SLICE   => $slice,
       -ADAPTOR => $self,
       -DBID    => $karyotype_id,
       -NAME    => $band,
       -STAIN   => $stain);
131
  }
132

133
  return \@features;
134
135
136
}


137

138
=head2 fetch_all_by_chr_name
139

Graham McVicker's avatar
Graham McVicker committed
140
141
  Arg [1]    : string $chr_name
               Name of the chromosome from which to retrieve band objects 
142
  Example    : @bands=@{$karyotype_band_adaptor->fetch_all_by_chr_name('X')}; 
Graham McVicker's avatar
Graham McVicker committed
143
144
  Description: Fetches all the karyotype band objects from the database for the
               given chromosome. 
Graham McVicker's avatar
Graham McVicker committed
145
146
  Returntype : listref of Bio::EnsEMBL::KaryotypeBand in chromosomal 
               (assembly) coordinates 
Graham McVicker's avatar
Graham McVicker committed
147
148
  Exceptions : none 
  Caller     : general 
149
150
151

=cut

152
sub fetch_all_by_chr_name {
153
    my ($self,$chr_name) = @_;
154

155
    throw('Chromosome name argument expected') if(!$chr_name);
156

157
    my $slice =
158
      $self->db->get_SliceAdaptor->fetch_by_region(undef, $chr_name);
159
160
    return $self->fetch_all_by_Slice($slice);
}
161

162

Web Admin's avatar
Web Admin committed
163
=head2 fetch_by_chr_band
164

Graham McVicker's avatar
Graham McVicker committed
165
166
167
168
  Arg  [1]   : string $chr_name
               Name of the chromosome from which to retrieve the band
  Arg  [2]   : string $band
               The name of the band to retrieve from the specified chromosome
169
170
171
172
173
174
175
  Example    : @bands = @{$kary_adaptor->fetch_all_by_chr_band('4', 'q23')};
  Description: Fetches the karyotype band object from the database
               for the given chromosome and band name.  If no such band
               exists, undef is returned instead.  This function uses fuzzy
               matching of the band name. For example the bands 'q23.1' and
               'q23.4' could be matched by fetch_all_by_chr_band('20', 'q23');
  Returntype : Bio::EnsEMBL::KaryotypeBand in chromosomal coordinates.
Graham McVicker's avatar
Graham McVicker committed
176
177
  Exceptions : none
  Caller     : general
178
179
180

=cut

181
182
sub fetch_all_by_chr_band {
  my ($self, $chr_name, $band) = @_;
183

184
185
  throw('Chromosome name argument expected') if(!$chr_name);
  throw('Band argument expected') if(!$band);
186

187
  my $slice = $self->db->get_SliceAdaptor->fetch_by_region(undef,
188
                                                           $chr_name);
189

190
191
192
  my $constraint = "k.band like '$band%'";
  return $self->fetch_all_by_Slice_constraint($slice,$constraint);
}
193
194
195



196
197
198
sub fetch_by_chr_band {
  my $self = shift;
  deprecate('Use fetch_all_by_chr_band instead.');
199

200
201
  my ($band) = @{$self->fetch_all_by_chr_band(@_)};
  return $band;
202
203
}

204

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
=head2 list_dbIDs

  Arg [1]    : none
  Example    : @kary_ids = @{$karyotype_band_adaptor->list_dbIDs()};
  Description: Gets an array of internal ids for all karyotype bands in the
               current db
  Returntype : reference to a list of ints
  Exceptions : none
  Caller     : ?

=cut

sub list_dbIDs {
  my $self = shift;

  return $self->_list_dbIDs("karyotype");
}

223

224
1;