Bio::DB::SeqFeature::Store LoadHelper
SummaryPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::DB::SeqFeature::Store::LoadHelper -- Internal utility for Bio::DB::SeqFeature::Store
Package variables
No package variables defined.
Included modules
DB_File
Fcntl qw ( O_CREAT O_RDWR )
File::Path ' rmtree '
File::Spec
File::Temp ' tempdir '
Synopsis
  # For internal use only.
Description
For internal use only
Methods
new
No description
Code
DESTROY
No description
Code
create_dbs
No description
Code
indexit
No description
Code
toplevel
No description
Code
each_toplevel
No description
Code
local2global
No description
Code
add_children
No description
Code
children
No description
Code
each_family
No description
Code
local_ids
No description
Code
loaded_ids
No description
Code
Methods description
None available.
Methods code
newdescriptionprevnextTop
sub new {
    my $class   = shift;
    my $tmpdir  = shift;

    my $template = 'SeqFeatureLoadHelper_XXXXXX';

    my @tmpargs = $tmpdir ? ($template,DIR=>$tmpdir) : ($template);
    my $tmppath = tempdir(@tmpargs,CLEANUP=>1);
    my $self    = $class->create_dbs($tmppath);
    $self->{tmppath} = $tmppath;
    return bless $self,$class;
}
DESTROYdescriptionprevnextTop
sub DESTROY {
    my $self = shift;
    rmtree $self->{tmppath};
#    File::Temp::cleanup() unless $self->{keep};
}
create_dbsdescriptionprevnextTop
sub create_dbs {
    my $self = shift;
    my $tmp  = shift;
    my %self;

    my $hash_options           = DB_File::HASHINFO->new();

    # Each of these hashes allow only unique keys
for my $dbname (qw(IndexIt TopLevel Local2Global)) { my %h; tie(%h,'DB_File',File::Spec->catfile($tmp,$dbname), O_CREAT|O_RDWR,0666,$hash_options); $self{$dbname} =\% h; } # The Parent2Child hash allows duplicate keys, so we
# create it with the R_DUP flag.
my $btree_options = DB_File::BTREEINFO->new(); $btree_options->{flags} = R_DUP; my %h; tie(%h,'DB_File',File::Spec->catfile($tmp,'Parent2Child'), O_CREAT|O_RDWR,0666,$btree_options); $self{Parent2Child} =\% h; return\% self;
}
indexitdescriptionprevnextTop
sub indexit {
    my $self = shift;
    my $id   = shift;
    $self->{IndexIt}{$id} = shift if @_;
    return $self->{IndexIt}{$id};
}
topleveldescriptionprevnextTop
sub toplevel {
    my $self = shift;
    my $id   = shift;
    $self->{TopLevel}{$id} = shift if @_;
    return $self->{TopLevel}{$id};
}
each_topleveldescriptionprevnextTop
sub each_toplevel {
    my $self = shift;
    my ($id) = each %{$self->{TopLevel}};
    $id;
}
local2globaldescriptionprevnextTop
sub local2global {
    my $self = shift;
    my $id   = shift;
    $self->{Local2Global}{$id} = shift if @_;
    return $self->{Local2Global}{$id};
}
add_childrendescriptionprevnextTop
sub add_children {
    my $self      = shift;
    my $parent_id = shift;
    # (@children) = @_;
$self->{Parent2Child}{$parent_id} = shift while @_;
}
childrendescriptionprevnextTop
sub children {
    my $self = shift;
    my $parent_id = shift;

    my @children;

    my $db        = tied(%{$self->{Parent2Child}});
    my $key       = $parent_id;
    my $value     = '';
    for (my $status = $db->seq($key,$value,R_CURSOR);
	 $status    == 0 && $key eq $parent_id;
	 $status    = $db->seq($key,$value,R_NEXT)
	) {
	push @children,$value;
    }
    return wantarray ? @children:\@ children;
}

# this acts like each() and returns each parent id and an array ref of children
}
each_familydescriptionprevnextTop
sub each_family {
    my $self = shift;

    my $db        = tied(%{$self->{Parent2Child}});

    if ($self->{_cursordone}) {
	undef $self->{_cursordone};
	undef $self->{_parent};
	undef $self->{_child};
	return;
    }

    # do a slightly tricky cursor search
unless (defined $self->{_parent}) { return unless $db->seq($self->{_parent},$self->{_child},R_FIRST) == 0; } my $parent = $self->{_parent}; my @children = $self->{_child}; my $status; while (($status = $db->seq($self->{_parent},$self->{_child},R_NEXT)) == 0 && $self->{_parent} eq $parent ) { push @children,$self->{_child}; } $self->{_cursordone}++ if $status != 0; return ($parent,\@children);
}
local_idsdescriptionprevnextTop
sub local_ids {
    my $self = shift;
    my @ids  = keys %{$self->{Local2Global}}
                   if $self->{Local2Global};
    return\@ ids;
}
loaded_idsdescriptionprevnextTop
sub loaded_ids {
    my $self = shift;
    my @ids  = values %{$self->{Local2Global}}
                     if $self->{Local2Global};
    return\@ ids;
}

1;
}
General documentation
SEE ALSOTop
bioperl,
Bio::DB::SeqFeature::Store,
Bio::DB::SeqFeature::Segment,
Bio::DB::SeqFeature::NormalizedFeature,
Bio::DB::SeqFeature::GFF2Loader,
Bio::DB::SeqFeature::Store::DBI::mysql,
Bio::DB::SeqFeature::Store::berkeleydb
AUTHORTop
Lincoln Stein <lstein@cshl.org>.
Copyright (c) 2006 Cold Spring Harbor Laboratory.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.