EnsEMBL/DBSQL/RepeatConsensusAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 12 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 101 CC 3 SCAR 11.2
CC
3
Cov
0%
_generic_fetch
6.0
store
6.0
fetch_all_repeat_types
2.0
CRAP 3.1
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::RepeatConsensusAdaptor
34  
35 =head1 SYNOPSIS
36  
37 $rca = $database_adaptor->get_RepeatConsensusAdaptor();
38  
39 $repeat_consensus = $rca->fetch_by_dbID(132);
40 $repeat_consensus = $rca->fetch_by_name_class( 'AluSx', 'SINE/Alu' );
41  
42 $rca->store( $rc1, $rc2, $rc3 );
43  
44 =head1 DESCRIPTION
45  
46 This is an adaptor for the retrieval and storage of RepeatConsensus
47 objects.
48  
49 =head1 METHODS
50  
51 =cut
52  
53 package Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor;
54 $Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::VERSION = '114.0.0_50'; # TRIAL
55 $Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor::VERSION = '114.0.050';
56 use strict;
57 use warnings;
58 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
59 use Bio::EnsEMBL::RepeatConsensus;
60 use Bio::EnsEMBL::Utils::Exception qw(throw);
61  
62 use base qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
63  
64 =head2 fetch_all_repeat_types
65  
66 Example : my $types = $rca->fetch_all_repeat_types();
67 Description : Returns the distinct repeat types available from a database
68 Returntype : Array
69 Exceptions : -
70  
71 =cut
72  
73  
74 sub fetch_all_repeat_types {
75 my ($self) = @_;
76 return $self->dbc()->sql_helper()->execute_simple(
77 -SQL => 'SELECT DISTINCT repeat_type FROM repeat_consensus');
78 }
79  
80  
81 =head2 fetch_by_dbID
82  
83 Arg [1] : int $db_id
84 The database identifier for the RepeatConsensus to obtain
85 Example : $repeat_consensus = $repeat_consensus_adaptor->fetch_by_dbID(4);
86 Description: Obtains a RepeatConsensus object from the database via its
87 primary key.
88 Returntype : Bio::EnsEMBL::RepeatConsensus
89 Exceptions : none
90 Caller : general, Bio::EnsEMBL::RepeatFeatureAdaptor
91 Status : Stable
92  
93 =cut
94  
95 sub fetch_by_dbID {
96 my( $self, $db_id ) = @_;
97  
98 my ($rc) = @{$self->_generic_fetch("repeat_consensus_id = $db_id")};
99  
100 return $rc;
101 }
102  
103  
104  
105 =head2 fetch_by_name
106  
107 Arg [1] : string $name
108 the name of the repeat consensus to obtain
109 Example : $rc = $repeat_consensus_adaptor->fetch_by_name('AluSx');
110 Description: Obtains a repeat consensus from the database via its name
111 Returntype : Bio::EnsEMBL::RepeatConsensus
112 Exceptions : none
113 Caller : general
114 Status : Stable
115  
116 =cut
117  
118 sub fetch_by_name {
119 my( $self, $name ) = @_;
120  
121 my ($rc) = @{$self->_generic_fetch("repeat_name = '$name'")};
122  
123 return $rc;
124 }
125  
126  
127 =head2 fetch_by_name_class
128  
129 Arg [1] : string $name
130 the name of the repeat consensus to obtain
131 Arg [2] : string $class
132 the class of the repeat consensus to obtain
133 Example : $rc = $repeat_consensus_adaptor->
134 fetch_by_name_class('AluSx', 'SINE/Alu');
135 Description: Obtains a repeat consensus from the database
136 via its name and class
137 Returntype : Bio::EnsEMBL::RepeatConsensus
138 Exceptions : none
139 Caller : general
140 Status : Stable
141  
142 =cut
143  
144 sub fetch_by_name_class {
145 my( $self, $name, $class ) = @_;
146  
147  
148 my ($rc) = @{$self->_generic_fetch(qq{
149 repeat_name = '$name'
150 AND repeat_class = '$class'
151 })};
152  
153 return $rc;
154 }
155  
156  
157 =head2 fetch_all_by_class_seq
158  
159 Arg [1] : string $class
160 the class of the repeat consensus to obtain
161 Arg [2] : string $seq
162 the sequence of the repeat consensus to obtain
163 Example : $rc = $repeat_consensus_adaptor->
164 fetch_all_by_class_seq('trf', 'ATGGTGTCA');
165 Description: Obtains a repeat consensus from the database
166 via its class and sequence
167 Returntype : listREF of Bio::EnsEMBL::RepeatConsensus
168 Exceptions : none
169 Caller : general
170 Status : Stable
171  
172 =cut
173  
174 sub fetch_all_by_class_seq {
175 my( $self, $class, $seq ) = @_;
176  
177 return $self->_generic_fetch(qq{
178 repeat_class = '$class'
179 AND repeat_consensus = '$seq'
180 });
181 }
182  
183  
184 =head2 _generic_fetch
185  
186 Arg [1] : string $where_clause
187 Example : none
188 Description: PRIVATE used to create RepeatConsensus features from an
189 SQL constraint
190 Returntype : listref of Bio::EnsEMBL::RepeatConsensus objects
191 Exceptions : none
192 Caller : internal
193 Status : Stable
194  
195 =cut
196  
197 sub _generic_fetch {
198 my( $self, $where_clause ) = @_;
199  
200 my( $repeat_consensus_id, $repeat_name, $repeat_class,$repeat_length,
201 $repeat_consensus, $repeat_type );
202  
203 my $sth = $self->prepare(qq{
204 SELECT repeat_consensus_id
205 , repeat_name
206 , repeat_class
207 , repeat_type
208 , repeat_consensus
209 FROM repeat_consensus
210 WHERE }. $where_clause);
211  
212 $sth->execute;
213 $sth->bind_columns(
214 \$repeat_consensus_id,
215 \$repeat_name,
216 \$repeat_class,
217 \$repeat_type,
218 \$repeat_consensus
219 );
220  
221
222 my @consensi;
223 while ($sth->fetch) {
224 if ($repeat_consensus =~ /^(\d+)\(N\)$/) {
225 $repeat_length = $1;
226 } else {
227 $repeat_length = CORE::length($repeat_consensus);
228 }
229  
230 push @consensi, Bio::EnsEMBL::RepeatConsensus->new
231 (-DBID => $repeat_consensus_id,
232 -NAME => $repeat_name,
233 -REPEAT_CLASS => $repeat_class,
234 -REPEAT_TYPE => $repeat_type,
235 -LENGTH => $repeat_length,
236 -ADAPTOR => $self,
237 -REPEAT_CONSENSUS => $repeat_consensus);
238 }
239 return \@consensi;
240 }
241  
242  
243 =head2 store
244  
245 Arg [1] : list of Bio::EnsEMBL::RepeatConsensus @consensi
246 Example : $repeat_consensus_adaptor->store(@consensi);
247 Description: stores a list of RepeatConsensus objects in the database
248 Returntype : none
249 Exceptions : none
250 Caller : ?
251 Status : Stable
252  
253 =cut
254  
255 sub store {
256 my( $self, @consensi ) = @_;
257  
258 my $sth = $self->prepare(q{
259 INSERT into repeat_consensus( repeat_consensus_id
260 , repeat_name
261 , repeat_class
262 , repeat_type
263 , repeat_consensus )
264 VALUES (NULL, ?,?,?,?)
265 });
266  
267 foreach my $rc (@consensi) {
268 my $name = $rc->name
269 or throw("name not set");
270 my $class = $rc->repeat_class
271 or throw("repeat_class not set");
272 my $type = $rc->repeat_type();
273 $type = "" unless defined $type;
274 my $seq = $rc->repeat_consensus
275 or throw("repeat_consensus not set");
276  
277 $sth->bind_param(1,$name,SQL_VARCHAR);
278 $sth->bind_param(2,$class,SQL_VARCHAR);
279 $sth->bind_param(3,$type,SQL_VARCHAR);
280 $sth->bind_param(4,$seq,SQL_LONGVARCHAR);
281  
282 $sth->execute();
283  
284 my $db_id = $self->last_insert_id('repeat_consensus_id', undef, 'repeat_consensus')
285 or throw("Didn't get an insertid from the INSERT statement");
286  
287 $rc->dbID($db_id);
288 $rc->adaptor($self);
289 }
290 }
291  
292 1;
293  
294 __END__