3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
24 Please email comments or questions to the
public Ensembl
25 developers list at <http:
27 Questions may also be sent to the Ensembl help desk at
41 -host =>
'ensembldb.ensembl.org',
48 my @prot_feats = @{ $pfa->fetch_all_by_translation_id(1231) };
50 my $prot_feat = $pfa->fetch_by_dbID(523);
56 package Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor;
67 =head2 fetch_all_by_translation_id
70 the
internal id of the translation corresponding to protein
71 whose features are desired
72 Example : @prot_feats =
73 @{ $prot_feat_adaptor->fetch_by_translation_id(1234) };
74 Description: Gets all protein features present on a peptide
using the
75 translations
internal identifier. This method will
return
76 an unsorted list of all protein_feature types. The feature
77 types may be distinguished
using the logic name attribute of
78 the attached analysis objects.
79 Returntype : listref of Bio::EnsEMBL::ProteinFeatures
86 sub fetch_all_by_translation_id {
87 my ($self, $translation_id, $logic_name) = @_;
89 my $constraint =
"pf.translation_id = ?";
91 if(defined $logic_name){
92 my $logic_constraint = $self->_logic_name_to_constraint(
'', $logic_name );
93 $constraint .=
" AND ".$logic_constraint
if defined $logic_constraint;
95 $self->bind_param_generic_fetch($translation_id, SQL_INTEGER);
96 my $features = $self->generic_fetch($constraint);
99 } ## end sub fetch_all_by_translation_id
101 =head2 fetch_all_by_logic_name
103 Arg [1] :
string $logic_name
104 the logic name of the type of features to obtain
105 Example : $fs = $a->fetch_all_by_logic_name(
'foobar');
106 Description: Returns a listref of features created from the database.
107 only features with an analysis of type $logic_name will
108 be returned. If the logic name is invalid (not in the
109 analysis table), a reference to an empty list will be
111 Returntype : listref of Bio::EnsEMBL::ProteinFeatures
112 Exceptions : thrown
if no $logic_name
118 sub fetch_all_by_logic_name {
119 my ( $self, $logic_name ) = @_;
121 if ( !defined($logic_name) ) {
122 throw(
"Need a logic_name");
125 my $constraint = $self->_logic_name_to_constraint(
'', $logic_name );
127 if ( !defined($constraint) ) {
128 warning(
"Invalid logic name: $logic_name");
132 return $self->generic_fetch($constraint);
137 Arg [1] :
int $protfeat_id
138 the unique database identifier of the protein feature to obtain
139 Example : my $feature = $prot_feat_adaptor->fetch_by_dbID();
140 Description: Obtains a protein feature
object via its unique
id
141 Returntype : Bio::EnsEMBL::ProteinFeauture
149 my ($self, $protfeat_id) = @_;
151 my @select_cols = $self->_tbl_columns(1); # skip pk - protein_feature_id
152 my @select_cols_alias =
map {
'pf.'.$_ } @select_cols;
153 my $select_sql =
"SELECT ". (join
',', @select_cols_alias);
155 $select_sql .=
", x.description, x.display_label, i.interpro_ac "
156 .
"FROM protein_feature pf "
157 .
"LEFT JOIN interpro AS i ON pf.hit_name = i.id "
158 .
"LEFT JOIN xref AS x ON x.dbprimary_acc = i.interpro_ac "
159 .
"WHERE pf.protein_feature_id = ?";
161 my $sth = $self->prepare($select_sql);
163 $sth->bind_param(1, $protfeat_id, SQL_INTEGER);
164 my $res = $sth->execute();
166 my $pf_hash_ref = $sth->fetchrow_hashref();
168 if($sth->rows == 0) {
175 my $analysis = $self->db->get_AnalysisAdaptor->fetch_by_dbID($pf_hash_ref->{analysis_id});
177 my( $cigar_string, $align_type);
178 $cigar_string = $pf_hash_ref->{cigar_line}
if exists $pf_hash_ref->{cigar_line}; # available > e92
179 $align_type = $pf_hash_ref->{align_type}
if exists $pf_hash_ref->{align_type}; # available > e92
184 -DBID => $protfeat_id,
185 -START => $pf_hash_ref->{seq_start},
186 -END => $pf_hash_ref->{seq_end},
187 -HSTART => $pf_hash_ref->{hit_start},
188 -HEND => $pf_hash_ref->{hit_end},
189 -HSEQNAME => $pf_hash_ref->{hit_name},
190 -HDESCRIPTION => $pf_hash_ref->{hit_description},
191 -ANALYSIS => $analysis,
192 -SCORE => $pf_hash_ref->{score},
193 -P_VALUE => $pf_hash_ref->{evalue},
194 -PERCENT_ID => $pf_hash_ref->{perc_ident},
195 -IDESC => $pf_hash_ref->{description},
196 -ILABEL => $pf_hash_ref->{display_label},
197 -INTERPRO_AC => $pf_hash_ref->{interpro_ac},
198 -TRANSLATION_ID => $pf_hash_ref->{translation_id},
199 -CIGAR_STRING => $cigar_string,
200 -ALIGN_TYPE => $align_type
202 } ## end sub fetch_by_dbID
207 The feature to be stored
208 Arg [2] :
int $translation_id
210 Example : $protein_feature_adaptor->store($protein_feature);
211 Description: Stores a protein feature in the database
212 Returntype :
int - the
new internal identifier of the stored protein feature
220 my ($self, $feature, $translation_id) = @_;
222 if (!ref($feature) || !$feature->isa(
'Bio::EnsEMBL::ProteinFeature')) {
223 throw(
"ProteinFeature argument is required");
226 my $db = $self->db();
228 if ($feature->is_stored($db)) {
229 warning(
"ProteinFeature " . $feature->dbID() .
" is already stored in " .
"this database - not storing again");
232 my $analysis = $feature->analysis();
233 if (!defined($analysis)) {
234 throw(
"Feature doesn't have analysis. Can't write to database");
236 if (!$analysis->is_stored($db)) {
237 $db->get_AnalysisAdaptor->store($analysis);
240 my $insert_ignore = $self->insert_ignore_clause();
241 my @insert_cols = $self->_tbl_columns(1); # skip pk - protein_feature_id
243 my @insert_values =
map {
'?' } @insert_cols;
244 my $insert_stmt =
"${insert_ignore} INTO protein_feature (". (join
',', @insert_cols) .
') VALUES (' . (join
',', @insert_values) .
')';
246 my $sth = $self->prepare($insert_stmt);
249 $sth->bind_param(++$i, $translation_id, SQL_INTEGER);
250 $sth->bind_param(++$i, $feature->start, SQL_INTEGER);
251 $sth->bind_param(++$i, $feature->end, SQL_INTEGER);
252 $sth->bind_param(++$i, $feature->hstart, SQL_INTEGER);
253 $sth->bind_param(++$i, $feature->hend, SQL_INTEGER);
254 $sth->bind_param(++$i, $feature->hseqname, SQL_VARCHAR);
255 $sth->bind_param(++$i, $analysis->dbID, SQL_INTEGER);
256 $sth->bind_param(++$i, $feature->score, SQL_DOUBLE);
257 $sth->bind_param(++$i, $feature->p_value, SQL_DOUBLE);
258 $sth->bind_param(++$i, $feature->percent_id, SQL_FLOAT);
259 $sth->bind_param(++$i, $feature->external_data, SQL_VARCHAR);
260 $sth->bind_param(++$i, $feature->hdescription, SQL_LONGVARCHAR);
262 if ($self->schema_version > 92) {
263 $sth->bind_param(++$i, $feature->cigar_string, SQL_VARCHAR);
264 $sth->bind_param(++$i, $feature->align_type, SQL_VARCHAR);
269 if (defined($sth->err) && $sth->err eq 0){ # is a warning
if 0 and defined
270 warning(
'SQL warning : ' . $sth->errstr .
"\n");
273 my $dbID = $self->last_insert_id(
'protein_feature_id', undef,
'protein_feature');
275 $feature->adaptor($self);
276 $feature->dbID($dbID);
286 return ([
'protein_feature',
'pf'], [
'interpro',
'ip'], [
'xref',
'x']);
290 return ([
'interpro',
"pf.hit_name = ip.id"], [
'xref',
"x.dbprimary_acc = ip.interpro_ac"]);
293 # return columns from protein_feature table
295 my ($self, $skip_pk) = @_;
296 $skip_pk = defined $skip_pk ? $skip_pk : 0;
314 $self->schema_version > 92 and push @columns, (
'cigar_line',
'align_type');
315 shift @columns
if $skip_pk;
319 # return columns from joined tables (xref and interpro) prefixed with alias
323 my @columns =
map{
"pf.".$_} $self->_tbl_columns();
325 push @columns, qw(x.description x.display_label ip.interpro_ac);
332 # Arg [1] : StatementHandle $sth
334 # Description: PROTECTED implementation of abstract superclass method.
335 # responsible for the creation of ProteinFeatures
336 # Returntype : listref of Bio::EnsEMBL::ProteinFeatures
342 my ($self, $sth) = @_;
344 my($dbID, $translation_id, $start, $end,
345 $hstart, $hend, $hid, $analysis_id,
346 $score, $evalue, $perc_id, $external_data,$hdesc,
347 $cigar_line, $align_type,
348 $desc, $ilabel, $interpro_ac);
351 $sth->bind_col(++$i, \$dbID);
352 $sth->bind_col(++$i, \$translation_id);
353 $sth->bind_col(++$i, \$start);
354 $sth->bind_col(++$i, \$end);
355 $sth->bind_col(++$i, \$hstart);
356 $sth->bind_col(++$i, \$hend);
357 $sth->bind_col(++$i, \$hid);
358 $sth->bind_col(++$i, \$analysis_id);
359 $sth->bind_col(++$i, \$score);
360 $sth->bind_col(++$i, \$evalue);
361 $sth->bind_col(++$i, \$perc_id);
362 $sth->bind_col(++$i, \$external_data);
363 $sth->bind_col(++$i, \$hdesc);
366 if ($self->schema_version > 92) {
367 $sth->bind_col(++$i, \$cigar_line);
368 $sth->bind_col(++$i, \$align_type);
371 $sth->bind_col(++$i, \$desc);
372 $sth->bind_col(++$i, \$ilabel);
373 $sth->bind_col(++$i, \$interpro_ac);
375 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
378 while($sth->fetch()) {
380 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
387 -SEQNAME => $translation_id,
390 -ANALYSIS => $analysis,
391 -PERCENT_ID => $perc_id,
397 -HDESCRIPTION => $hdesc,
400 -INTERPRO_AC => $interpro_ac,
401 -TRANSLATION_ID => $translation_id,
402 -CIGAR_STRING => $cigar_line,
403 -ALIGN_TYPE => $align_type,
411 =head2 fetch_all_by_uniprot_acc
414 The uniprot
accession of the features to obtain
415 Arg [2] : (optional)
string $logic_name
416 The analysis logic name of the type of features to
417 obtain. Default is
'gifts_import'
419 @{ $adaptor->fetch_all_by_uniprot_acc(
'P20366',
421 Description: Returns a listref of features created from the
422 database which correspond to the given uniprot
accession. If
423 logic name is defined, only features with an analysis
424 of type $logic_name will be returned. Defaults to
'gifts_import'
425 Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
426 Exceptions : thrown
if uniprot_acc is not defined
432 sub fetch_all_by_uniprot_acc {
433 my ( $self, $uniprot_acc, $logic_name ) = @_;
434 $logic_name = defined $logic_name ? $logic_name :
"gifts_import";
435 return $self->fetch_all_by_hit_name($uniprot_acc, $logic_name);
438 #inherited methods from BaseAlignFeatureAdaptor
439 sub fetch_all_by_Slice_and_hcoverage {
441 $self->throw(
"ProteinFeatures can't be fetched by slice as".
442 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
445 sub fetch_all_by_Slice_and_external_db {
447 $self->throw(
"ProteinFeatures can't be fetched by slice as".
448 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
451 sub fetch_all_by_Slice_and_pid {
453 $self->throw(
"ProteinFeatures can't be fetched by slice as".
454 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
457 sub fetch_all_by_Slice {
459 $self->throw(
"ProteinFeatures can't be fetched by slice as".
460 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
463 sub fetch_Iterator_by_Slice_method {
465 $self->throw(
"ProteinFeatures can't be fetched by slice as".
466 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
469 sub fetch_Iterator_by_Slice {
471 $self->throw(
"ProteinFeatures can't be fetched by slice as".
472 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
475 sub fetch_all_by_Slice_and_score {
477 $self->throw(
"ProteinFeatures can't be fetched by slice as".
478 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
481 sub fetch_all_by_Slice_constraint {
483 $self->throw(
"ProteinFeatures can't be fetched by slice as".
484 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
487 sub fetch_all_by_stable_id_list {
488 my ( $self, $id_list_ref, $slice ) = @_;
489 $self->throw(
"ProteinFeatures can't be fetched by slice as".
490 " they are not on EnsEMBL coord system. Try fetch_all_by_translation_id instead" );
493 sub count_by_Slice_constraint {
495 $self->throw(
"ProteinFeatures cant be count by slice as".
496 " they are not on EnsEMBL coord system." );
499 sub remove_by_Slice {
501 $self->throw(
"ProteinFeatures cant be removed by slice as".
502 " they are not on EnsEMBL coord system." );
505 sub get_seq_region_id_internal{
507 $self->throw(
"No seq_region_id as ProteinFeatures are not on EnsEMBL coord system." );
510 sub get_seq_region_id_external{
512 $self->throw(
"No seq_region_id as ProteinFeatures are not on EnsEMBL coord system." );