-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSNPtable2countdata.pl
48 lines (44 loc) · 1.09 KB
/
SNPtable2countdata.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
#!/bin/perl
use warnings;
use strict;
#This script takes a list of sites (in the initial case it was high Fst sites for ben-lim stickleback), and it asks how many of those sites does each sample have data for.
my $sites = $ARGV[0]; #List of sites in two columns (chrom\tpos)
#Snp table is piped in
open SITES, $sites;
my %sites_hash;
while (<SITES>){
chomp;
my @a = split(/\t/,$_);
$sites_hash{$a[0]}{$a[1]}++;
}
close SITES;
my %samplelist;
my $number_ind;
my %data_counter;
while(<STDIN>){
chomp;
my @a = split(/\t/,$_);
if ($. == 1){
foreach my $i (2..$#a){
$samplelist{$i} = $a[$i];
}
$number_ind = $#a;
}else{
my $chrom = $a[0];
my $pos = $a[1];
if ($sites_hash{$chrom}{$pos}){
foreach my $i (2..$#a){
if ($a[$i] ne "NN"){
$data_counter{$i}++;
}
}
}
}
}
print "Sample\tNumber_sites";
foreach my $i (2..$number_ind){
unless ($data_counter{$i}){
$data_counter{$i} = 0;
}
print "\n$samplelist{$i}\t$data_counter{$i}";
}