-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparseSAMHappyPairs.pl
More file actions
executable file
·42 lines (35 loc) · 1.12 KB
/
Copy pathparseSAMHappyPairs.pl
File metadata and controls
executable file
·42 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl -w
use strict;
# Parses the bitwise flag field of the sam file and counts happy paired reads, i.e. mapped within expected insert size and correct orientation#
die "usage: parseSAMHappyPairs.pl <SAM file>\n" unless @ARGV == 1;
my $total_count;
my $happy_count;
my $unhappy_count;
open IN, "< $ARGV[0]";
while (<IN>) {
unless ($_ =~ /^@/) {
$total_count++;
my @line = split '\t', $_;
my $flag = $line[1];
# print "$flag\n";
if ($flag == 99 || $flag == 147 || $flag == 83 || $flag == 163) {
# print "Happy Pair\t";
# print "$_";
$happy_count++;
}
else {
# print "Unhappy Pair\t";
# print "$_";
$unhappy_count++;
}
}
}
my $happy_pair_count = $happy_count / 2;
my $unhappy_pair_count = $unhappy_count / 2;
my $total_pair_count = $total_count / 2;
my $happy_percentage = ($happy_pair_count / $total_pair_count) * 100;
close IN;
print "Total amount of Pairs: $total_pair_count\n";
print "Amount of Happy Pairs: $happy_pair_count\n";
print "Amount of Unhappy Pairs: $unhappy_pair_count\n";
print "% Happy Pairs: "; printf "%.1f\n", "$happy_percentage";