#!/opt/local/bin/perl use Bio::Seq; use Bio::DB::Sam; use PDL; use PDL::Char; $PDL::SHARE = $PDL::SHARE; # Load bam file my $bamfile = Bio::DB::Sam->new( -bam => "eg1.bam" ); my @allReads = $bamfile->features( -type => 'match' ); for my $read (@allReads) { # Get read and target sequences ( $ref, $matches, $query ) = $read->padded_alignment; my $target = PDL::Char->new("$ref"); for my $str ("$query") { my $match = PDL::Char->new($str); my @diff = which( $match != $target )->list; # Print read name and mismatching positions print $read->qname,': ', "@diff\n"; } }