Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create an index of every 10000th line to the byte offset.
- tie %$idx,'MLDBM', $foo.".lidx", O_CREAT|O_RDWR, 0666 or die "$! $foo.lidx";
- my $sam = Bio::DB::Sam->new(-bam => $foo);
- my $bam = $sam->bam;
- my $iterator = $sam->features(-iterator=>1);
- my $cnt = 0;
- while(my $seq = $iterator->next_seq()) {
- if( $cnt % 10000 == 0 ) {
- print STDERR "$cnt:". $bam->tell."n";
- $idx->{$cnt} = $bam->tell;
- }
- $cnt++;
- }
- ### ...later on
- # Open the bam file again
- my $sam = Bio::DB::Sam->new(-bam => $foo);
- my $bam = $sam->bam;
- print $bam->tell."\n";
- $bam->seek($idx->{$pos,0);
- #Should have seeked to the new pos.
- print STDERR $bam->tell ." $idx->{$ARGV[1]}n";
- # Print out the 1000th line in the 'sam' file.
- my $iterator = $sam->features(-iterator=>1);
- my $seq = $iterator->next_seq();
- print $seq->qname."n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement