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::AnalysisAdaptor
|
|
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 $analysis_adaptor =
|
|
35 Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "analysis" );
|
|
36
|
|
37 my $analysis = $analysis_adaptor->fetch_by_logic_name('genscan');
|
|
38
|
|
39 =head1 DESCRIPTION
|
|
40
|
|
41 Module to encapsulate all db access for persistent class Analysis.
|
|
42 There should be just one per application and database connection.
|
|
43
|
|
44 =head1 METHODS
|
|
45
|
|
46 =cut
|
|
47
|
|
48
|
|
49 package Bio::EnsEMBL::DBSQL::AnalysisAdaptor;
|
|
50
|
|
51 use Bio::EnsEMBL::Analysis;
|
|
52 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
|
|
53 use Bio::EnsEMBL::Utils::Exception;
|
|
54
|
|
55
|
|
56 use vars qw(@ISA);
|
|
57 use strict;
|
|
58
|
|
59 @ISA = qw( Bio::EnsEMBL::DBSQL::BaseAdaptor);
|
|
60
|
|
61
|
|
62 =head2 new
|
|
63
|
|
64 Args : Bio::EnsEMBL::DBSQL::DBAdaptor
|
|
65 Example : my $aa = new Bio::EnsEMBL::DBSQL::AnalysisAdaptor();
|
|
66 Description: Creates a new Bio::EnsEMBL::DBSQL::AnalysisAdaptor object and
|
|
67 internally loads and caches all the Analysis objects from the
|
|
68 database.
|
|
69 Returntype : Bio::EnsEMBL::DBSQL::AnalysisAdaptor
|
|
70 Exceptions : none
|
|
71 Caller : Bio::EnsEMBL::DBSQL::DBAdaptor
|
|
72 Status : Stable
|
|
73
|
|
74 =cut
|
|
75
|
|
76 sub new {
|
|
77 my ($class, $db) = @_;
|
|
78
|
|
79 my $self = $class->SUPER::new($db);
|
|
80
|
|
81 #load and cache all of the Analysis objects
|
|
82 $self->fetch_all;
|
|
83
|
|
84 return $self;
|
|
85 }
|
|
86
|
|
87
|
|
88 =head2 fetch_all
|
|
89
|
|
90 Args : none
|
|
91 Example : my @analysis = @{$analysis_adaptor->fetch_all()};
|
|
92 Description: fetches all of the Analysis objects from the database and caches
|
|
93 them internally.
|
|
94 Returntype : listref of Bio::EnsEMBL::Analysis retrieved from the database
|
|
95 Exceptions : none
|
|
96 Caller : AnalysisAdaptor::new
|
|
97 Status : Stable
|
|
98
|
|
99 =cut
|
|
100
|
|
101 sub fetch_all {
|
|
102 my $self = shift;
|
|
103 my ( $analysis, $dbID );
|
|
104 my $rowHashRef;
|
|
105
|
|
106 $self->{_cache} = {};
|
|
107 $self->{_logic_name_cache} = {};
|
|
108
|
|
109 my $sth = $self->prepare( q {
|
|
110 SELECT analysis.analysis_id, logic_name,
|
|
111 program, program_version, program_file,
|
|
112 db, db_version, db_file,
|
|
113 module, module_version,
|
|
114 gff_source, gff_feature,
|
|
115 created, parameters, description, display_label, displayable, web_data
|
|
116 FROM analysis
|
|
117 LEFT JOIN analysis_description
|
|
118 ON analysis.analysis_id = analysis_description.analysis_id } );
|
|
119 $sth->execute;
|
|
120
|
|
121 while( $rowHashRef = $sth->fetchrow_hashref ) {
|
|
122 my $analysis = $self->_objFromHashref( $rowHashRef );
|
|
123
|
|
124 $self->{_cache}->{$analysis->dbID} = $analysis;
|
|
125 $self->{_logic_name_cache}->{lc($analysis->logic_name())} = $analysis;
|
|
126 }
|
|
127
|
|
128 my @ana = values %{$self->{_cache}};
|
|
129
|
|
130 return \@ana;
|
|
131 }
|
|
132
|
|
133
|
|
134 =head2 fetch_all_by_feature_class
|
|
135
|
|
136 Arg [1] : string $feature_cless - The name of the feature class
|
|
137 Example : my @analyses = @{$analysis_adaptor->fetch_all_by_feature_class('Gene');
|
|
138 Description: Returns all analyses that correspond to a given
|
|
139 feature class; see feature_classes method for a list.
|
|
140 Returntype : Listref of Bio::EnsEMBL::Analysis
|
|
141 Exceptions : none
|
|
142 Caller : general
|
|
143 Status : Stable
|
|
144
|
|
145 =cut
|
|
146
|
|
147 sub fetch_all_by_feature_class {
|
|
148 my $self = shift;
|
|
149 deprecate("Deprecated. Hard-coded logic is not supported");
|
|
150 my $feat_class = shift || throw( "Need a feature type, e.g. SimpleFeature" );
|
|
151
|
|
152 my @feature_classes = $self->feature_classes; # List of all feature classes
|
|
153 my %feat_table_map;
|
|
154 foreach my $class( @feature_classes ){
|
|
155 # Map e.g. DnaAlignFeature to dna_align_feature
|
|
156 my $table = join( "_", map lc, ( $class =~ /([A-Z][a-z]+)/g ) );
|
|
157 $feat_table_map{$class} = $table;
|
|
158 }
|
|
159 $feat_table_map{DensityFeature}='density_type'; # analysis_id in diff table
|
|
160 my $feat_table = $feat_table_map{$feat_class} ||
|
|
161 ( warning( "No feature type corresponding to $feat_class" ) &&
|
|
162 return [] );
|
|
163
|
|
164 my $sql_t = qq|
|
|
165 SELECT DISTINCT analysis_id FROM %s |;
|
|
166
|
|
167 my $sql = sprintf( $sql_t, $feat_table );
|
|
168 my $sth = $self->prepare( $sql );
|
|
169 my $rv = $sth->execute();
|
|
170 my $res = $sth->fetchall_arrayref;
|
|
171 my @analyses;
|
|
172 foreach my $r( @{$res} ){
|
|
173 my $analysis = $self->fetch_by_dbID($r->[0])
|
|
174 || throw( "analysis_id $r->[0] from $feat_table table "
|
|
175 . "is not in the analysis table!" );
|
|
176 push @analyses, $analysis;
|
|
177 }
|
|
178 return [@analyses];
|
|
179 }
|
|
180
|
|
181
|
|
182 =head2 feature_classes
|
|
183
|
|
184 Arg [1] : NONE
|
|
185 Example : my @fclasses = $analysis_adaptor->feature_classes;
|
|
186 Description: Returns a list of the different classes of Ensembl feature
|
|
187 object that have an analysis
|
|
188 Returntype : List of feature classes
|
|
189 Exceptions : none
|
|
190 Caller : general
|
|
191 Status : Stable
|
|
192
|
|
193 =cut
|
|
194
|
|
195 sub feature_classes{
|
|
196 deprecate("Deprecated. Hard-coded logic is not supported");
|
|
197 # Can't think of a way to do this programatically, so hard-coded
|
|
198 return qw(
|
|
199 DensityFeature
|
|
200 DnaAlignFeature
|
|
201 Gene
|
|
202 MarkerFeature
|
|
203 PredictionTranscript
|
|
204 ProteinAlignFeature
|
|
205 ProteinFeature
|
|
206 QtlFeature
|
|
207 RepeatFeature
|
|
208 SimpleFeature
|
|
209 );
|
|
210 }
|
|
211
|
|
212 =head2 fetch_by_dbID
|
|
213
|
|
214 Arg [1] : int $internal_analysis_id - the database id of the analysis
|
|
215 record to retrieve
|
|
216 Example : my $analysis = $analysis_adaptor->fetch_by_dbID(1);
|
|
217 Description: Retrieves an Analysis object from the database via its internal
|
|
218 id.
|
|
219 Returntype : Bio::EnsEMBL::Analysis
|
|
220 Exceptions : none
|
|
221 Caller : general
|
|
222 Status : Stable
|
|
223
|
|
224 =cut
|
|
225
|
|
226 sub fetch_by_dbID {
|
|
227 my $self = shift;
|
|
228 my $id = shift;
|
|
229
|
|
230 if( defined $self->{_cache}->{$id} ) {
|
|
231 return $self->{_cache}->{$id};
|
|
232 }
|
|
233
|
|
234 my $query = q{
|
|
235 SELECT analysis.analysis_id, logic_name,
|
|
236 program, program_version, program_file,
|
|
237 db, db_version, db_file,
|
|
238 module, module_version,
|
|
239 gff_source, gff_feature,
|
|
240 created, parameters, description, display_label, displayable, web_data
|
|
241 FROM analysis
|
|
242 LEFT JOIN analysis_description
|
|
243 ON analysis.analysis_id = analysis_description.analysis_id
|
|
244 WHERE analysis.analysis_id = ? };
|
|
245
|
|
246 my $sth = $self->prepare($query);
|
|
247 $sth->bind_param(1,$id,SQL_INTEGER);
|
|
248 $sth->execute();
|
|
249 my $rowHashRef = $sth->fetchrow_hashref;
|
|
250 if( ! defined $rowHashRef ) {
|
|
251 return undef;
|
|
252 }
|
|
253
|
|
254 my $anal = $self->_objFromHashref( $rowHashRef );
|
|
255 $self->{_cache}->{$anal->dbID} = $anal;
|
|
256 $self->{_logic_name_cache}->{lc($anal->logic_name())} = $anal;
|
|
257 return $anal;
|
|
258 }
|
|
259
|
|
260
|
|
261 =head2 fetch_by_logic_name
|
|
262
|
|
263 Arg [1] : string $logic_name the logic name of the analysis to retrieve
|
|
264 Example : my $analysis = $a_adaptor->fetch_by_logic_name('Eponine');
|
|
265 Description: Retrieves an analysis object from the database using its unique
|
|
266 logic name.
|
|
267 Returntype : Bio::EnsEMBL::Analysis
|
|
268 Exceptions : none
|
|
269 Caller : general
|
|
270 Status : Stable
|
|
271
|
|
272 =cut
|
|
273
|
|
274 sub fetch_by_logic_name {
|
|
275 my ( $self, $logic_name ) = @_;
|
|
276
|
|
277 my $analysis;
|
|
278 my $rowHash;
|
|
279
|
|
280 # Check the cache for the logic name
|
|
281 if ( defined( $self->{_logic_name_cache}{ lc($logic_name) } ) ) {
|
|
282 return $self->{_logic_name_cache}{ lc($logic_name) };
|
|
283 }
|
|
284
|
|
285 my $sth = $self->prepare(
|
|
286 qq(
|
|
287 SELECT analysis.analysis_id,
|
|
288 logic_name,
|
|
289 program,
|
|
290 program_version,
|
|
291 program_file,
|
|
292 db,
|
|
293 db_version,
|
|
294 db_file,
|
|
295 module,
|
|
296 module_version,
|
|
297 gff_source,
|
|
298 gff_feature,
|
|
299 created,
|
|
300 parameters,
|
|
301 description,
|
|
302 display_label,
|
|
303 displayable,
|
|
304 web_data
|
|
305 FROM analysis
|
|
306 LEFT JOIN analysis_description
|
|
307 ON ( analysis.analysis_id = analysis_description.analysis_id )
|
|
308 WHERE LOWER(logic_name) = ?)
|
|
309 );
|
|
310
|
|
311 $sth->bind_param( 1, lc($logic_name), SQL_VARCHAR );
|
|
312 $sth->execute();
|
|
313 my $rowHashRef = $sth->fetchrow_hashref();
|
|
314
|
|
315 if ( !defined($rowHashRef) ) { return undef }
|
|
316
|
|
317 $analysis = $self->_objFromHashref($rowHashRef);
|
|
318
|
|
319 # place the analysis in the caches, cross referenced by dbID and
|
|
320 # logic_name
|
|
321 $self->{_cache}->{ $analysis->dbID() } = $analysis;
|
|
322 $self->{_logic_name_cache}->{ lc($logic_name) } = $analysis;
|
|
323
|
|
324 return $analysis;
|
|
325 } ## end sub fetch_by_logic_name
|
|
326
|
|
327
|
|
328 =head2 store
|
|
329
|
|
330 Arg [1] : Bio:EnsEMBL::Analysis $analysis
|
|
331 Example : $analysis_adaptor->store($analysis);
|
|
332 Description: Stores $analysis in db. If the analysis is already stored in
|
|
333 the database its dbID and adaptor are updated, but the analysis
|
|
334 is not stored a second time.
|
|
335 Sets created date if not already set. Sets dbID and adaptor
|
|
336 inside $analysis. Returns dbID.
|
|
337 Returntype : int - dbID of stored analysis
|
|
338 Exceptions : throw on incorrect argument
|
|
339 throw if analysis argument does not have a logic name
|
|
340 Caller : general
|
|
341 Status : Stable
|
|
342
|
|
343 =cut
|
|
344
|
|
345 sub store {
|
|
346 my $self = shift;
|
|
347 my $analysis = shift;
|
|
348
|
|
349 if(!ref($analysis) || !$analysis->isa('Bio::EnsEMBL::Analysis')) {
|
|
350 throw("Bio::EnsEMBL::Analysis argument expected.");
|
|
351 }
|
|
352
|
|
353 if($analysis->is_stored($self->db())) {
|
|
354 return $analysis->dbID();
|
|
355 }
|
|
356
|
|
357 if(!$analysis->logic_name()) {
|
|
358 throw("Analysis cannot be stored without a valid logic_name");
|
|
359 }
|
|
360
|
|
361 my $insertion_method = (lc($self->dbc->driver) eq 'sqlite') ? 'INSERT OR IGNORE' : 'INSERT IGNORE';
|
|
362
|
|
363 my $rows_inserted = 0;
|
|
364 my $sth;
|
|
365
|
|
366 if ( $analysis->created() ) {
|
|
367
|
|
368 # We use insert IGNORE so that this method can be used in a
|
|
369 # multi-process environment. If another process has already written
|
|
370 # this record then there will not be a problem.
|
|
371
|
|
372 $sth = $self->prepare(
|
|
373 qq{
|
|
374 $insertion_method INTO analysis
|
|
375 (created, logic_name, db, db_version, db_file, program, program_version, program_file, parameters, module, module_version, gff_source, gff_feature)
|
|
376 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
377 }
|
|
378 );
|
|
379 $sth->bind_param( 1, $analysis->created(), SQL_DATETIME );
|
|
380 $sth->bind_param( 2, lc( $analysis->logic_name() ), SQL_VARCHAR );
|
|
381 $sth->bind_param( 3, $analysis->db(), SQL_VARCHAR );
|
|
382 $sth->bind_param( 4, $analysis->db_version(), SQL_VARCHAR );
|
|
383 $sth->bind_param( 5, $analysis->db_file(), SQL_VARCHAR );
|
|
384 $sth->bind_param( 6, $analysis->program(), SQL_VARCHAR );
|
|
385 $sth->bind_param( 7, $analysis->program_version(), SQL_VARCHAR );
|
|
386 $sth->bind_param( 8, $analysis->program_file(), SQL_VARCHAR );
|
|
387 $sth->bind_param( 9, $analysis->parameters(), SQL_VARCHAR );
|
|
388 $sth->bind_param( 10, $analysis->module(), SQL_VARCHAR );
|
|
389 $sth->bind_param( 11, $analysis->module_version(), SQL_VARCHAR );
|
|
390 $sth->bind_param( 12, $analysis->gff_source(), SQL_VARCHAR );
|
|
391 $sth->bind_param( 13, $analysis->gff_feature(), SQL_VARCHAR );
|
|
392
|
|
393 $rows_inserted = $sth->execute();
|
|
394
|
|
395 } else {
|
|
396 $sth = $self->prepare(
|
|
397 qq{
|
|
398 $insertion_method INTO analysis
|
|
399 (created, logic_name, db, db_version, db_file, program, program_version, program_file, parameters, module, module_version, gff_source, gff_feature)
|
|
400 VALUES (CURRENT_TIMESTAMP, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
401 }
|
|
402 );
|
|
403
|
|
404 $sth->bind_param( 1, $analysis->logic_name, SQL_VARCHAR );
|
|
405 $sth->bind_param( 2, $analysis->db, SQL_VARCHAR );
|
|
406 $sth->bind_param( 3, $analysis->db_version, SQL_VARCHAR );
|
|
407 $sth->bind_param( 4, $analysis->db_file, SQL_VARCHAR );
|
|
408 $sth->bind_param( 5, $analysis->program, SQL_VARCHAR );
|
|
409 $sth->bind_param( 6, $analysis->program_version, SQL_VARCHAR );
|
|
410 $sth->bind_param( 7, $analysis->program_file, SQL_VARCHAR );
|
|
411 $sth->bind_param( 8, $analysis->parameters, SQL_VARCHAR );
|
|
412 $sth->bind_param( 9, $analysis->module, SQL_VARCHAR );
|
|
413 $sth->bind_param( 10, $analysis->module_version, SQL_VARCHAR );
|
|
414 $sth->bind_param( 11, $analysis->gff_source, SQL_VARCHAR );
|
|
415 $sth->bind_param( 12, $analysis->gff_feature, SQL_VARCHAR );
|
|
416
|
|
417 $rows_inserted = $sth->execute();
|
|
418
|
|
419 } ## end else [ if ( $analysis->created...)]
|
|
420
|
|
421 my $dbID;
|
|
422 # If we need to fetch the timestamp, or the insert failed due to
|
|
423 # existance of an existing entry, we need to retrieve the entry from
|
|
424 # the database. Note: $sth->execute() may return 0E0 on error which
|
|
425 # is zero, but true which is why the $rows_inserted clause was added.
|
|
426 if ( !$analysis->created() || !$rows_inserted || $rows_inserted == 0 )
|
|
427 {
|
|
428 my $new_analysis =
|
|
429 $self->fetch_by_logic_name( $analysis->logic_name );
|
|
430
|
|
431 if ( !$new_analysis ) {
|
|
432 throw("Could not retrieve just stored analysis from database.\n"
|
|
433 . "Possibly incorrect db permissions or missing analysis table\n"
|
|
434 );
|
|
435 }
|
|
436
|
|
437 $dbID = $new_analysis->dbID();
|
|
438 $analysis->created( $new_analysis->created() );
|
|
439 }
|
|
440
|
|
441 $dbID ||= $sth->{'mysql_insertid'};
|
|
442 $sth->finish();
|
|
443
|
|
444 # store description and display_label
|
|
445 if( defined( $analysis->description() ) || defined( $analysis->display_label() )|| defined( $analysis->web_data() )) {
|
|
446 $sth = $self->prepare( "INSERT IGNORE INTO analysis_description (analysis_id, display_label, description, displayable, web_data) VALUES (?,?,?,?, ?)");
|
|
447
|
|
448 $sth->bind_param(1,$dbID,SQL_INTEGER);
|
|
449 $sth->bind_param(2,$analysis->display_label(),SQL_VARCHAR);
|
|
450 $sth->bind_param(3,$analysis->description,SQL_LONGVARCHAR);
|
|
451 $sth->bind_param(4,$analysis->displayable,SQL_TINYINT);
|
|
452 #$sth->bind_param(5,$analysis->web_data(),SQL_LONGVARCHAR);
|
|
453 my $web_data;
|
|
454 $web_data = $self->dump_data($analysis->web_data()) if ($analysis->web_data());
|
|
455 $sth->bind_param(5,$web_data,SQL_LONGVARCHAR);
|
|
456 $sth->execute();
|
|
457
|
|
458 $sth->finish();
|
|
459 }
|
|
460
|
|
461
|
|
462
|
|
463 $self->{_cache}->{$dbID} = $analysis;
|
|
464 $self->{_logic_name_cache}{lc($analysis->logic_name)} = $analysis;
|
|
465
|
|
466 $analysis->adaptor( $self );
|
|
467 $analysis->dbID( $dbID );
|
|
468
|
|
469 return $dbID;
|
|
470 }
|
|
471
|
|
472
|
|
473
|
|
474 =head2 update
|
|
475
|
|
476 Arg [1] : Bio::EnsEMBL::Analysis $anal
|
|
477 Example : $adaptor->update($anal)
|
|
478 Description: Updates this analysis in the database
|
|
479 Returntype : int 1 if update is performed, undef if it is not
|
|
480 Exceptions : throw if arg is not an analysis object
|
|
481 Caller : ?
|
|
482 Status : Stable
|
|
483
|
|
484 =cut
|
|
485
|
|
486 sub update {
|
|
487 my $self = shift;
|
|
488 my $a = shift;
|
|
489
|
|
490 if (!ref($a) || !$a->isa('Bio::EnsEMBL::Analysis')) {
|
|
491 throw("Expected Bio::EnsEMBL::Analysis argument.");
|
|
492 }
|
|
493
|
|
494 if(!$a->is_stored($self->db())) {
|
|
495 return undef;
|
|
496 }
|
|
497
|
|
498 my $sth = $self->prepare
|
|
499 ("UPDATE analysis " .
|
|
500 "SET created = ?, logic_name = ?, db = ?, db_version = ?, db_file = ?, ".
|
|
501 " program = ?, program_version = ?, program_file = ?, ".
|
|
502 " parameters = ?, module = ?, module_version = ?, ".
|
|
503 " gff_source = ?, gff_feature = ? " .
|
|
504 "WHERE analysis_id = ?");
|
|
505
|
|
506
|
|
507
|
|
508 $sth->bind_param(1,$a->created,SQL_DATETIME);
|
|
509 $sth->bind_param(2,$a->logic_name,SQL_VARCHAR);
|
|
510 $sth->bind_param(3,$a->db,SQL_VARCHAR);
|
|
511 $sth->bind_param(4,$a->db_version,SQL_VARCHAR);
|
|
512 $sth->bind_param(5,$a->db_file,SQL_VARCHAR);
|
|
513 $sth->bind_param(6,$a->program,SQL_VARCHAR);
|
|
514 $sth->bind_param(7,$a->program_version,SQL_VARCHAR);
|
|
515 $sth->bind_param(8,$a->program_file,SQL_VARCHAR);
|
|
516 $sth->bind_param(9,$a->parameters,SQL_VARCHAR);
|
|
517 $sth->bind_param(10,$a->module,SQL_VARCHAR);
|
|
518 $sth->bind_param(11,$a->module_version,SQL_VARCHAR);
|
|
519 $sth->bind_param(12,$a->gff_source,SQL_VARCHAR);
|
|
520 $sth->bind_param(13,$a->gff_feature,SQL_VARCHAR);
|
|
521 $sth->bind_param(14,$a->dbID,SQL_INTEGER);
|
|
522
|
|
523 $sth->execute();
|
|
524
|
|
525 $sth->finish();
|
|
526
|
|
527 # also update description & display label - may need to create these if
|
|
528 # not already there
|
|
529 $sth = $self->prepare("SELECT description FROM analysis_description WHERE analysis_id= ?");
|
|
530 $sth->execute($a->dbID);
|
|
531 my $web_data; #this is an anonymous reference to a hash, will have to be dumped into string before writing to db
|
|
532 if ($sth->fetchrow_hashref) { # update if exists
|
|
533 $web_data = $self->dump_data($a->web_data()) if ($a->web_data());
|
|
534 $sth = $self->prepare
|
|
535 ("UPDATE analysis_description SET description = ?, display_label = ?, displayable = ?, web_data = ? WHERE analysis_id = ?");
|
|
536 $sth->bind_param(1,$a->description,SQL_LONGVARCHAR);
|
|
537 $sth->bind_param(2,$a->display_label(),SQL_VARCHAR);
|
|
538 $sth->bind_param(3,$a->displayable,SQL_TINYINT);
|
|
539 # print "after $web_data\n";
|
|
540 $sth->bind_param(4,$web_data,SQL_LONGVARCHAR);
|
|
541 $sth->bind_param(5,$a->dbID,SQL_INTEGER);
|
|
542 $sth->execute();
|
|
543
|
|
544 } else { # create new entry
|
|
545
|
|
546 if( $a->description() || $a->display_label() || $a->web_data) {
|
|
547 $web_data = $self->dump_data($a->web_data()) if ($a->web_data());
|
|
548 #my $web_data = $self->dump_data($a->web_data());
|
|
549 $sth = $self->prepare( "INSERT IGNORE INTO analysis_description (analysis_id, display_label, description, displayable, web_data) VALUES (?,?,?,?,?)");
|
|
550 $sth->bind_param(1,$a->dbID,SQL_INTEGER);
|
|
551 $sth->bind_param(2,$a->display_label(),SQL_VARCHAR);
|
|
552 $sth->bind_param(3,$a->description,SQL_LONGVARCHAR);
|
|
553 $sth->bind_param(4,$a->displayable,SQL_TINYINT);
|
|
554 #my $web_data = $self->dump_data($a->web_data());
|
|
555 $sth->bind_param(5,$web_data,SQL_LONGVARCHAR);
|
|
556 $sth->execute();
|
|
557
|
|
558 }
|
|
559
|
|
560 }
|
|
561
|
|
562
|
|
563 $sth->finish();
|
|
564
|
|
565 # the logic_name cache needs to be re-updated now, since we may have just
|
|
566 # changed the logic_name
|
|
567 $self->fetch_all();
|
|
568
|
|
569 return 1;
|
|
570 }
|
|
571
|
|
572
|
|
573
|
|
574 =head2 remove
|
|
575
|
|
576 Arg [1] : Bio::EnsEMBL::Analysis $anal
|
|
577 Example : $adaptor->remove($anal)
|
|
578 Description: Removes this analysis from the database. This is not really
|
|
579 safe to execute in a multi process environment, so programs
|
|
580 should not remove analysis while out on the farm.
|
|
581 Returntype : none
|
|
582 Exceptions : thrown if $anal arg is not an analysis object
|
|
583 Caller : ?
|
|
584 Status : Stable
|
|
585
|
|
586 =cut
|
|
587
|
|
588 sub remove {
|
|
589 my ($self, $analysis) = @_;
|
|
590
|
|
591 if (!defined $analysis || !ref $analysis) {
|
|
592 throw("called remove on AnalysisAdaptor with a [$analysis]");
|
|
593 }
|
|
594
|
|
595 if(!$analysis->is_stored($self->db())) {
|
|
596 return undef;
|
|
597 }
|
|
598
|
|
599 my $sth = $self->prepare("DELETE FROM analysis WHERE analysis_id = ?");
|
|
600 $sth->bind_param(1,$analysis->dbID,SQL_INTEGER);
|
|
601 $sth->execute();
|
|
602
|
|
603 $sth = $self->prepare("DELETE FROM analysis_description WHERE analysis_id = ?");
|
|
604 $sth->execute($analysis->dbID());
|
|
605
|
|
606 # remove this analysis from the cache
|
|
607 delete $self->{'_cache'}->{$analysis->dbID()};
|
|
608 delete $self->{'_logic_name_cache'}->{lc($analysis->logic_name)};
|
|
609
|
|
610
|
|
611 # unset the adaptor and dbID
|
|
612 $analysis->dbID(undef);
|
|
613 $analysis->adaptor(undef);
|
|
614
|
|
615 return;
|
|
616 }
|
|
617
|
|
618
|
|
619
|
|
620 =head2 exists
|
|
621
|
|
622 Arg [1] : Bio::EnsEMBL::Analysis $anal
|
|
623 Example : if($adaptor->exists($anal)) #do something
|
|
624 Description: Tests whether this Analysis already exists in the database
|
|
625 by checking first if the adaptor and dbID are set and
|
|
626 secondly by whether it is in this adaptors internal cache.
|
|
627 Note that this will not actually check the database and will
|
|
628 not find and analysis which were recently added by other
|
|
629 processes. You are better off simply trying to store an
|
|
630 analysis which will reliably ensure that it is not stored twice
|
|
631 in the database.
|
|
632 Returntype : int dbID if analysis is found, otherwise returns undef
|
|
633 Exceptions : thrown if $anal arg is not an analysis object
|
|
634 Caller : store
|
|
635 Status : Stable
|
|
636
|
|
637 =cut
|
|
638
|
|
639 sub exists {
|
|
640 my ($self,$anal) = @_;
|
|
641
|
|
642 if(!ref($anal) || !$anal->isa("Bio::EnsEMBL::Analysis")) {
|
|
643 throw("Object is not a Bio::EnsEMBL::Analysis");
|
|
644 }
|
|
645
|
|
646 #if this analysis is stored in this db already return its dbID
|
|
647 if($anal->is_stored($self->db())) {
|
|
648 return $anal->dbID();
|
|
649 }
|
|
650
|
|
651 #this analysis object is not stored but one exactly like it may have been
|
|
652 foreach my $cacheId (keys %{$self->{_cache}}) {
|
|
653 if ($self->{_cache}->{$cacheId}->compare($anal) >= 0) {
|
|
654 # $anal->dbID( $cacheId );
|
|
655 # $anal->adaptor( $self );
|
|
656 return $cacheId;
|
|
657 }
|
|
658 }
|
|
659
|
|
660 #no analysis like this one exists in the database
|
|
661 return undef;
|
|
662 }
|
|
663
|
|
664
|
|
665 =head2 _objFromHashref
|
|
666
|
|
667 Arg [1] : hashref $rowHash
|
|
668 Description: Private helper function generates an Analysis object from a
|
|
669 mysql row hash reference.
|
|
670 Returntype : Bio::EnsEMBL::Analysis
|
|
671 Exceptions : none
|
|
672 Caller : Bio::EnsEMBL::DBSQL::AnalsisAdaptor::fetch_* methods
|
|
673 Status : Stable
|
|
674
|
|
675 =cut
|
|
676
|
|
677 sub _objFromHashref {
|
|
678 my $self = shift;
|
|
679 my $h = shift;
|
|
680
|
|
681 my $web_data = $h->{web_data} ? $self->get_dumped_data($h->{web_data}) : '';
|
|
682
|
|
683 return Bio::EnsEMBL::Analysis->new_fast({
|
|
684 dbID => $h->{analysis_id},
|
|
685 adaptor => $self,
|
|
686 _db => $h->{db},
|
|
687 _db_file => $h->{db_file},
|
|
688 _db_version => $h->{db_version},
|
|
689 _program => $h->{program},
|
|
690 _program_version => $h->{program_version},
|
|
691 _program_file => $h->{program_file},
|
|
692 _gff_source => $h->{gff_source},
|
|
693 _gff_feature => $h->{gff_feature},
|
|
694 _module => $h->{module},
|
|
695 _module_version => $h->{module_version},
|
|
696 _parameters => $h->{parameters},
|
|
697 _created => $h->{created},
|
|
698 _logic_name => $h->{logic_name},
|
|
699 _description => $h->{description},
|
|
700 _display_label => $h->{display_label},
|
|
701 _displayable => $h->{displayable},
|
|
702 _web_data => $web_data,
|
|
703 });
|
|
704 }
|
|
705
|
|
706
|
|
707
|
|
708 1;
|