Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.04 KB | None | 0 0
  1. #!/usr/bin/perl  -w
  2.  
  3. use strict;
  4.  
  5. use Benchmark::Timer;
  6.  
  7. use Bio::DB::Sam;
  8.  
  9.  
  10.  
  11. ## The BAM in question
  12. my $bam_file
  13.   = '../Results/bowtie_combined.sorted.bam';
  14.  
  15. ## Get in in BioPerl format
  16. my $sam = Bio::DB::Sam->
  17.   new( -bam  => $bam_file );
  18.  
  19. ## Check that it's alive
  20. print "there are ",
  21.   $sam->n_targets, " target sequences (contigs) in '$bam_file'\n";
  22.  
  23.  
  24.  
  25. ## Get a list of all the target sequences
  26. my @seqs = $sam->seq_ids;
  27.  
  28.  
  29.  
  30. ## Prove that we can count the number of reads using the longest
  31. ## target sequence...
  32.  
  33. my $seq = $seqs[0];
  34. my $len = $sam->length($seq);
  35.  
  36. print
  37.   join("\t", $seq, $len,
  38.        scalar( $sam->segment( $seq, 1, $len )->features() )
  39.       ), "\n";
  40.  
  41.  
  42.  
  43. ## Do some benchmarking of the top 1000 contigs (most of the big
  44. ## ones)...
  45.  
  46. my $timer = Benchmark::Timer->new(skip => 1);
  47.  
  48. for my $i (0..1000){
  49.   $seq = $seqs[$i];
  50.   $len = $sam->length($seq);
  51.  
  52.   $timer->start('count reads');
  53.   my @features = $sam->segment( $seq, 1, $len )->features();
  54.   $timer->stop;
  55. }
  56.  
  57. print $timer->report;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement