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::UnmappedObjectAdaptor
|
|
24
|
|
25 =head1 SYNOPSIS
|
|
26
|
|
27 my $uoa = $database_adaptor->get_UnmappedObjectAdaptor();
|
|
28
|
|
29 my $missed = @{ $uoa->fetch_all_by_type('xref') };
|
|
30
|
|
31 =head1 DESCRIPTION
|
|
32
|
|
33 Unmapped ObjectAdaptor - An adaptor responsible for the creation,
|
|
34 editing, retrieval of Unmapped Objects. These being the Objects that
|
|
35 where not mapped in a specific process i.e. xref, cDNA, Markers.
|
|
36
|
|
37 =head1 METHODS
|
|
38
|
|
39 =cut
|
|
40
|
|
41 package Bio::EnsEMBL::DBSQL::UnmappedObjectAdaptor;
|
|
42 use vars qw(@ISA);
|
|
43 use strict;
|
|
44
|
|
45
|
|
46 use POSIX;
|
|
47 use Bio::EnsEMBL::Utils::Cache;
|
|
48 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
|
|
49 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
|
|
50 use Bio::EnsEMBL::UnmappedObject;
|
|
51 use Bio::EnsEMBL::Analysis;
|
|
52 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
|
|
53
|
|
54 our %desc_to_id;
|
|
55
|
|
56 =head2 new
|
|
57
|
|
58 Arg [1] : list of args @args
|
|
59 Superclass constructor arguments
|
|
60 Example : none
|
|
61 Description: Constructor which just initializes internal cache structures
|
|
62 Returntype : Bio::EnsEMBL::DBSQL::UnmappedObjectAdaptor
|
|
63 Exceptions : none
|
|
64 Caller : implementing subclass constructors
|
|
65 Status : At Risk
|
|
66
|
|
67 =cut
|
|
68
|
|
69 sub new {
|
|
70 my $proto = shift;
|
|
71
|
|
72 my $class = ref($proto) || $proto;
|
|
73
|
|
74 my $self = $class->SUPER::new(@_);
|
|
75
|
|
76 my $sth =
|
|
77 $self->prepare( "SELECT unmapped_reason_id, full_description "
|
|
78 . "FROM unmapped_reason" );
|
|
79
|
|
80 $sth->execute();
|
|
81
|
|
82 my ( $id, $desc );
|
|
83 $sth->bind_columns( \( $id, $desc ) );
|
|
84
|
|
85 while ( $sth->fetch() ) {
|
|
86 $desc_to_id{$desc} = $id;
|
|
87 }
|
|
88
|
|
89 $sth->finish();
|
|
90
|
|
91 return $self;
|
|
92 }
|
|
93
|
|
94
|
|
95 # _tables
|
|
96 # Arg [1] : none
|
|
97 # Description: PROTECTED implementation of superclass abstract method
|
|
98 # returns the names, aliases of the tables to use for queries
|
|
99 # Returntype : list of listrefs of strings
|
|
100 # Exceptions : none
|
|
101 # Caller : internal
|
|
102 # Status : At Risk
|
|
103 sub _tables {
|
|
104 my $self = shift;
|
|
105
|
|
106 return (['unmapped_object', 'uo'],
|
|
107 ['unmapped_reason', 'ur']);
|
|
108 }
|
|
109
|
|
110
|
|
111 # _columns
|
|
112 # Arg [1] : none
|
|
113 # Example : none
|
|
114 # Description: PROTECTED implementation of superclass abstract method
|
|
115 # returns a list of columns to use for queries
|
|
116 # Returntype : list of strings
|
|
117 # Exceptions : none
|
|
118 # Caller : internal
|
|
119 # Status : At Risk
|
|
120
|
|
121 sub _columns {
|
|
122 my $self = shift;
|
|
123
|
|
124 return qw(uo.unmapped_object_id uo.type uo.analysis_id uo.external_db_id
|
|
125 uo.identifier uo.unmapped_reason_id uo.query_score uo.target_score
|
|
126 uo.ensembl_id uo.ensembl_object_type
|
|
127 ur.summary_description ur.full_description);
|
|
128 }
|
|
129
|
|
130 sub _left_join {
|
|
131 return ( [
|
|
132 'unmapped_object', "uo.unmapped_reason_id = ur.unmapped_reason_id"
|
|
133 ] );
|
|
134 }
|
|
135
|
|
136 =head2 list_dbIDs
|
|
137
|
|
138 Arg [1] : none
|
|
139 Example : @unmapped_object_ids = @{$unmapped_object_adaptor->list_dbIDs()};
|
|
140 Description: Gets an array of internal ids for all unmapped_objects in the current db
|
|
141 Returntype : list of ints
|
|
142 Exceptions : none
|
|
143 Caller : ?
|
|
144 Status : Stable
|
|
145
|
|
146 =cut
|
|
147
|
|
148 sub list_dbIDs {
|
|
149 my ($self) = @_;
|
|
150
|
|
151 return $self->_list_dbIDs("unmapped_object");
|
|
152 }
|
|
153
|
|
154 =head2 list_unmapped_reasons
|
|
155
|
|
156 Arg [1] : none
|
|
157 Example : @unmapped_object_reason+ids =
|
|
158 @{$unmapped_object_adaptor->list_unmapped_reasons()};
|
|
159 Description: Gets an array of internal ids for all unmapped_objects in the current db
|
|
160 Returntype : list of ints
|
|
161 Exceptions : none
|
|
162 Caller : ?
|
|
163 Status : Stable
|
|
164
|
|
165 =cut
|
|
166
|
|
167 sub list_unmapped_reasons {
|
|
168 my ($self) = @_;
|
|
169
|
|
170 return $self->_list_dbIDs("unmapped_reason");
|
|
171 }
|
|
172
|
|
173
|
|
174 # _objs_from_sth
|
|
175
|
|
176 # Arg [1] : StatementHandle $sth
|
|
177 # Example : none
|
|
178 # Description: PROTECTED implementation of abstract superclass method.
|
|
179 # responsible for the creation of UnmappedObjects
|
|
180 # Returntype : listref of Bio::EnsEMBL::UnmappedObjects
|
|
181 # Exceptions : none
|
|
182 # Caller : internal
|
|
183 # Status : At Risk
|
|
184
|
|
185 sub _objs_from_sth {
|
|
186 my ($self, $sth) = @_;
|
|
187
|
|
188 my($unmapped_object_id, $type, $analysis_id, $external_db_id, $identifier,
|
|
189 $unmapped_reason_id, $query_score, $target_score, $ensembl_id,
|
|
190 $ensembl_object_type, $summary, $full_desc);
|
|
191
|
|
192 $sth->bind_columns(\$unmapped_object_id,\$type, \$analysis_id,
|
|
193 \$external_db_id, \$identifier, \$unmapped_reason_id,
|
|
194 \$query_score, \$target_score, \$ensembl_id,
|
|
195 \$ensembl_object_type, \$summary, \$full_desc);
|
|
196
|
|
197 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
|
|
198
|
|
199 my @features;
|
|
200 while($sth->fetch()) {
|
|
201 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
|
|
202
|
|
203 #print "$identifier\n";
|
|
204
|
|
205 push( @features,
|
|
206 $self->_create_feature(
|
|
207 'Bio::EnsEMBL::UnmappedObject', {
|
|
208 -unmapped_object_id => $unmapped_object_id,
|
|
209 -unmapped_reason_id => $unmapped_reason_id,
|
|
210 -type => $type,
|
|
211 -analysis => $analysis,
|
|
212 -external_db_id => $external_db_id,
|
|
213 -identifier => $identifier,
|
|
214 -query_score => $query_score,
|
|
215 -target_score => $target_score,
|
|
216 -ensembl_id => $ensembl_id,
|
|
217 -ensembl_object_type => $ensembl_object_type,
|
|
218 -summary => $summary,
|
|
219 -full_desc => $full_desc,
|
|
220 -adaptor => $self
|
|
221 } ) );
|
|
222
|
|
223 }
|
|
224 return \@features;
|
|
225 }
|
|
226
|
|
227
|
|
228
|
|
229 =head2 store
|
|
230
|
|
231 Arg [1] : list of Bio::EnsEMBL::UnmappedObjects @uo
|
|
232 the unmapped objects to store in the database
|
|
233 Example : $ou_adaptor->store(@uo);
|
|
234 Description: Stores a list of unmapped objects in the database
|
|
235 Returntype : none
|
|
236 Exceptions : thrown if no Analysis, or no list of objects to store.
|
|
237 Caller : general
|
|
238 Status : Stable
|
|
239
|
|
240 =cut
|
|
241
|
|
242 sub store{
|
|
243 my ($self,@uos) = @_;
|
|
244
|
|
245 if( scalar(@uos) == 0 ) {
|
|
246 throw("Must call store with list of UnmappedObjects");
|
|
247 }
|
|
248
|
|
249
|
|
250 my $db = $self->db();
|
|
251 my $analysis_adaptor = $db->get_AnalysisAdaptor();
|
|
252
|
|
253 my $sth_reason = $self->prepare
|
|
254 ("INSERT INTO unmapped_reason (summary_description, full_description)".
|
|
255 " VALUES (?,?)");
|
|
256
|
|
257 my $sth_unmapped_object = $self->prepare
|
|
258 ("INSERT INTO unmapped_object (type, analysis_id, external_db_id,
|
|
259 identifier, unmapped_reason_id, query_score, target_score,
|
|
260 ensembl_id, ensembl_object_type)".
|
|
261 " VALUES (?,?,?,?,?,?,?,?,?)");
|
|
262
|
|
263 FEATURE: foreach my $uo ( @uos ) {
|
|
264
|
|
265 if( !ref $uo || !$uo->isa("Bio::EnsEMBL::UnmappedObject") ) {
|
|
266 throw("UnmappedObject must be an Ensembl UnmappedObject, " .
|
|
267 "not a [".ref($uo)."]");
|
|
268 }
|
|
269 if($uo->is_stored($db)){
|
|
270 next;
|
|
271 }
|
|
272
|
|
273 my $analysis = $uo->analysis();
|
|
274 throw("UnmappedObject must have an analysis object.".$uo->analysis."\n") if(!defined($analysis));
|
|
275
|
|
276 my $analysis_id;
|
|
277 if($analysis->is_stored($db)) {
|
|
278 $analysis_id = $analysis->dbID();
|
|
279 } else {
|
|
280 $analysis_id = $db->get_AnalysisAdaptor->store($analysis);
|
|
281 }
|
|
282
|
|
283 #First check to see unmapped reason is stored
|
|
284 if(!defined($desc_to_id{$uo->{'description'}})){
|
|
285 $sth_reason->bind_param(1,$uo->{'summary'},SQL_VARCHAR);
|
|
286 $sth_reason->bind_param(2,$uo->{'description'},SQL_VARCHAR);
|
|
287 $sth_reason->execute();
|
|
288 $uo->{'unmapped_reason_id'} = $desc_to_id{$uo->{'description'}}
|
|
289 = $sth_reason->{'mysql_insertid'};
|
|
290
|
|
291 }
|
|
292 else{
|
|
293 $uo->{'unmapped_reason_id'} = $desc_to_id{$uo->{'description'}} ;
|
|
294 }
|
|
295 $sth_unmapped_object->bind_param(1,$uo->{'type'},SQL_VARCHAR);
|
|
296 $sth_unmapped_object->bind_param(2,$uo->analysis->dbID,SQL_INTEGER);
|
|
297 $sth_unmapped_object->bind_param(3,$uo->{'external_db_id'},SQL_INTEGER);
|
|
298 $sth_unmapped_object->bind_param(4,$uo->{'identifier'},SQL_VARCHAR);
|
|
299 $sth_unmapped_object->bind_param(5,$uo->{'unmapped_reason_id'},SQL_VARCHAR);
|
|
300 $sth_unmapped_object->bind_param(6,$uo->{'query_score'},SQL_DOUBLE);
|
|
301 $sth_unmapped_object->bind_param(7,$uo->{'target_score'},SQL_DOUBLE);
|
|
302 $sth_unmapped_object->bind_param(8,$uo->{'ensembl_id'},SQL_INTEGER);
|
|
303 $sth_unmapped_object->bind_param(9,$uo->{'ensembl_object_type'},SQL_VARCHAR);
|
|
304 $sth_unmapped_object->execute();
|
|
305 $uo->dbID($sth_unmapped_object->{'mysql_insertid'});
|
|
306 }
|
|
307 $sth_reason->finish();
|
|
308 return;
|
|
309 }
|
|
310
|
|
311
|
|
312 =head2 fetch_all_by_type
|
|
313
|
|
314 Arg [1] : string type. The type of unmapped objects
|
|
315 Example : @unmapped_object = @{$uoa->fetch_all_by_type('xref')};
|
|
316 Description : Retrieves all the unmapped object for a particular
|
|
317 type. e.g. 'xref','cDNA', 'marker'
|
|
318 Returntype : Array ref of Bio::EnsEMBL::UnmappedObject
|
|
319 Exceptions : none
|
|
320 Caller : general
|
|
321 Status : At Risk
|
|
322
|
|
323 =cut
|
|
324
|
|
325 sub fetch_all_by_type {
|
|
326 my ($self, $type) = @_;
|
|
327
|
|
328 unless($type) {
|
|
329 throw("type argument is required");
|
|
330 }
|
|
331 $self->bind_param_generic_fetch($type,SQL_VARCHAR);
|
|
332 $self->generic_fetch("uo.type = ?");
|
|
333
|
|
334 }
|
|
335
|
|
336 =head2 fetch_all_by_analysis
|
|
337
|
|
338 Arg [1] : Bio:EnsEMBL::Analysis object
|
|
339 Arg [2] : (optional) string database name
|
|
340 Example : @unmapped_object = @{$uoa->fetch_all_by_analysis($analysis)};
|
|
341 Description : Retrieves all the unmapped object for a particular
|
|
342 analysis type with the the option of a particular
|
|
343 database type.
|
|
344 Returntype : array ref of Bio::EnsEMBL::UnmappedObject
|
|
345 Exceptions : thorws if first argument is not an anaylisi object
|
|
346 Caller : general
|
|
347 Status : At Risk
|
|
348
|
|
349 =cut
|
|
350
|
|
351 sub fetch_all_by_analysis {
|
|
352 my ($self, $analysis,$dbname) = @_;
|
|
353
|
|
354 unless($analysis) {
|
|
355 throw("analysis argument is required");
|
|
356 }
|
|
357 $self->bind_param_generic_fetch($analysis->dbID,SQL_INTEGER);
|
|
358 my $constraint = "uo.analysis_id = ?";
|
|
359 if(defined($dbname)){
|
|
360 my $db_id =0;
|
|
361 my $sth = $self->prepare('select external_db_id from external_db where db_name like "'.
|
|
362 $dbname.'"');
|
|
363 $sth->execute;
|
|
364 $sth->bind_columns(\$db_id);
|
|
365 $sth->fetch();
|
|
366 if(!defined($db_id) or $db_id == 0){
|
|
367 throw("$dbname could not be found in the external database table\n");
|
|
368 }
|
|
369 $self->bind_param_generic_fetch($db_id,SQL_INTEGER);
|
|
370 $constraint .= " AND uo.external_db_id = ?";
|
|
371 }
|
|
372 $self->generic_fetch($constraint);
|
|
373
|
|
374 }
|
|
375
|
|
376 =head2 fetch_by_identifier
|
|
377
|
|
378 Arg [1] : string type. The type of unmapped objects
|
|
379 Arg [2] : (optional) string database name
|
|
380 Example : @unmapped_object = @{$uoa->fetch_by_identifier('Q123345')};
|
|
381 Description : Retrieves the unmapped object for a particular
|
|
382 identifier/accession
|
|
383 Returntype : array ref of Bio::EnsEMBL::UnmappedObject
|
|
384 Exceptions : none
|
|
385 Caller : general
|
|
386 Status : At Risk
|
|
387
|
|
388 =cut
|
|
389
|
|
390 sub fetch_by_identifier {
|
|
391 my ($self, $identifier, $dbname) = @_;
|
|
392
|
|
393 unless($identifier) {
|
|
394 throw("identifier argument is required");
|
|
395 }
|
|
396 $self->bind_param_generic_fetch($identifier,SQL_VARCHAR);
|
|
397 my $constraint = 'uo.identifier like ?';
|
|
398
|
|
399 if(defined($dbname)){
|
|
400 my $db_id =0;
|
|
401 my $sth = $self->prepare('select external_db_id from external_db where db_name like "'.
|
|
402 $dbname.'"');
|
|
403 $sth->execute;
|
|
404 $sth->bind_columns(\$db_id);
|
|
405 $sth->fetch();
|
|
406 if(!defined($db_id) or $db_id == 0){
|
|
407 throw("$dbname could not be found in the external database table\n");
|
|
408 }
|
|
409 $self->bind_param_generic_fetch($db_id,SQL_INTEGER);
|
|
410 $constraint .= " AND uo.external_db_id = ?";
|
|
411 }
|
|
412 return $self->generic_fetch($constraint);
|
|
413 }
|
|
414
|
|
415 =head2 fetch_all_by_object_type_id
|
|
416
|
|
417 Arg [1] : string - The object type of the ensembl object e.g. Gene
|
|
418 Arg [2] : int - The internal dbID of the ensembl object
|
|
419 Example : my @unmapped_objects = @{$uoa->fetch_all_by_object_type_id('Gene', 12341)};
|
|
420 Description : Retrieves the unmapped objects for a particular ensembl object
|
|
421 This is a base method which should be called by wrapper methods
|
|
422 defining the correct object type e.g. $uoa->fetch_all_by_Gene($gene)
|
|
423 Returntype : array ref of Bio::EnsEMBL::UnmappedObject objects
|
|
424 Exceptions : Throws if arguments are not defined
|
|
425 Caller : general
|
|
426 Status : At Risk
|
|
427
|
|
428 =cut
|
|
429
|
|
430 sub fetch_all_by_object_type_id {
|
|
431 my ($self, $object_type, $dbid) = @_;
|
|
432
|
|
433 if(! ($object_type && $dbid)){
|
|
434 throw("object_type and dbid arguments required");
|
|
435 }
|
|
436
|
|
437 $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
|
|
438 $self->bind_param_generic_fetch($dbid, SQL_INTEGER);
|
|
439
|
|
440 my $constraint = 'uo.ensembl_object_type=? and uo.ensembl_id=?';
|
|
441
|
|
442 return $self->generic_fetch($constraint);
|
|
443 }
|
|
444
|
|
445
|
|
446
|
|
447 1;
|