Archive Ensembl HomeArchive Ensembl Home
KaryotypeBandAdaptor.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
00024 
00025 =head1 SYNOPSIS
00026 
00027   $kary_adaptor = $db_adaptor->get_KaryotypeBandAdaptor();
00028 
00029   foreach $band ( @{ $kary_adaptor->fetch_all_by_Slice($slice) } ) {
00030     # do something with band
00031   }
00032 
00033   $band = $kary_adaptor->fetch_by_dbID($id);
00034 
00035   my @bands = @{ $kary_adaptor->fetch_all_by_chr_name('X') };
00036 
00037   my $band = $kary_adaptor->fetch_by_chr_band( '4', 'q23' );
00038 
00039 =head1 DESCRIPTION
00040 
00041 Database adaptor to provide access to KaryotypeBand objects
00042 
00043 =head1 METHODS
00044 
00045 =cut
00046 
00047 package Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor;
00048 
00049 use strict;
00050 
00051 use vars qw(@ISA);
00052 
00053 use Bio::EnsEMBL::KaryotypeBand;
00054 use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
00055 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
00056 
00057 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
00058 
00059 #_tables
00060 #
00061 #  Arg [1]    : none
00062 #  Example    : none
00063 #  Description: PROTECTED Implementation of abstract superclass method to
00064 #               provide the name of the tables to query
00065 #  Returntype : string
00066 #  Exceptions : none
00067 #  Caller     : internal
00068 
00069 
00070 sub _tables {
00071   my $self = shift;
00072 
00073   return (['karyotype','k'])
00074 }
00075 
00076 
00077 #_columns
00078 
00079 #  Arg [1]    : none
00080 #  Example    : none
00081 #  Description: PROTECTED Implementation of abstract superclass method to 
00082 #               provide the name of the columns to query 
00083 #  Returntype : list of strings
00084 #  Exceptions : none
00085 #  Caller     : internal
00086 
00087 sub _columns {
00088   my $self = shift;
00089 
00090   #warning _objs_from_sth implementation depends on ordering
00091   return qw (
00092        k.karyotype_id
00093        k.seq_region_id
00094        k.seq_region_start
00095        k.seq_region_end
00096        k.band
00097        k.stain );
00098 }
00099 
00100 
00101 sub _objs_from_sth {
00102   my ($self, $sth) = @_;
00103   my $db = $self->db();
00104   my $slice_adaptor = $db->get_SliceAdaptor();
00105 
00106   my @features;
00107   my %slice_cache;
00108 
00109   my($karyotype_id,$seq_region_id,$seq_region_start,$seq_region_end,
00110      $band,$stain);
00111 
00112   $sth->bind_columns(\$karyotype_id, \$seq_region_id, \$seq_region_start,
00113                      \$seq_region_end, \$band, \$stain);
00114 
00115   while ( $sth->fetch() ) {
00116     #need to get the internal_seq_region, if present
00117     $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
00118 
00119     my $slice = $slice_cache{$seq_region_id} ||=
00120       $slice_adaptor->fetch_by_seq_region_id($seq_region_id);
00121 
00122     push( @features,
00123           $self->_create_feature( 'Bio::EnsEMBL::KaryotypeBand', {
00124                                     -START   => $seq_region_start,
00125                                     -END     => $seq_region_end,
00126                                     -SLICE   => $slice,
00127                                     -ADAPTOR => $self,
00128                                     -DBID    => $karyotype_id,
00129                                     -NAME    => $band,
00130                                     -STAIN   => $stain
00131                                   } ) );
00132 
00133   }
00134 
00135   return \@features;
00136 }
00137 
00138 
00139 
00140 =head2 fetch_all_by_chr_name
00141 
00142   Arg [1]    : string $chr_name
00143                Name of the chromosome from which to retrieve band objects 
00144   Example    : @bands=@{$karyotype_band_adaptor->fetch_all_by_chr_name('X')}; 
00145   Description: Fetches all the karyotype band objects from the database for the
00146                given chromosome. 
00147   Returntype : listref of Bio::EnsEMBL::KaryotypeBand in chromosomal 
00148                (assembly) coordinates 
00149   Exceptions : none 
00150   Caller     : general 
00151   Status     : Stable
00152 
00153 =cut
00154 
00155 sub fetch_all_by_chr_name {
00156     my ($self,$chr_name) = @_;
00157     
00158     throw('Chromosome name argument expected') if(!$chr_name);
00159 
00160     my $slice =
00161       $self->db->get_SliceAdaptor->fetch_by_region(undef, $chr_name);
00162     unless ($slice){
00163         warning("Cannot retrieve chromosome $chr_name");
00164         return;
00165     }
00166     return $self->fetch_all_by_Slice($slice);
00167 }
00168 
00169 
00170 
00171 sub fetch_all_by_chr_band {
00172   my ($self, $chr_name, $band) = @_;
00173 
00174   throw('Chromosome name argument expected') if(!$chr_name);
00175   throw('Band argument expected') if(!$band);
00176 
00177   my $slice = $self->db->get_SliceAdaptor->fetch_by_region(undef,
00178                                                            $chr_name);
00179 
00180   my $constraint = "k.band like '$band%'";
00181   return $self->fetch_all_by_Slice_constraint($slice,$constraint);
00182 }
00183 
00184 
00185 =head2 fetch_by_chr_band
00186 
00187   Arg  [1]   : string $chr_name
00188                Name of the chromosome from which to retrieve the band
00189   Arg  [2]   : string $band
00190                The name of the band to retrieve from the specified chromosome
00191   Example    : @bands = @{$kary_adaptor->fetch_all_by_chr_band('4', 'q23')};
00192   Description: Fetches the karyotype band object from the database
00193                for the given chromosome and band name.  If no such band
00194                exists, undef is returned instead.  This function uses fuzzy
00195                matching of the band name. For example the bands 'q23.1' and
00196                'q23.4' could be matched by fetch_all_by_chr_band('20', 'q23');
00197   Returntype : Bio::EnsEMBL::KaryotypeBand in chromosomal coordinates.
00198   Exceptions : throws if chr or band is missing in arguments
00199   Caller     : general
00200   Status     : Stable
00201 
00202 =cut
00203 
00204 sub fetch_by_chr_band {
00205   my $self = shift;
00206   deprecate('Use fetch_all_by_chr_band instead.');
00207 
00208   my ($band) = @{$self->fetch_all_by_chr_band(@_)};
00209   return $band;
00210 }
00211 
00212 
00213 =head2 list_dbIDs
00214 
00215   Arg [1]    : none
00216   Example    : @kary_ids = @{$karyotype_band_adaptor->list_dbIDs()};
00217   Description: Gets an array of internal ids for all karyotype bands in the
00218                current db
00219   Arg[1]     : <optional> int. not 0 for the ids to be sorted by the seq_region.
00220   Returntype : reference to a list of ints
00221   Exceptions : none
00222   Caller     : ?
00223   Status     : Stable
00224 
00225 =cut
00226 
00227 sub list_dbIDs {
00228   my ($self, $ordered) = shift;
00229 
00230   return $self->_list_dbIDs("karyotype",undef, $ordered);
00231 }
00232 
00233 
00234 1;