View difference between Paste ID: C7tzWKS3 and SSj3AHTe
SHOW: | | - or go back to the newest paste.
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);
23+
$bam->seek($idx->{$pos},0);
24
25
#Should have seeked to the new pos.
26-
print STDERR $bam->tell ." $idx->{$ARGV[1]}n";
26+
print STDERR $bam->tell ." $idx->{$pos}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";