Advertisement
Guest User

Untitled

a guest
May 9th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.84 KB | None | 0 0
  1. # Create an index of every 10000th line to the byte offset.
  2. tie %$idx,'MLDBM', $foo.".lidx", O_CREAT|O_RDWR, 0666 or die "$! $foo.lidx";
  3. my $sam = Bio::DB::Sam->new(-bam => $foo);
  4. my $bam = $sam->bam;
  5. my $iterator = $sam->features(-iterator=>1);
  6.  
  7. my $cnt = 0;
  8. while(my $seq = $iterator->next_seq()) {
  9.     if( $cnt % 10000 == 0 ) {
  10.         print STDERR "$cnt:". $bam->tell."n";
  11.         $idx->{$cnt} = $bam->tell;
  12.     }
  13.     $cnt++;
  14. }
  15.  
  16.  
  17. ### ...later on
  18. # Open the bam file again
  19. my $sam = Bio::DB::Sam->new(-bam => $foo);
  20.  
  21. my $bam = $sam->bam;
  22. print $bam->tell."\n";
  23. $bam->seek($idx->{$pos,0);
  24.  
  25. #Should have seeked to the new pos.
  26. print STDERR $bam->tell ." $idx->{$ARGV[1]}n";
  27.  
  28. # Print out the 1000th line in the 'sam' file.
  29. my $iterator = $sam->features(-iterator=>1);
  30. my $seq = $iterator->next_seq();
  31. print $seq->qname."n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement