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