EnsEMBL/DBSQL/KaryotypeBandAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 113 CC 8 SCAR 21.9
CC
8
Cov
0%
store
20.0
fetch_all_by_chr_name
12.0
fetch_all_by_chr_band
12.0
CRAP 8.9
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
34  
35 =head1 SYNOPSIS
36  
37 $kary_adaptor = $db_adaptor->get_KaryotypeBandAdaptor();
38  
39 foreach $band ( @{ $kary_adaptor->fetch_all_by_Slice($slice) } ) {
40 # do something with band
41 }
42  
43 $band = $kary_adaptor->fetch_by_dbID($id);
44  
45 my @bands = @{ $kary_adaptor->fetch_all_by_chr_name('X') };
46  
47 my $band = $kary_adaptor->fetch_by_chr_band( '4', 'q23' );
48  
49 =head1 DESCRIPTION
50  
51 Database adaptor to provide access to KaryotypeBand objects
52  
53 =head1 METHODS
54  
55 =cut
56  
57 package Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor;
58 $Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor::VERSION = '114.0.0_50'; # TRIAL
59 $Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor::VERSION = '114.0.050';
60 use strict;
61  
62 use vars qw(@ISA);
63  
64 use Bio::EnsEMBL::KaryotypeBand;
65 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
66 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
67  
68 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
69  
70 =head2 store
71  
72 Arg [1] : list of Bio::EnsEMBL::KaryotypeBand @k
73 the karyotype bands to store in the database
74 Example : $karyotype_adaptor->store(@karyotype_band);
75 Description: Stores a list of karyotype band objects in the database
76 Returntype : none
77 Exceptions : thrown if @k is not defined, if any of the features do not
78 have an attached slice.
79 or if any elements of @k are not Bio::EnsEMBL::KaryotypeBand
80 Caller : general
81 Status : Stable
82  
83 =cut
84  
85 sub store{
86 my ($self,@k) = @_;
87  
88 if( scalar(@k) == 0 ) {
89 throw("Must call store with list of karyotype bands");
90 }
91  
92 my $sth = $self->prepare
93 ("INSERT INTO karyotype (seq_region_id, seq_region_start, " .
94 "seq_region_end, band, " .
95 "stain) " .
96 "VALUES (?,?,?,?,?)");
97  
98 my $db = $self->db();
99 my $slice_adaptor = $db->get_SliceAdaptor();
100  
101 BAND: foreach my $k ( @k ) {
102  
103 if( !ref $k || !$k->isa("Bio::EnsEMBL::KaryotypeBand") ) {
104 throw("KaryotypeBand must be an Ensembl KaryotypeBand, " .
105 "not a [".ref($k)."]");
106 }
107  
108 if($k->is_stored($db)) {
109 warning("KaryotypeBand [".$k->dbID."] is already stored" .
110 " in this database.");
111 next BAND;
112 }
113  
114 my $original = $k;
115 my $seq_region_id;
116 ($k, $seq_region_id) = $self->_pre_store($k);
117  
118 $sth->bind_param(1,$seq_region_id,SQL_INTEGER);
119 $sth->bind_param(2,$k->start,SQL_INTEGER);
120 $sth->bind_param(3,$k->end,SQL_INTEGER);
121 $sth->bind_param(4,$k->name,SQL_VARCHAR);
122 $sth->bind_param(5,$k->stain,SQL_VARCHAR);
123  
124 $sth->execute();
125  
126 $original->dbID($self->last_insert_id('karyotype_id', undef, 'karyotype'));
127 $original->adaptor($self);
128 }
129 }
130  
131  
132 #_tables
133 #
134 # Arg [1] : none
135 # Example : none
136 # Description: PROTECTED Implementation of abstract superclass method to
137 # provide the name of the tables to query
138 # Returntype : string
139 # Exceptions : none
140 # Caller : internal
141  
142  
143 sub _tables {
144 my $self = shift;
145  
146 return (['karyotype','k'])
147 }
148  
149  
150 #_columns
151  
152 # Arg [1] : none
153 # Example : none
154 # Description: PROTECTED Implementation of abstract superclass method to
155 # provide the name of the columns to query
156 # Returntype : list of strings
157 # Exceptions : none
158 # Caller : internal
159  
160 sub _columns {
161 my $self = shift;
162  
163 #warning _objs_from_sth implementation depends on ordering
164 return qw (
165 k.karyotype_id
166 k.seq_region_id
167 k.seq_region_start
168 k.seq_region_end
169 k.band
170 k.stain );
171 }
172  
173  
174 sub _objs_from_sth {
175 my ($self, $sth) = @_;
176 my $db = $self->db();
177 my $slice_adaptor = $db->get_SliceAdaptor();
178  
179 my @features;
180 my %slice_cache;
181  
182 my($karyotype_id,$seq_region_id,$seq_region_start,$seq_region_end,
183 $band,$stain);
184  
185 $sth->bind_columns(\$karyotype_id, \$seq_region_id, \$seq_region_start,
186 \$seq_region_end, \$band, \$stain);
187  
188 while ( $sth->fetch() ) {
189 #need to get the internal_seq_region, if present
190 $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
191  
192 my $slice = $slice_cache{$seq_region_id} ||=
193 $slice_adaptor->fetch_by_seq_region_id($seq_region_id);
194  
195 push( @features,
196 $self->_create_feature( 'Bio::EnsEMBL::KaryotypeBand', {
197 -START => $seq_region_start,
198 -END => $seq_region_end,
199 -SLICE => $slice,
200 -ADAPTOR => $self,
201 -DBID => $karyotype_id,
202 -NAME => $band,
203 -STAIN => $stain
204 } ) );
205  
206 }
207  
208 return \@features;
209 }
210  
211  
212  
213 =head2 fetch_all_by_chr_name
214  
215 Arg [1] : string $chr_name
216 Name of the chromosome from which to retrieve band objects
217 Example : @bands=@{$karyotype_band_adaptor->fetch_all_by_chr_name('X')};
218 Description: Fetches all the karyotype band objects from the database for the
219 given chromosome.
220 Returntype : listref of Bio::EnsEMBL::KaryotypeBand in chromosomal
221 (assembly) coordinates
222 Exceptions : none
223 Caller : general
224 Status : Stable
225  
226 =cut
227  
228 sub fetch_all_by_chr_name {
229 my ($self,$chr_name) = @_;
230
231 throw('Chromosome name argument expected') if(!$chr_name);
232  
233 my $slice =
234 $self->db->get_SliceAdaptor->fetch_by_region(undef, $chr_name);
235 unless ($slice){
236 warning("Cannot retrieve chromosome $chr_name");
237 return;
238 }
239 return $self->fetch_all_by_Slice($slice);
240 }
241  
242  
243  
244 sub fetch_all_by_chr_band {
245 my ($self, $chr_name, $band) = @_;
246  
247 throw('Chromosome name argument expected') if(!$chr_name);
248 throw('Band argument expected') if(!$band);
249  
250 my $slice = $self->db->get_SliceAdaptor->fetch_by_region(undef,
251 $chr_name);
252  
253 my $constraint = "k.band like '$band%'";
254 return $self->fetch_all_by_Slice_constraint($slice,$constraint);
255 }
256  
257  
258 =head2 list_dbIDs
259  
260 Arg [1] : none
261 Example : @kary_ids = @{$karyotype_band_adaptor->list_dbIDs()};
262 Description: Gets an array of internal ids for all karyotype bands in the
263 current db
264 Arg[1] : <optional> int. not 0 for the ids to be sorted by the seq_region.
265 Returntype : reference to a list of ints
266 Exceptions : none
267 Caller : ?
268 Status : Stable
269  
270 =cut
271  
272 sub list_dbIDs {
273 my ($self, $ordered) = @_;
274  
275 return $self->_list_dbIDs("karyotype",undef, $ordered);
276 }
277  
278  
279 1;