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::ProteinFeatureAdaptor
|
|
24
|
|
25 =head1 SYNOPSIS
|
|
26
|
|
27 use Bio::EnsEMBL::Registry;
|
|
28
|
|
29 Bio::EnsEMBL::Registry->load_registry_from_db(
|
|
30 -host => 'ensembldb.ensembl.org',
|
|
31 -user => 'anonymous'
|
|
32 );
|
|
33
|
|
34 $pfa = Bio::EnsEMBL::Registry->get_adaptor( "human", "core",
|
|
35 "proteinfeature" );
|
|
36
|
|
37 my @prot_feats = @{ $pfa->fetch_all_by_translation_id(1231) };
|
|
38
|
|
39 my $prot_feat = $pfa->fetch_by_dbID(523);
|
|
40
|
|
41 =head1 METHODS
|
|
42
|
|
43 =cut
|
|
44
|
|
45
|
|
46 package Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor;
|
|
47
|
|
48 use strict;
|
|
49
|
|
50 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
|
|
51 use Bio::EnsEMBL::ProteinFeature;
|
|
52 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning);
|
|
53
|
|
54 use vars qw(@ISA);
|
|
55 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
|
|
56
|
|
57
|
|
58 =head2 fetch_all_by_translation_id
|
|
59
|
|
60 Arg [1] : int $transl
|
|
61 the internal id of the translation corresponding to protein
|
|
62 whose features are desired
|
|
63 Example : @prot_feats =
|
|
64 @{ $prot_feat_adaptor->fetch_by_translation_id(1234) };
|
|
65 Description: Gets all protein features present on a peptide using the
|
|
66 translations internal identifier. This method will return
|
|
67 an unsorted list of all protein_feature types. The feature
|
|
68 types may be distinguished using the logic name attribute of
|
|
69 the attached analysis objects.
|
|
70 Returntype : listref of Bio::EnsEMBL::ProteinFeatures
|
|
71 Exceptions : none
|
|
72 Caller : ?
|
|
73 Status : Stable
|
|
74
|
|
75 =cut
|
|
76
|
|
77 sub fetch_all_by_translation_id {
|
|
78 my($self,$translation_id) = @_;
|
|
79
|
|
80 if(!$translation_id) {
|
|
81 throw("translation_id argument is required\n");
|
|
82 }
|
|
83
|
|
84 my @features;
|
|
85 my $analysis_adaptor = $self->db()->get_AnalysisAdaptor();
|
|
86
|
|
87 my $sth = $self->prepare
|
|
88 ("SELECT protein_feature_id, p.seq_start, p.seq_end, p.analysis_id, " .
|
|
89 " p.score, p.perc_ident, p.evalue, p.hit_start, p.hit_end, " .
|
|
90 " p.hit_name, x.display_label, i.interpro_ac " .
|
|
91 "FROM protein_feature p " .
|
|
92 "LEFT JOIN interpro AS i ON p.hit_name = i.id " .
|
|
93 "LEFT JOIN xref AS x ON x.dbprimary_acc = i.interpro_ac " .
|
|
94 "WHERE p.translation_id = ?");
|
|
95
|
|
96 $sth->bind_param(1,$translation_id,SQL_INTEGER);
|
|
97 $sth->execute();
|
|
98
|
|
99 while( my $row = $sth->fetchrow_arrayref) {
|
|
100 my ($dbID, $start, $end, $analysisid, $score, $perc_id, $evalue, $hstart,
|
|
101 $hend,$hid,$desc, $interpro_ac) = @$row;
|
|
102
|
|
103 my $analysis = $analysis_adaptor->fetch_by_dbID($analysisid);
|
|
104
|
|
105 if(!$analysis) {
|
|
106 warning("Analysis with dbID=$analysisid does not exist\n" .
|
|
107 "but is referenced by ProteinFeature $dbID");
|
|
108 }
|
|
109
|
|
110 my $feat = Bio::EnsEMBL::ProteinFeature->new
|
|
111 (-DBID => $dbID,
|
|
112 -ADAPTOR => $self,
|
|
113 -SEQNAME => $translation_id,
|
|
114 -START => $start,
|
|
115 -END => $end,
|
|
116 -ANALYSIS => $analysis,
|
|
117 -PERCENT_ID => $perc_id,
|
|
118 -P_VALUE => $evalue,
|
|
119 -SCORE => $score,
|
|
120 -HSTART => $hstart,
|
|
121 -HEND => $hend,
|
|
122 -HSEQNAME => $hid,
|
|
123 -IDESC => $desc,
|
|
124 -INTERPRO_AC => $interpro_ac);
|
|
125
|
|
126 push(@features,$feat);
|
|
127 }
|
|
128
|
|
129 $sth->finish();
|
|
130
|
|
131 return \@features;
|
|
132 }
|
|
133
|
|
134
|
|
135 =head2 fetch_by_dbID
|
|
136
|
|
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
|
|
142 Exceptions : none
|
|
143 Caller : ?
|
|
144 Status : Stable
|
|
145
|
|
146 =cut
|
|
147
|
|
148 sub fetch_by_dbID{
|
|
149 my ($self,$protfeat_id) = @_;
|
|
150
|
|
151 my $sth = $self->prepare(
|
|
152 "SELECT p.seq_start, p.seq_end, p.analysis_id, " .
|
|
153 " p.score, p.perc_ident, p.evalue, " .
|
|
154 " p.hit_start, p.hit_end, p.hit_name, " .
|
|
155 " x.display_label, i.interpro_ac " .
|
|
156 "FROM protein_feature p " .
|
|
157 "LEFT JOIN interpro AS i ON p.hit_name = i.id " .
|
|
158 "LEFT JOIN xref AS x ON x.dbprimary_acc = i.interpro_ac " .
|
|
159 "WHERE p.protein_feature_id = ?");
|
|
160
|
|
161 $sth->bind_param(1,$protfeat_id,SQL_INTEGER);
|
|
162 my $res = $sth->execute();
|
|
163
|
|
164 if($sth->rows == 0) {
|
|
165 $sth->finish();
|
|
166 return undef;
|
|
167 }
|
|
168
|
|
169 my ($start, $end, $analysis_id, $score, $perc_ident, $pvalue, $hstart,
|
|
170 $hend, $hseqname, $idesc, $interpro_ac) = $sth->fetchrow_array();
|
|
171
|
|
172 $sth->finish();
|
|
173
|
|
174 my $analysis = $self->db->get_AnalysisAdaptor->fetch_by_dbID($analysis_id);
|
|
175
|
|
176 return Bio::EnsEMBL::ProteinFeature->new
|
|
177 (-ADAPTOR => $self,
|
|
178 -DBID => $protfeat_id,
|
|
179 -START => $start,
|
|
180 -END => $end,
|
|
181 -HSTART => $hstart,
|
|
182 -HEND => $hend,
|
|
183 -HSEQNAME => $hseqname,
|
|
184 -ANALYSIS => $analysis,
|
|
185 -SCORE => $score,
|
|
186 -P_VALUE => $pvalue,
|
|
187 -PERCENT_ID => $perc_ident,
|
|
188 -IDESC => $idesc,
|
|
189 -INTERPRO_AC => $interpro_ac);
|
|
190 }
|
|
191
|
|
192
|
|
193
|
|
194
|
|
195 =head2 store
|
|
196
|
|
197 Arg [1] : Bio::EnsEMBL::ProteinFeature $feature
|
|
198 The feature to be stored
|
|
199 Arg [2] : int $translation_id
|
|
200
|
|
201 Example : $protein_feature_adaptor->store($protein_feature);
|
|
202 Description: Stores a protein feature in the database
|
|
203 Returntype : int - the new internal identifier of the stored protein feature
|
|
204 Exceptions : thrown if arg is not a Bio::EnsEMBL:
|
|
205 Caller : none
|
|
206 Status : Stable
|
|
207
|
|
208 =cut
|
|
209
|
|
210 sub store {
|
|
211 my ($self,$feature, $translation_id) = @_;
|
|
212
|
|
213 if(!ref($feature) || !$feature->isa('Bio::EnsEMBL::ProteinFeature')) {
|
|
214 throw("ProteinFeature argument is required");
|
|
215 }
|
|
216
|
|
217 if(!$translation_id) {
|
|
218 deprecate("Calling ProteinFeatureAdaptor without a translation_id is " .
|
|
219 "deprecated. Pass a translation_id argument rather than " .
|
|
220 "setting the ProteinFeature seqname to be the translation " .
|
|
221 "id");
|
|
222 $translation_id = $feature->seqname();
|
|
223 }
|
|
224
|
|
225 my $db = $self->db();
|
|
226
|
|
227 if($feature->is_stored($db)) {
|
|
228 warning("ProteinFeature " . $feature->dbID() . " is already stored in " .
|
|
229 "this database - not storing again");
|
|
230 }
|
|
231
|
|
232 my $analysis = $feature->analysis();
|
|
233 if (!defined($analysis)) {
|
|
234 throw("Feature doesn't have analysis. Can't write to database");
|
|
235 }
|
|
236
|
|
237 if(!$analysis->is_stored($db)) {
|
|
238 $db->get_AnalysisAdaptor->store($analysis);
|
|
239 }
|
|
240
|
|
241 my $sth =
|
|
242 $self->prepare("INSERT INTO protein_feature " .
|
|
243 " SET translation_id = ?, " .
|
|
244 " seq_start = ?, ".
|
|
245 " seq_end = ?, ".
|
|
246 " analysis_id = ?, ".
|
|
247 " hit_start = ?, ".
|
|
248 " hit_end = ?, ".
|
|
249 " hit_name = ?, ".
|
|
250 " score = ?, ".
|
|
251 " perc_ident = ?, ".
|
|
252 " evalue = ?");
|
|
253
|
|
254 $sth->bind_param(1,$translation_id,SQL_INTEGER);
|
|
255 $sth->bind_param(2,$feature->start,SQL_INTEGER);
|
|
256 $sth->bind_param(3,$feature->end,SQL_INTEGER);
|
|
257 $sth->bind_param(4,$analysis->dbID,SQL_INTEGER);
|
|
258 $sth->bind_param(5,$feature->hstart,SQL_INTEGER);
|
|
259 $sth->bind_param(6,$feature->hend,SQL_INTEGER);
|
|
260 $sth->bind_param(7,$feature->hseqname,SQL_VARCHAR);
|
|
261 $sth->bind_param(8,$feature->score,SQL_DOUBLE);
|
|
262 $sth->bind_param(9,$feature->percent_id,SQL_FLOAT);
|
|
263 $sth->bind_param(10,$feature->p_value,SQL_DOUBLE);
|
|
264
|
|
265 $sth->execute();
|
|
266
|
|
267 my $dbID = $sth->{'mysql_insertid'};
|
|
268
|
|
269 $feature->adaptor($self);
|
|
270 $feature->dbID($dbID);
|
|
271
|
|
272 $sth->finish();
|
|
273
|
|
274 return $dbID;
|
|
275 }
|
|
276
|
|
277
|
|
278
|
|
279 sub fetch_by_translation_id {
|
|
280 deprecate("Use fetch_all_by_translation_id instead.");
|
|
281 fetch_all_by_translation_id(@_);
|
|
282 }
|
|
283
|
|
284 sub fetch_all_by_feature_and_dbID {
|
|
285 my $self = shift;
|
|
286 my $feature = shift;
|
|
287 my $translation_id = shift;
|
|
288 deprecate("Use fetch_all_by_translation_id instead.");
|
|
289
|
|
290 print STDERR "translation_id = $translation_id feature = $feature\n";
|
|
291
|
|
292 my $features = $self->fetch_all_by_translation_id($translation_id);
|
|
293
|
|
294 my @out;
|
|
295 foreach my $f (@$features) {
|
|
296 my $logic_name = lc($f->analysis->logic_name());
|
|
297 print STDERR "LOGIC_NAME = $logic_name | FEATURE = $feature\n";
|
|
298 push(@out, $f) if($logic_name eq lc($feature));
|
|
299 }
|
|
300
|
|
301 return \@out;
|
|
302 }
|
|
303
|
|
304
|
|
305 sub save {
|
|
306
|
|
307 my ($self, $features) = @_;
|
|
308
|
|
309 my @feats = @$features;
|
|
310 throw("Must call save with features") if( scalar(@feats) == 0 );
|
|
311
|
|
312 # my @tabs = $self->_tables;
|
|
313 # my ($tablename) = @{$tabs[0]};
|
|
314 my $tablename = 'protein_feature';
|
|
315
|
|
316 my $db = $self->db();
|
|
317 my $analysis_adaptor = $db->get_AnalysisAdaptor();
|
|
318
|
|
319 my $sql = qq{INSERT INTO $tablename (translation_id, seq_start, seq_end, hit_start, hit_end, hit_name, analysis_id, score, evalue, perc_ident, external_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)};
|
|
320
|
|
321 my $sth = $self->prepare($sql);
|
|
322
|
|
323 foreach my $feat ( @feats ) {
|
|
324 if( !ref $feat || !$feat->isa("Bio::EnsEMBL::ProteinFeature") ) {
|
|
325 throw("feature must be a Bio::EnsEMBL::ProteinFeature,". " not a [".ref($feat)."].");
|
|
326 }
|
|
327
|
|
328 if($feat->is_stored($db)) {
|
|
329 warning("ProteinFeature [".$feat->dbID."] is already stored" .
|
|
330 " in this database.");
|
|
331 next;
|
|
332 }
|
|
333
|
|
334 my $hstart = defined $feat->hstart ? $feat->hstart : $feat->start ;
|
|
335 my $hend = defined $feat->hend ? $feat->hend : $feat->end;
|
|
336
|
|
337 if(!defined($feat->analysis)) {
|
|
338 throw("An analysis must be attached to the features to be stored.");
|
|
339 }
|
|
340
|
|
341 #store the analysis if it has not been stored yet
|
|
342 if(!$feat->analysis->is_stored($db)) {
|
|
343 $analysis_adaptor->store($feat->analysis());
|
|
344 }
|
|
345
|
|
346 my $original = $feat;
|
|
347 my $extra_data = $feat->extra_data ? $self->dump_data($feat->extra_data) : '';
|
|
348
|
|
349 $sth->bind_param(1,$feat->translation_id,SQL_INTEGER);
|
|
350 $sth->bind_param(2,$feat->start,SQL_INTEGER);
|
|
351 $sth->bind_param(3,$feat->end,SQL_INTEGER);
|
|
352 $sth->bind_param(4,$hstart,SQL_INTEGER);
|
|
353 $sth->bind_param(5,$hend,SQL_INTEGER);
|
|
354 $sth->bind_param(6,$feat->hseqname,SQL_VARCHAR);
|
|
355 $sth->bind_param(7,$feat->analysis->dbID,SQL_INTEGER);
|
|
356 $sth->bind_param(8,$feat->score,SQL_DOUBLE);
|
|
357 $sth->bind_param(9,$feat->p_value,SQL_DOUBLE);
|
|
358 $sth->bind_param(10,$feat->percent_id,SQL_FLOAT);
|
|
359 $sth->bind_param(11,$extra_data,SQL_LONGVARCHAR);
|
|
360
|
|
361 $sth->execute();
|
|
362 $original->dbID($sth->{'mysql_insertid'});
|
|
363 $original->adaptor($self);
|
|
364 }
|
|
365
|
|
366 $sth->finish();
|
|
367 }
|
|
368
|
|
369
|
|
370 1;
|
|
371
|