Skip to content

Instantly share code, notes, and snippets.

@piroyon
Last active May 18, 2022 04:13
Show Gist options
  • Save piroyon/895e0cc936d034e7d3d3d4021039fc22 to your computer and use it in GitHub Desktop.
Save piroyon/895e0cc936d034e7d3d3d4021039fc22 to your computer and use it in GitHub Desktop.
Calculate alignment length from CIGAR string (perl, subroutine)
sub cigarlen {
my $cigar = shift;
my @c = $cigar =~ /\d+[MI=X]/g;
my $len = 0;
foreach my $i (@c) {
$i =~ /(\d+)[MI=X]/;
$len += $1;
}
return $len;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment