-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_v_cov2.pl
More file actions
executable file
·70 lines (58 loc) · 1.49 KB
/
shared_v_cov2.pl
File metadata and controls
executable file
·70 lines (58 loc) · 1.49 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl -w
#
# shared_v_cov2.pl
#
# A new script to look at sharing versus coverage levels
# across any number of populations
#
# July 30, 2014
# Liz Cooper
use strict;
# Get the input and output file names from the command line
my ($USAGE) = "\n$0 <input.counts> <output.shared>
\tinput.counts = A text file of shared snp types created by SNP_categories.pl
\toutput.shared = A output file with a line for every coverage value, and the proportion of shared sites at that cov\n\n";
unless (@ARGV) {
print $USAGE;
exit;
}
my ($input, $output) = @ARGV;
open (IN, $input) || die "\nUnable to open the file $input!\n";
my %shared = ();
my %total = ();
while (<IN>) {
chomp $_;
my @info = split(/\s{1,}/, $_);
my $cat = $info[0];
my @covs = @info[1..(scalar @info -1)];
my $sum = 0;
foreach my $c (@covs) {
$sum += $c;
}
my $mean = int($sum/(scalar @covs));
if (exists $total{$mean}) {
$total{$mean} += 1;
} else {
$total{$mean} = 1;
}
if ($cat == 15) {
if (exists $shared{$mean}) {
$shared{$mean} += 1;
} else {
$shared{$mean} = 1;
}
}
}
close(IN);
open (OUT, ">$output") || die "\nUnable to open the file $output!\n";
my @cov_means = sort {$a <= $b} keys %total;
foreach my $coverage (@cov_means) {
if (exists $shared{$coverage}) {
my $prop = $shared{$coverage}/$total{$coverage};
print OUT $coverage, "\t", $prop, "\t", $total{$coverage}, "\n";
} else {
print OUT $coverage, "\t", "0", "\t", "0\n";
}
}
close(OUT);
exit;