-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSNPtable2treemix.pl
executable file
·91 lines (84 loc) · 1.58 KB
/
SNPtable2treemix.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/perl
use warnings;
use strict;
#unless (@ARGV == 3) {die;}
my $in = $ARGV[0];
my $out = $ARGV[1];
my $pop = $ARGV[2];
my %pop;
my %samples;
my @samples;
my %popList;
my $NumColBad=3;
if ($pop){
open POP, $pop;
while (<POP>){
unless ($. == 1){
chomp;
my @a = split (/\t/,$_);
$pop{$a[0]}=$a[1];
$popList{$a[1]}++;
}
}
close POP;
}
open OUT, ">$out";
my $count;
foreach my $pop (sort keys %popList){
$count++;
if ($count ==1) {
print OUT $pop;
}else {
print OUT "\t$pop";
}
}
print OUT "\n";
open IN, $in;
while (<IN>){
chomp;
my @a = split (/\t/,$_);
if ($. == 1 ){
foreach my $i ($NumColBad..$#a){
if ($pop{$a[$i]}){
$samples{$i}=$a[$i];
push(@samples,$a[$i]);
}
}
}else{
my %h;
my %alleles;
foreach my $i ($NumColBad..$#a){
if ($samples{$i}){
unless ($a[$i] eq "NN"){
my @tmp = split('',$a[$i]);
$h{$pop{$samples{$i}}}{$tmp[0]}++;
$h{$pop{$samples{$i}}}{$tmp[1]}++;
$alleles{$tmp[0]}++;
$alleles{$tmp[1]}++;
}
}
}
if (keys %alleles ne 2){
next;
}
foreach my $pop (sort keys %popList){
my $c;
foreach my $allele (sort keys %alleles){
$c++;
if ($c ==2){
print OUT ",";
}elsif ($c ==3){
print OUT "-WARNING_MORE_THAN_2_ALLELES-(this script is fail)\t";
}
if ($h{$pop}{$allele}){
print OUT "$h{$pop}{$allele}";
}else{
print OUT "0";
}
}
print OUT "\t";
}
print OUT "\n";
}
}
close IN;