ensembl-hive  2.8.1
AccumulatorAdaptor.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  $dba->get_AccumulatorAdaptor->store( \@rows );
10 
11 =head1 DESCRIPTION
12 
13  This is currently an "objectless" adaptor for building accumulated structures.
14 
15 =head1 LICENSE
16 
17  See the NOTICE file distributed with this work for additional information
18  regarding copyright ownership.
19 
20  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
21  You may obtain a copy of the License at
22 
23  http://www.apache.org/licenses/LICENSE-2.0
24 
25  Unless required by applicable law or agreed to in writing, software distributed under the License
26  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  See the License for the specific language governing permissions and limitations under the License.
28 
29 =head1 CONTACT
30 
31  Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
32 
33 =cut
34 
35 
36 package Bio::EnsEMBL::Hive::DBSQL::AccumulatorAdaptor;
37 
38 use strict;
39 use warnings;
40 
41 use Bio::EnsEMBL::Hive::Utils ('destringify');
42 
43 use base ('Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor');
44 
45 
46 sub default_table_name {
47  return 'accu';
48 }
49 
50 
51 sub fetch_structures_for_job_ids {
52  my ($self, $job_ids_csv, $id_scale, $id_offset) = @_;
53  $id_scale ||= 1;
54  $id_offset ||= 0;
55 
56  my %structures = ();
57 
58  if( $job_ids_csv ) {
59 
60  my $sql = "SELECT s.dependent_job_id, a.struct_name, a.key_signature, a.value FROM accu a JOIN semaphore s ON (s.semaphore_id=a.receiving_semaphore_id) WHERE s.dependent_job_id in ($job_ids_csv)";
61  my $sth = $self->prepare( $sql );
62  $sth->execute();
63 
64  ROW: while(my ($receiving_job_id, $struct_name, $key_signature, $stringified_value) = $sth->fetchrow_array() ) {
65 
66  my $value = destringify($stringified_value);
67 
68  my $sptr = \$structures{$receiving_job_id * $id_scale + $id_offset}{$struct_name};
69 
70  while( $key_signature=~/(?:(?:\[(\d*)\])|(?:\{(.*?)\}))/g) {
71  my ($array_index, $hash_key) = ($1, $2);
72  if(defined($array_index)) {
73  unless(length($array_index)) {
74  $array_index = scalar(@{$$sptr||[]});
75  }
76  $sptr = \$$sptr->[$array_index];
77  } elsif(defined($hash_key)) {
78  if(length($hash_key)) {
79  $sptr = \$$sptr->{$hash_key};
80  } else {
81  $sptr = \$$sptr->{$value};
82  $$sptr++;
83  next ROW;
84  }
85  }
86  }
87  $$sptr = $value;
88  }
89  $sth->finish;
90  }
91 
92  return \%structures;
93 }
94 
95 1;
Bio::EnsEMBL::Hive::Utils
Definition: Collection.pm:4
Bio::EnsEMBL::Hive::DBSQL::AccumulatorAdaptor
Definition: AccumulatorAdaptor.pm:17
Bio::EnsEMBL::Hive::DBSQL::BaseAdaptor::store
public store()