-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclusteredness.pl
More file actions
executable file
·67 lines (56 loc) · 1.28 KB
/
clusteredness.pl
File metadata and controls
executable file
·67 lines (56 loc) · 1.28 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
#!/usr/bin/perl
#
# Clusteredness.pl
#
# A script to estimate the average "clusteredness" of individuals
# from STRUCTURE output
#
# Written by Liz Cooper
use warnings;
use strict;
my($USAGE)= "$0 <Input_Filename>\n\tInput_Filename = The output file generated by STRUCTURE\n";
# Collect the name of the input file at the command line
unless (@ARGV) {
print $USAGE, "\n";
exit;
}
my($inputfile) = $ARGV[0];
open (INPUT, $inputfile) || die "Unable to open the file $inputfile!\n";
my $G = 0;
my $I = 0;
# Read in the STRUCTURE input file;
# Skip all lines until getting to the Q-matrix
# Then, calculate the avg. membership for each individual
my $flag = 0;
while (<INPUT>) {
chomp $_;
if ($_ =~ /^Inferred\sancestry/) {
$flag++;
} elsif ($_ =~ /^\s*$/) {
$flag=0;
next;
} elsif ($flag) {
if ($_ =~ /Label/) {
next;
} else {
my @line = split (/:/, $_);
$line[1] =~ s/^\s{1,}//;
my @q = split(/\s/, $line[1]);
my $sum = 0;
for (my $i = 0; $i < scalar @q; $i++) {
my $tmp = ($q[$i] - (1/(scalar @q)))**2;
$sum += $tmp;
}
my $mem = ((scalar @q)/((scalar @q) - 1)) * $sum;
$mem = $mem**(1/2);
$G += $mem;
$I++;
}
} else {
next;
}
}
close(INPUT);
$G = $G * (1/$I);
print $G, "\n";
exit;