EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 174 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 9 Subroutinesub 0.0% 0 / 29 Podpod 0.0% 0 / 23 totaltotal 0.0% 0 / 269 CC 18 SCAR 26.5
CC
18
Cov
0%
store
56.0
fetch_by_dbID
20.0
fetch_all_by_translation_id
12.0
CRAP 14.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  
22 =head1 CONTACT
23  
24 Please email comments or questions to the public Ensembl
25 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
26  
27 Questions may also be sent to the Ensembl help desk at
28 <http://www.ensembl.org/Help/Contact>.
29  
30 =cut
31  
32 =head1 NAME
33  
34 Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor
35  
36 =head1 SYNOPSIS
37  
38 use Bio::EnsEMBL::Registry;
39  
40 Bio::EnsEMBL::Registry->load_registry_from_db(
41 -host => 'ensembldb.ensembl.org',
42 -user => 'anonymous'
43 );
44  
45 $pfa = Bio::EnsEMBL::Registry->get_adaptor( "human", "core",
46 "proteinfeature" );
47  
48 my @prot_feats = @{ $pfa->fetch_all_by_translation_id(1231) };
49  
50 my $prot_feat = $pfa->fetch_by_dbID(523);
51  
52 =head1 METHODS
53  
54 =cut
55  
56 package Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor;
57 $Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor::VERSION = '114.0.0_50'; # TRIAL
58 $Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor::VERSION = '114.0.050';
59 use strict;
60  
61 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
62 use Bio::EnsEMBL::ProteinFeature;
63 use Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;
64 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning);
65  
66 use parent qw(Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor);
67  
68 =head2 fetch_all_by_translation_id
69  
70 Arg [1] : int $transl
71 the internal id of the translation corresponding to protein
72 whose features are desired
73 Example : @prot_feats =
74 @{ $prot_feat_adaptor->fetch_by_translation_id(1234) };
75 Description: Gets all protein features present on a peptide using the
76 translations internal identifier. This method will return
77 an unsorted list of all protein_feature types. The feature
78 types may be distinguished using the logic name attribute of
79 the attached analysis objects.
80 Returntype : listref of Bio::EnsEMBL::ProteinFeatures
81 Exceptions : none
82 Caller : ?
83 Status : Stable
84  
85 =cut
86  
87 sub fetch_all_by_translation_id {
88 my ($self, $translation_id, $logic_name) = @_;
89  
90 my $constraint = "pf.translation_id = ?";
91  
92 if(defined $logic_name){
93 my $logic_constraint = $self->_logic_name_to_constraint( '', $logic_name );
94 $constraint .= " AND ".$logic_constraint if defined $logic_constraint;
95 }
96 $self->bind_param_generic_fetch($translation_id, SQL_INTEGER);
97 my $features = $self->generic_fetch($constraint);
98  
99 return $features;
100 } ## end sub fetch_all_by_translation_id
101  
102 =head2 fetch_all_by_logic_name
103  
104 Arg [1] : string $logic_name
105 the logic name of the type of features to obtain
106 Example : $fs = $a->fetch_all_by_logic_name('foobar');
107 Description: Returns a listref of features created from the database.
108 only features with an analysis of type $logic_name will
109 be returned. If the logic name is invalid (not in the
110 analysis table), a reference to an empty list will be
111 returned.
112 Returntype : listref of Bio::EnsEMBL::ProteinFeatures
113 Exceptions : thrown if no $logic_name
114 Caller : General
115 Status : Stable
116  
117 =cut
118  
119 sub fetch_all_by_logic_name {
120 my ( $self, $logic_name ) = @_;
121  
122 if ( !defined($logic_name) ) {
123 throw("Need a logic_name");
124 }
125  
126 my $constraint = $self->_logic_name_to_constraint( '', $logic_name );
127  
128 if ( !defined($constraint) ) {
129 warning("Invalid logic name: $logic_name");
130 return [];
131 }
132  
133 return $self->generic_fetch($constraint);
134 }
135  
136 =head2 fetch_by_dbID
137  
138 Arg [1] : int $protfeat_id
139 the unique database identifier of the protein feature to obtain
140 Example : my $feature = $prot_feat_adaptor->fetch_by_dbID();
141 Description: Obtains a protein feature object via its unique id
142 Returntype : Bio::EnsEMBL::ProteinFeauture
143 Exceptions : none
144 Caller : ?
145 Status : Stable
146  
147 =cut
148  
149 sub fetch_by_dbID {
150 my ($self, $protfeat_id) = @_;
151  
152 my @select_cols = $self->_tbl_columns(1); # skip pk - protein_feature_id
153 my @select_cols_alias = map { 'pf.'.$_ } @select_cols;
154 my $select_sql = "SELECT ". (join ',', @select_cols_alias);
155  
156 $select_sql .= ", x.description, x.display_label, i.interpro_ac "
157 . "FROM protein_feature pf "
158 . "LEFT JOIN interpro AS i ON pf.hit_name = i.id "
159 . "LEFT JOIN xref AS x ON x.dbprimary_acc = i.interpro_ac "
160 . "WHERE pf.protein_feature_id = ?";
161  
162 my $sth = $self->prepare($select_sql);
163  
164 $sth->bind_param(1, $protfeat_id, SQL_INTEGER);
165 my $res = $sth->execute();
166  
167 my $pf_hash_ref = $sth->fetchrow_hashref();
168  
169 if($sth->rows == 0) {
170 $sth->finish();
171 return undef;
172 }
173  
174 $sth->finish();
175  
176 my $analysis = $self->db->get_AnalysisAdaptor->fetch_by_dbID($pf_hash_ref->{analysis_id});
177  
178 my( $cigar_string, $align_type);
179 $cigar_string = $pf_hash_ref->{cigar_line} if exists $pf_hash_ref->{cigar_line}; # available > e92
180 $align_type = $pf_hash_ref->{align_type} if exists $pf_hash_ref->{align_type}; # available > e92
181  
182  
183 return
184 Bio::EnsEMBL::ProteinFeature->new(-ADAPTOR => $self,
185 -DBID => $protfeat_id,
186 -START => $pf_hash_ref->{seq_start},
187 -END => $pf_hash_ref->{seq_end},
188 -HSTART => $pf_hash_ref->{hit_start},
189 -HEND => $pf_hash_ref->{hit_end},
190 -HSEQNAME => $pf_hash_ref->{hit_name},
191 -HDESCRIPTION => $pf_hash_ref->{hit_description},
192 -ANALYSIS => $analysis,
193 -SCORE => $pf_hash_ref->{score},
194 -P_VALUE => $pf_hash_ref->{evalue},
195 -PERCENT_ID => $pf_hash_ref->{perc_ident},
196 -IDESC => $pf_hash_ref->{description},
197 -ILABEL => $pf_hash_ref->{display_label},
198 -INTERPRO_AC => $pf_hash_ref->{interpro_ac},
199 -TRANSLATION_ID => $pf_hash_ref->{translation_id},
200 -CIGAR_STRING => $cigar_string,
201 -ALIGN_TYPE => $align_type
202 );
203 } ## end sub fetch_by_dbID
204  
205 =head2 store
206  
207 Arg [1] : Bio::EnsEMBL::ProteinFeature $feature
208 The feature to be stored
209 Arg [2] : int $translation_id
210
211 Example : $protein_feature_adaptor->store($protein_feature);
212 Description: Stores a protein feature in the database
213 Returntype : int - the new internal identifier of the stored protein feature
214 Exceptions : thrown if arg is not a Bio::EnsEMBL:
215 Caller : none
216 Status : Stable
217  
218 =cut
219  
220 sub store {
221 my ($self, $feature, $translation_id) = @_;
222  
223 if (!ref($feature) || !$feature->isa('Bio::EnsEMBL::ProteinFeature')) {
224 throw("ProteinFeature argument is required");
225 }
226  
227 my $db = $self->db();
228  
229 if ($feature->is_stored($db)) {
230 warning("ProteinFeature " . $feature->dbID() . " is already stored in " . "this database - not storing again");
231 }
232  
233 my $analysis = $feature->analysis();
234 if (!defined($analysis)) {
235 throw("Feature doesn't have analysis. Can't write to database");
236 }
237 if (!$analysis->is_stored($db)) {
238 $db->get_AnalysisAdaptor->store($analysis);
239 }
240  
241 my $insert_ignore = $self->insert_ignore_clause();
242 my @insert_cols = $self->_tbl_columns(1); # skip pk - protein_feature_id
243  
244 my @insert_values = map { '?' } @insert_cols;
245 my $insert_stmt = "${insert_ignore} INTO protein_feature (". (join ',', @insert_cols) . ') VALUES (' . (join ',', @insert_values) . ')';
246  
247 my $sth = $self->prepare($insert_stmt);
248  
249 my $i = 0;
250 $sth->bind_param(++$i, $translation_id, SQL_INTEGER);
251 $sth->bind_param(++$i, $feature->start, SQL_INTEGER);
252 $sth->bind_param(++$i, $feature->end, SQL_INTEGER);
253 $sth->bind_param(++$i, $feature->hstart, SQL_INTEGER);
254 $sth->bind_param(++$i, $feature->hend, SQL_INTEGER);
255 $sth->bind_param(++$i, $feature->hseqname, SQL_VARCHAR);
256 $sth->bind_param(++$i, $analysis->dbID, SQL_INTEGER);
257 $sth->bind_param(++$i, $feature->score, SQL_DOUBLE);
258 $sth->bind_param(++$i, $feature->p_value, SQL_DOUBLE);
259 $sth->bind_param(++$i, $feature->percent_id, SQL_FLOAT);
260 $sth->bind_param(++$i, $feature->external_data, SQL_VARCHAR);
261 $sth->bind_param(++$i, $feature->hdescription, SQL_LONGVARCHAR);
262  
263 if ($self->schema_version > 92) {
264 $sth->bind_param(++$i, $feature->cigar_string, SQL_VARCHAR);
265 $sth->bind_param(++$i, $feature->align_type, SQL_VARCHAR);
266 }
267  
268 $sth->execute();
269  
270 if (defined($sth->err) && $sth->err eq 0){ # is a warning if 0 and defined
271 warning('SQL warning : ' . $sth->errstr ."\n");
272 }
273
274 my $dbID = $self->last_insert_id('protein_feature_id', undef, 'protein_feature');
275  
276 $feature->adaptor($self);
277 $feature->dbID($dbID);
278  
279 $sth->finish();
280  
281 return $dbID;
282 } ## end sub store
283  
284 sub _tables {
285 my $self = shift;
286  
287 return (['protein_feature', 'pf'], ['interpro', 'ip'], ['xref', 'x']);
288 }
289  
290 sub _left_join {
291 return (['interpro', "pf.hit_name = ip.id"], ['xref', "x.dbprimary_acc = ip.interpro_ac"]);
292 }
293  
294 # return columns from protein_feature table
295 sub _tbl_columns {
296 my ($self, $skip_pk) = @_;
297 $skip_pk = defined $skip_pk ? $skip_pk : 0;
298  
299 my @columns = qw(
300 protein_feature_id
301 translation_id
302 seq_start
303 seq_end
304 hit_start
305 hit_end
306 hit_name
307 analysis_id
308 score
309 evalue
310 perc_ident
311 external_data
312 hit_description
313 );
314  
315 $self->schema_version > 92 and push @columns, ('cigar_line', 'align_type');
316 shift @columns if $skip_pk;
317 return @columns;
318 }
319  
320 # return columns from joined tables (xref and interpro) prefixed with alias
321 sub _columns {
322 my $self = shift;
323  
324 my @columns = map{ "pf.".$_} $self->_tbl_columns();
325  
326 push @columns, qw(x.description x.display_label ip.interpro_ac);
327  
328 return @columns
329  
330 }
331  
332  
333 # Arg [1] : StatementHandle $sth
334 # Example : none
335 # Description: PROTECTED implementation of abstract superclass method.
336 # responsible for the creation of ProteinFeatures
337 # Returntype : listref of Bio::EnsEMBL::ProteinFeatures
338 # Exceptions : none
339 # Caller : internal
340 # Status : At Risk
341  
342 sub _objs_from_sth {
343 my ($self, $sth) = @_;
344  
345 my($dbID, $translation_id, $start, $end,
346 $hstart, $hend, $hid, $analysis_id,
347 $score, $evalue, $perc_id, $external_data,$hdesc,
348 $cigar_line, $align_type,
349 $desc, $ilabel, $interpro_ac);
350  
351 my $i = 0;
352 $sth->bind_col(++$i, \$dbID);
353 $sth->bind_col(++$i, \$translation_id);
354 $sth->bind_col(++$i, \$start);
355 $sth->bind_col(++$i, \$end);
356 $sth->bind_col(++$i, \$hstart);
357 $sth->bind_col(++$i, \$hend);
358 $sth->bind_col(++$i, \$hid);
359 $sth->bind_col(++$i, \$analysis_id);
360 $sth->bind_col(++$i, \$score);
361 $sth->bind_col(++$i, \$evalue);
362 $sth->bind_col(++$i, \$perc_id);
363 $sth->bind_col(++$i, \$external_data);
364 $sth->bind_col(++$i, \$hdesc);
365  
366  
367 if ($self->schema_version > 92) {
368 $sth->bind_col(++$i, \$cigar_line);
369 $sth->bind_col(++$i, \$align_type);
370 }
371  
372 $sth->bind_col(++$i, \$desc);
373 $sth->bind_col(++$i, \$ilabel);
374 $sth->bind_col(++$i, \$interpro_ac);
375  
376 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
377  
378 my @features;
379 while($sth->fetch()) {
380  
381 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
382  
383 push(
384 @features,
385 my $feat = Bio::EnsEMBL::ProteinFeature->new(
386 -DBID => $dbID,
387 -ADAPTOR => $self,
388 -SEQNAME => $translation_id,
389 -START => $start,
390 -END => $end,
391 -ANALYSIS => $analysis,
392 -PERCENT_ID => $perc_id,
393 -P_VALUE => $evalue,
394 -SCORE => $score,
395 -HSTART => $hstart,
396 -HEND => $hend,
397 -HSEQNAME => $hid,
398 -HDESCRIPTION => $hdesc,
399 -IDESC => $desc,
400 -ILABEL => $ilabel,
401 -INTERPRO_AC => $interpro_ac,
402 -TRANSLATION_ID => $translation_id,
403 -CIGAR_STRING => $cigar_line,
404 -ALIGN_TYPE => $align_type,
405 ));
406  
407 }
408 return \@features;
409 }
410  
411 #wrapper method
412 =head2 fetch_all_by_uniprot_acc
413  
414 Arg [1] : string uniprot accession
415 The uniprot accession of the features to obtain
416 Arg [2] : (optional) string $logic_name
417 The analysis logic name of the type of features to
418 obtain. Default is 'gifts_import'
419 Example : @feats =
420 @{ $adaptor->fetch_all_by_uniprot_acc( 'P20366',
421 'gifts_import' ); }
422 Description: Returns a listref of features created from the
423 database which correspond to the given uniprot accession. If
424 logic name is defined, only features with an analysis
425 of type $logic_name will be returned. Defaults to 'gifts_import'
426 Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
427 Exceptions : thrown if uniprot_acc is not defined
428 Caller : general
429 Status : Stable
430  
431 =cut
432  
433 sub fetch_all_by_uniprot_acc {
434 my ( $self, $uniprot_acc, $logic_name ) = @_;
435 $logic_name = defined $logic_name ? $logic_name : "gifts_import";
436 return $self->fetch_all_by_hit_name($uniprot_acc, $logic_name);
437 }
438  
439 #inherited methods from BaseAlignFeatureAdaptor
440 sub fetch_all_by_Slice_and_hcoverage {
441 my ( $self ) = @_;
442 $self->throw( "ProteinFeatures can't be fetched by slice as".
443 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
444 }
445  
446 sub fetch_all_by_Slice_and_external_db {
447 my ( $self ) = @_;
448 $self->throw( "ProteinFeatures can't be fetched by slice as".
449 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
450 }
451  
452 sub fetch_all_by_Slice_and_pid {
453 my ( $self ) = @_;
454 $self->throw( "ProteinFeatures can't be fetched by slice as".
455 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
456 }
457  
458 sub fetch_all_by_Slice {
459 my ( $self ) = @_;
460 $self->throw( "ProteinFeatures can't be fetched by slice as".
461 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
462 }
463  
464 sub fetch_Iterator_by_Slice_method {
465 my ( $self ) = @_;
466 $self->throw( "ProteinFeatures can't be fetched by slice as".
467 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
468 }
469  
470 sub fetch_Iterator_by_Slice {
471 my ( $self ) = @_;
472 $self->throw( "ProteinFeatures can't be fetched by slice as".
473 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
474 }
475  
476 sub fetch_all_by_Slice_and_score {
477 my ( $self ) = @_;
478 $self->throw( "ProteinFeatures can't be fetched by slice as".
479 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
480 }
481  
482 sub fetch_all_by_Slice_constraint {
483 my ( $self ) = @_;
484 $self->throw( "ProteinFeatures can't be fetched by slice as".
485 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
486 }
487  
488 sub fetch_all_by_stable_id_list {
489 my ( $self, $id_list_ref, $slice ) = @_;
490 $self->throw( "ProteinFeatures can't be fetched by slice as".
491 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
492 }
493  
494 sub count_by_Slice_constraint {
495 my ( $self ) = @_;
496 $self->throw( "ProteinFeatures cant be count by slice as".
497 " they are not on EnsEMBL coord system." );
498 }
499  
500 sub remove_by_Slice {
501 my ( $self ) = @_;
502 $self->throw( "ProteinFeatures cant be removed by slice as".
503 " they are not on EnsEMBL coord system." );
504 }
505  
506 sub get_seq_region_id_internal{
507 my ( $self ) = @_;
508 $self->throw( "No seq_region_id as ProteinFeatures are not on EnsEMBL coord system." );
509 }
510  
511 sub get_seq_region_id_external{
512 my ( $self ) = @_;
513 $self->throw( "No seq_region_id as ProteinFeatures are not on EnsEMBL coord system." );
514 }
515  
516 1;
517