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