1
package Bio::DB::SeqFeature::Store::LoadHelper;
7
Bio::DB::SeqFeature::Store::LoadHelper -- Internal utility for Bio::DB::SeqFeature::Store
11
# For internal use only.
20
L<Bio::DB::SeqFeature::Store>,
21
L<Bio::DB::SeqFeature::Segment>,
22
L<Bio::DB::SeqFeature::NormalizedFeature>,
23
L<Bio::DB::SeqFeature::GFF2Loader>,
24
L<Bio::DB::SeqFeature::Store::DBI::mysql>,
25
L<Bio::DB::SeqFeature::Store::berkeleydb>
29
Lincoln Stein E<lt>lstein@cshl.orgE<gt>.
31
Copyright (c) 2006 Cold Spring Harbor Laboratory.
33
This library is free software; you can redistribute it and/or modify
34
it under the same terms as Perl itself.
40
use File::Temp 'tempdir';
42
use Fcntl qw(O_CREAT O_RDWR);
48
my @tmpargs = $tmpdir ? (DIR=>$tmpdir) : ();
49
my $tmppath = tempdir(@tmpargs,CLEANUP=>1);
50
my $self = $class->create_dbs($tmppath);
51
return bless $self,$class;
59
my $hash_options = DB_File::HASHINFO->new();
61
# Each of these hashes allow only unique keys
62
for my $dbname qw(IndexIt TopLevel Local2Global) {
64
tie(%h,'DB_File',File::Spec->catfile($tmp,$dbname),
65
O_CREAT|O_RDWR,0666,$hash_options);
69
# The Parent2Child hash allows duplicate keys, so we
70
# create it with the R_DUP flag.
71
my $btree_options = DB_File::BTREEINFO->new();
72
$btree_options->{flags} = R_DUP;
74
tie(%h,'DB_File',File::Spec->catfile($tmp,'Parent2Child'),
75
O_CREAT|O_RDWR,0666,$btree_options);
76
$self{Parent2Child} = \%h;
84
$self->{IndexIt}{$id} = shift if @_;
85
return $self->{IndexIt}{$id};
91
$self->{TopLevel}{$id} = shift if @_;
92
return $self->{TopLevel}{$id};
97
my ($id) = each %{$self->{TopLevel}};
104
$self->{Local2Global}{$id} = shift if @_;
105
return $self->{Local2Global}{$id};
110
my $parent_id = shift;
112
$self->{Parent2Child}{$parent_id} = shift while @_;
117
my $parent_id = shift;
121
my $db = tied(%{$self->{Parent2Child}});
122
my $key = $parent_id;
124
for (my $status = $db->seq($key,$value,R_CURSOR);
125
$status == 0 && $key eq $parent_id;
126
$status = $db->seq($key,$value,R_NEXT)
128
push @children,$value;
130
return wantarray ? @children: \@children;
133
# this acts like each() and returns each parent id and an array ref of children
137
my $db = tied(%{$self->{Parent2Child}});
139
if ($self->{_cursordone}) {
140
undef $self->{_cursordone};
141
undef $self->{_parent};
142
undef $self->{_child};
146
# do a slightly tricky cursor search
147
unless (defined $self->{_parent}) {
148
return unless $db->seq($self->{_parent},$self->{_child},R_FIRST) == 0;
151
my $parent = $self->{_parent};
152
my @children = $self->{_child};
155
while (($status = $db->seq($self->{_parent},$self->{_child},R_NEXT)) == 0
156
&& $self->{_parent} eq $parent
158
push @children,$self->{_child};
161
$self->{_cursordone}++ if $status != 0;
163
return ($parent,\@children);