Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/perl
- package Bio::Assembly::AceTools;
- use strict;
- use warnings;
- use FileHandle;
- use Fcntl; # For O_RDWR, O_CREAT, etc.
- use DB_File;
- use vars qw(%index_hash);
- my $data_directory ="/home/vsk23/cxgn/data/ace_files/index/testerace.txt";
- my $index_directory="/home/vsk23/cxgn/data/ace_files/hashtables/";
- my $db_file_name = "testeracehash.db";
- my $data_handle = FileHandle -> new;
- my $index_handle = FileHandle -> new;
- build_ace_hash_file($data_handle, $index_handle,$index_directory,$db_file_name);
- my $byte_loc = get_location_by_id("".$index_directory."".$db_file_name."", "idnumone");
- print "Location of idnumone is: $byte_loc \n";
- sub build_ace_hash_file{
- my $data_handle = shift;
- my $index_handle = shift;
- my $index_path = shift || die "Need to provide index file path!";
- my $db_file_name= shift;
- my $contig_id="";
- my $unigene_id="";
- my $offset = 0;
- $data_handle-> open("< /home/vsk23/cxgn/data/ace_files/index/testerace.txt") or die "Can't open data handle: $!\n";
- $index_handle ->open("+> /home/vsk23/cxgn/data/ace_files/hashtables/testeracehash.db") or die "Can't open this file for read/write: $!\n";
- tie(%index_hash, 'DB_File',"/home/vsk23/cxgn/data/ace_files/hashtables/testeracehash.db", O_RDWR|O_CREAT, 0666)
- or die "Couldn't tie DB file 'filename': $!; aborting";
- while ( <$data_handle>) {
- if ($_ =~ m/^CO\s+(\S+)\s+/){
- $contig_id = $1;
- $offset = tell($data_handle);
- $index_hash{'$contig_id'}=$offset;
- print "Key value:::::: ". $index_hash{'$contig_id'}."\n";
- }
- }
- untie (%index_hash);
- }
- sub get_location_by_id{
- my $db_file = shift;
- my $id = shift;
- tie (%index_hash,'DB_File',"/home/vsk23/cxgn/data/ace_files/hashtables/testeracehash.db", O_RDWR,0666) or die "Can't open $db_file: $!\n";
- print " Hash is : ". scalar (%index_hash)."\n";
- if(exists $index_hash{$id}){
- return $index_hash{$id};
- }
- untie (%index_hash);
- }
- #
- #sub get_line_by_location{
- # my $self = shift;
- # my $data_handle=shift;
- # my $byte_location = shift;
- #
- # seek($data_handle, $byte_location,0);
- # return scalar(<$data_handle>);#
- #
- #}
Add Comment
Please, Sign In to add comment