KaryotypeBandAdaptor.pm 6.44 KB
Newer Older
1
=head1 LICENSE
2

3
Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4

5 6 7 8 9 10 11 12 13 14 15 16 17
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.

=cut
18 19


20
=head1 CONTACT
21

22
  Please email comments or questions to the public Ensembl
Magali Ruffier's avatar
Magali Ruffier committed
23
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
24

25
  Questions may also be sent to the Ensembl help desk at
Magali Ruffier's avatar
Magali Ruffier committed
26
  <http://www.ensembl.org/Help/Contact>.
27

28
=cut
29

30
=head1 NAME
31

32
Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
33

34
=head1 SYNOPSIS
35

36
  $kary_adaptor = $db_adaptor->get_KaryotypeBandAdaptor();
37

38 39 40
  foreach $band ( @{ $kary_adaptor->fetch_all_by_Slice($slice) } ) {
    # do something with band
  }
41

42
  $band = $kary_adaptor->fetch_by_dbID($id);
43

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

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

48
=head1 DESCRIPTION
49

50
Database adaptor to provide access to KaryotypeBand objects
51

52
=head1 METHODS
53 54 55

=cut

56
package Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor;
57

58
use strict;
59 60

use vars qw(@ISA);
61

Web Admin's avatar
Web Admin committed
62
use Bio::EnsEMBL::KaryotypeBand;
63 64
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
65

66
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
67

68 69 70 71 72 73 74 75 76
#_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
77 78


79 80
sub _tables {
  my $self = shift;
81

82 83
  return (['karyotype','k'])
}
84

Graham McVicker's avatar
Graham McVicker committed
85

86
#_columns
87

88 89 90 91 92 93 94
#  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
95

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
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;
117

118 119 120 121 122 123
  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);

124
  while ( $sth->fetch() ) {
125 126 127
    #need to get the internal_seq_region, if present
    $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);

128 129 130
    my $slice = $slice_cache{$seq_region_id} ||=
      $slice_adaptor->fetch_by_seq_region_id($seq_region_id);

131 132 133 134 135 136 137 138 139 140 141
    push( @features,
          $self->_create_feature( 'Bio::EnsEMBL::KaryotypeBand', {
                                    -START   => $seq_region_start,
                                    -END     => $seq_region_end,
                                    -SLICE   => $slice,
                                    -ADAPTOR => $self,
                                    -DBID    => $karyotype_id,
                                    -NAME    => $band,
                                    -STAIN   => $stain
                                  } ) );

142
  }
143

144
  return \@features;
145 146 147
}


148

149
=head2 fetch_all_by_chr_name
150

Graham McVicker's avatar
Graham McVicker committed
151 152
  Arg [1]    : string $chr_name
               Name of the chromosome from which to retrieve band objects 
153
  Example    : @bands=@{$karyotype_band_adaptor->fetch_all_by_chr_name('X')}; 
Graham McVicker's avatar
Graham McVicker committed
154 155
  Description: Fetches all the karyotype band objects from the database for the
               given chromosome. 
Graham McVicker's avatar
Graham McVicker committed
156 157
  Returntype : listref of Bio::EnsEMBL::KaryotypeBand in chromosomal 
               (assembly) coordinates 
Graham McVicker's avatar
Graham McVicker committed
158 159
  Exceptions : none 
  Caller     : general 
160
  Status     : Stable
161 162 163

=cut

164
sub fetch_all_by_chr_name {
165
    my ($self,$chr_name) = @_;
James Stalker's avatar
James Stalker committed
166
    
167
    throw('Chromosome name argument expected') if(!$chr_name);
168

169
    my $slice =
170
      $self->db->get_SliceAdaptor->fetch_by_region(undef, $chr_name);
171 172 173 174
    unless ($slice){
        warning("Cannot retrieve chromosome $chr_name");
        return;
    }
175 176
    return $self->fetch_all_by_Slice($slice);
}
177

178

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

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

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

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

  my $constraint = "k.band like '$band%'";
  return $self->fetch_all_by_Slice_constraint($slice,$constraint);
}


Web Admin's avatar
Web Admin committed
194
=head2 fetch_by_chr_band
195

Graham McVicker's avatar
Graham McVicker committed
196 197 198 199
  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
200 201 202 203 204 205 206
  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.
207
  Exceptions : throws if chr or band is missing in arguments
Graham McVicker's avatar
Graham McVicker committed
208
  Caller     : general
209
  Status     : Stable
210 211 212

=cut

213 214 215
sub fetch_by_chr_band {
  my $self = shift;
  deprecate('Use fetch_all_by_chr_band instead.');
216

217 218
  my ($band) = @{$self->fetch_all_by_chr_band(@_)};
  return $band;
219 220
}

221

222 223 224 225 226 227
=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
228
  Arg[1]     : <optional> int. not 0 for the ids to be sorted by the seq_region.
229 230 231
  Returntype : reference to a list of ints
  Exceptions : none
  Caller     : ?
232
  Status     : Stable
233 234 235 236

=cut

sub list_dbIDs {
237
  my ($self, $ordered) = @_;
238

239
  return $self->_list_dbIDs("karyotype",undef, $ordered);
240 241
}

242

243
1;