KaryotypeBandAdaptor.pm 5.25 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_by_Slice
64

Graham McVicker's avatar
Graham McVicker committed
65
66
67
68
69
  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice object covering the region to retrieve bands from 
  Example    : @bands = $karyotype_band_adaptor->fetch_by_Slice($slice);
  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
78
79
80
81
82
sub fetch_by_Slice {
  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
95
96
				AND	$start <= chr_end 
				AND	$end > chr_start 
			     ");

97
98
99
100
101
102
  $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;
103
104
    my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
    $band_obj->name($band);
105
106
107
108
109
110
    $band_obj->chr_name($chr_name);

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

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

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


119
=head2 fetch_by_chr_name
120

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

=cut

133
134
sub fetch_by_chr_name {
    my ($self,$chr_name) = @_;
135

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

139
    my $sth = $self->prepare(
140
        "SELECT	chr_start, chr_end, stain, band
141
         FROM karyotype 
142
         WHERE chromosome_id = ?"
143
    );
144
    $sth->execute( $chr_id );
145
    
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    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;
160
    }
161
    
Graham McVicker's avatar
Graham McVicker committed
162
    return \@out;
163
}
164

165

166
167
=head2 fetch_by_chr_band

Graham McVicker's avatar
Graham McVicker committed
168
169
170
171
172
173
174
175
176
177
178
  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
  Example    : $band = $karyotype_band_adaptor->fetch_by_chr_band('4', 'q23'); 
  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
179
180
181

=cut

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

185
    $self->throw("Need band name") unless defined $band;
186

187
188
189
    my $chr_adaptor = $self->db()->get_ChromosomeAdaptor();
   
    my $chr_id = $chr_adaptor->fetch_by_chr_name($chr_name)->dbID();
190
191

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

196
    $sth->execute( $band, $chr_id );
197
198
199
200
201
202

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

    return undef unless defined $chr_start;

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

    return $band_obj;
}

212
213

1;