-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCov_dist.pl
executable file
·49 lines (41 loc) · 1004 Bytes
/
getCov_dist.pl
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
43
44
45
46
47
48
49
#!/usr/bin/perl -w
#
# getCov_dist.pl
#
# Get coverage distribution from a pileup/cov file
#
# July 22, 2016
# By: Liz Cooper
use strict;
my ($USAGE) = "\n$0 <input.cov> <output.txt>
\tinput.cov = A merged coverage/pileup file for all individuals
\toutput.txt = A counts file (histogram) for all coverage values, to assist in choosing the right cut-offs\n\n";
unless (@ARGV) {
print $USAGE;
exit;
}
my ($input, $output) = @ARGV;
open (IN, $input) || die "\nUnable to open the file $input!\n";
open (OUT, ">$output") || die "\nUnable to open the file $output!\n";
my %covs = ();
while (<IN>) {
chomp $_;
my @info = split(/\s{1,}/, $_);
for (my $i = 1; $i < scalar @info; $i++) {
my @vals = split(/,/, $info[$i]);
foreach my $v (@vals) {
if (exists $covs{$v}) {
$covs{$v} += 1;
} else {
$covs{$v} = 1;
}
}
}
}
close(IN);
my @cov_sort = sort {$a <=> $b} (keys %covs);
foreach my $c (@cov_sort) {
print OUT $c, "\t", $covs{$c}, "\n";
}
close(OUT);
exit;