KaryotypeBandAdaptor.pm 5.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# Ensembl module for Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
#
# Cared for by James Stalker <jws@sanger.ac.uk>
#
# 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
18
$kary_adaptor = $db_adaptor->get_KaryotypeBandAdaptor();
19
20
21
foreach $band ( $kary_adaptor->fetch_by_Slice($slice) ) {
  #do something with band
}
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

=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

39
40
The rest of the documentation details each of the object methods. Internal 
methods are usually preceded with a _
41
42
43
44
45
46
47
48
49

=cut


# Let the code begin...


package Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor;
use vars qw(@ISA);
Web Admin's avatar
Web Admin committed
50
use Bio::EnsEMBL::KaryotypeBand;
51
52
use strict;

53
# Object preamble - inherits from Bio::EnsEMBL::BaseAdaptor
54
55
56
57
58
59

use Bio::EnsEMBL::DBSQL::BaseAdaptor;

@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);


60
# inherit new from BaseAdaptor
61

Graham McVicker's avatar
Graham McVicker committed
62

63
=head2 fetch_all_by_Slice
64

Graham McVicker's avatar
Graham McVicker committed
65
66
  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice object covering the region to retrieve bands from 
67
  Example    : @bands = @{$karyotype_band_adaptor->fetch_all_by_Slice($slice)};
Graham McVicker's avatar
Graham McVicker committed
68
69
  Description: Fetches karyotype band object from the database for the
               region given by the slice.
Graham McVicker's avatar
Graham McVicker committed
70
71
  Returntype : listref of Bio::EnsEMBL::KaryotypeBand objects in 
               Slice coordinates
Graham McVicker's avatar
Graham McVicker committed
72
73
  Exceptions : none
  Caller     : Bio::EnsEMBL::Slice::get_KarytypeBands 
74
75
76

=cut

77
sub fetch_all_by_Slice {
78
79
80
81
82
  my ($self,$slice) = @_;
  
  my $start = $slice->chr_start();
  my $end = $slice->chr_end();
  my $chr_name = $slice->chr_name();
83

84
85
  my $chr_adaptor = $self->db()->get_ChromosomeAdaptor();
  my $chr_id = $chr_adaptor->fetch_by_chr_name($chr_name)->dbID();
86

87
  my $sth = $self->prepare("	SELECT	chr_start,
88
89
90
91
					chr_end,
					band,
					stain
				FROM	karyotype 
92
				WHERE	chromosome_id = $chr_id
93
94
				AND	$start <= chr_end 
				AND	$end > chr_start 
95
                                order   by chr_start
96
97
			     ");

98
99
100
101
102
103
  $sth->execute;
  my @bands = ();
  my ($chr_start,$chr_end,$band,$stain) = ();
  
  while (($chr_start,$chr_end,$band,$stain) = $sth->fetchrow_array()){
    last unless defined $band;
104
105
    my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
    $band_obj->name($band);
106
107
108
109
110
111
    $band_obj->chr_name($chr_name);

    #convert to slice coordinates
    $band_obj->start($chr_start - $start + 1);
    $band_obj->end($chr_end - $start + 1);

112
    $band_obj->stain($stain);
113
114
    push (@bands, $band_obj);
  }
115

Graham McVicker's avatar
Graham McVicker committed
116
  return \@bands;
117
118
119
}


120
=head2 fetch_all_by_chr_name
121

Graham McVicker's avatar
Graham McVicker committed
122
123
  Arg [1]    : string $chr_name
               Name of the chromosome from which to retrieve band objects 
124
  Example    : @bands=@{$karyotype_band_adaptor->fetch_all_by_chr_name('X')}; 
Graham McVicker's avatar
Graham McVicker committed
125
126
  Description: Fetches all the karyotype band objects from the database for the
               given chromosome. 
Graham McVicker's avatar
Graham McVicker committed
127
128
  Returntype : listref of Bio::EnsEMBL::KaryotypeBand in chromosomal 
               (assembly) coordinates 
Graham McVicker's avatar
Graham McVicker committed
129
130
  Exceptions : none 
  Caller     : general 
131
132
133

=cut

134
sub fetch_all_by_chr_name {
135
    my ($self,$chr_name) = @_;
136

137
138
    my $chr_adaptor = $self->db()->get_ChromosomeAdaptor();
    my $chr_id = $chr_adaptor->fetch_by_chr_name($chr_name)->dbID();
139

140
    my $sth = $self->prepare(
141
        "SELECT	chr_start, chr_end, stain, band
142
         FROM karyotype 
143
144
         WHERE chromosome_id = ?
         ORDER BY chr_start"
145
    );
146
    $sth->execute( $chr_id );
147
    
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    my ($chr_start,$chr_end,$stain, $band) = ();
    my @out = ();

    while(($chr_start, $chr_end, $stain, $band) = $sth->fetchrow_array()) {
      last unless defined $chr_start;
      
      my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
      $band_obj->name($band);
      $band_obj->chr_name($chr_name);
      $band_obj->start($chr_start);
      $band_obj->end($chr_end);
      $band_obj->stain($stain);
      
      push @out, $band_obj;
162
    }
163
    
Graham McVicker's avatar
Graham McVicker committed
164
    return \@out;
165
}
166

167

168
169

=head2 fetch_all_by_chr_band
170

Graham McVicker's avatar
Graham McVicker committed
171
172
173
174
  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
175
  Example    : $band = $kary_adaptor->fetch_all_by_chr_band('4', 'q23'); 
Graham McVicker's avatar
Graham McVicker committed
176
177
178
179
180
181
  Description: Fetches the karyotype band object from the database 
               for the given chromosome and band name.
  Returntype : Bio::EnsEMBL::KaryotypeBand in 
               chromosomal (assembly) coordinates
  Exceptions : none
  Caller     : general
182
183
184

=cut

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

188
    $self->throw("Need band name") unless defined $band;
189

190
191
192
    my $chr_adaptor = $self->db()->get_ChromosomeAdaptor();
   
    my $chr_id = $chr_adaptor->fetch_by_chr_name($chr_name)->dbID();
193
194

    my $sth = $self->prepare(
195
        "SELECT	chr_start, chr_end, stain
196
         FROM karyotype 
197
         WHERE band = ? AND chromosome_id = ?");
198

199
    $sth->execute( $band, $chr_id );
200
201
202
203
204
205

    my ($chr, $chr_start,$chr_end,$stain) = $sth->fetchrow_array;

    return undef unless defined $chr_start;

    my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
206
207
    $band_obj->name($band);
    $band_obj->chr_name($chr_name);
208
209
210
211
212
213
214
    $band_obj->start($chr_start);
    $band_obj->end($chr_end);
    $band_obj->stain($stain);

    return $band_obj;
}

215

216

217
1;