[Bio] / FigKernelScripts / reindex_sim_btrees.pl Repository:
ViewVC logotype

View of /FigKernelScripts/reindex_sim_btrees.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Jun 6 20:51:28 2012 UTC (7 years, 6 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
new script to update btree indexes of sims files in a genome dir

#
# Index the sims and expanded sims files in SEED genome dir.
#
# Usage: reindex_sim_btrees dirname [dirname ...]
#
#

use strict;
use FIG;
use DB_File;

@ARGV >= 1 or die "Usage: reindex_sim_btrees dirname [dirname ...]\n";


for my $dir (@ARGV)
{
    for my $file (qw(similarities similarities.flips expanded_similarities expanded_similarities.flips))
    {
	my $path = "$dir/$file";

	if (! -f $path)
	{
	    warn "$path does not exist\n";
	    next;
	}

	my $index_file = "$path.index";

	index_sims($path, $index_file);
    }
}

exit(0);


#
# Use the C index_sims_file app to create a berkeley db index
# of the sims file.
#

sub index_sims
{
    my($sims, $index_file) = @_;

    my $path = &FIG::find_fig_executable("index_sims_file");

    open(IDX, "$path 0 < $sims |") or die "Cannot open index_sims_file pipe: $!\n";

    my %index;
    my $tied = tie %index, 'DB_File', $index_file, O_RDWR | O_CREAT, 0666, $DB_BTREE;

    $tied or &fatal("Creation of hash $index_file failed: $!\n");

    while (<IDX>)
    {
	chomp;
	my($peg, undef, $seek, $len) = split(/\t/);
	
	$index{$peg} = "$seek,$len";
    }
    close(IDX);
    
    $tied->sync();
    untie %index;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3