Guest User

Untitled

a guest
May 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #! /usr/bin/perl
  2. package Bio::Assembly::AceTools;
  3. use strict;
  4. use warnings;
  5.  
  6. use FileHandle;
  7. use Fcntl; # For O_RDWR, O_CREAT, etc.
  8. use DB_File;
  9.  
  10. use vars qw(%index_hash);
  11.  
  12.  
  13. my $data_directory ="/home/vsk23/cxgn/data/ace_files/index/testerace.txt";
  14. my $index_directory="/home/vsk23/cxgn/data/ace_files/hashtables/";
  15. my $db_file_name = "testeracehash.db";
  16.  
  17.  
  18. my $data_handle = FileHandle -> new;
  19. my $index_handle = FileHandle -> new;
  20.  
  21. build_ace_hash_file($data_handle, $index_handle,$index_directory,$db_file_name);
  22.  
  23.  
  24. my $byte_loc = get_location_by_id("".$index_directory."".$db_file_name."", "idnumone");
  25.  
  26. print "Location of idnumone is: $byte_loc \n";
  27.  
  28. sub build_ace_hash_file{
  29.  
  30. my $data_handle = shift;
  31. my $index_handle = shift;
  32. my $index_path = shift || die "Need to provide index file path!";
  33. my $db_file_name= shift;
  34. my $contig_id="";
  35. my $unigene_id="";
  36. my $offset = 0;
  37.  
  38. $data_handle-> open("< /home/vsk23/cxgn/data/ace_files/index/testerace.txt") or die "Can't open data handle: $!\n";
  39. $index_handle ->open("+> /home/vsk23/cxgn/data/ace_files/hashtables/testeracehash.db") or die "Can't open this file for read/write: $!\n";
  40.  
  41. tie(%index_hash, 'DB_File',"/home/vsk23/cxgn/data/ace_files/hashtables/testeracehash.db", O_RDWR|O_CREAT, 0666)
  42. or die "Couldn't tie DB file 'filename': $!; aborting";
  43.  
  44. while ( <$data_handle>) {
  45. if ($_ =~ m/^CO\s+(\S+)\s+/){
  46. $contig_id = $1;
  47. $offset = tell($data_handle);
  48. $index_hash{'$contig_id'}=$offset;
  49. print "Key value:::::: ". $index_hash{'$contig_id'}."\n";
  50. }
  51. }
  52.  
  53. untie (%index_hash);
  54. }
  55.  
  56.  
  57. sub get_location_by_id{
  58. my $db_file = shift;
  59. my $id = shift;
  60.  
  61. 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";
  62.  
  63. print " Hash is : ". scalar (%index_hash)."\n";
  64.  
  65. if(exists $index_hash{$id}){
  66. return $index_hash{$id};
  67. }
  68.  
  69. untie (%index_hash);
  70. }
  71.  
  72.  
  73. #
  74. #sub get_line_by_location{
  75. # my $self = shift;
  76. # my $data_handle=shift;
  77. # my $byte_location = shift;
  78. #
  79. # seek($data_handle, $byte_location,0);
  80. # return scalar(<$data_handle>);#
  81. #
  82. #}
Add Comment
Please, Sign In to add comment