0
|
1 #!/usr/bin/perl
|
|
2
|
|
3 use strict;
|
|
4 use Getopt::Long;
|
|
5 use Bio::SeqIO;
|
|
6
|
|
7 my $PLINK_EXE= "plink";
|
|
8
|
|
9 my $usage = qq~Usage:$0 <args> [<opts>]
|
|
10 where <args> are:
|
|
11 -i, --in <input>
|
|
12 -o, --out <output>
|
|
13 ~;
|
|
14 $usage .= "\n";
|
|
15
|
|
16 my ($in,$out);
|
|
17
|
|
18
|
|
19 GetOptions(
|
|
20 "in=s" => \$in,
|
|
21 "out=s" => \$out
|
|
22 );
|
|
23
|
|
24 die $usage
|
|
25 if ( !$in || !$out);
|
|
26
|
|
27
|
|
28 my $plink_command = $PLINK_EXE . " --file $in --noweb --cluster --matrix --mds-plot 2 --out $out >>$in.plink.log 2>&1";
|
|
29 system($plink_command);
|
|
30
|
|
31 my $awk_cmd = "awk \{\'print \$1\'\} $in.ped";
|
|
32 my $inds = `$awk_cmd`;
|
|
33 my @individuals = split("\n",$inds);
|
|
34
|
|
35 my %populations;
|
|
36 if (-e "$in.individual_info.txt")
|
|
37 {
|
|
38 open(my $I,"$in.individual_info.txt");
|
|
39 while(<$I>)
|
|
40 {
|
|
41 my $line = $_;
|
|
42 $line =~s/\n//g;
|
|
43 $line =~s/\r//g;
|
|
44 my ($ind,$pop) = split(/;/,$line);
|
|
45 $populations{$ind} = $pop;
|
|
46 }
|
|
47 close($I);
|
|
48 }
|
|
49
|
|
50 open(my $OUT,">$out.mds_plot.txt");
|
|
51 my $go = 0;
|
|
52 open(my $O,"$out.mds");
|
|
53 while(<$O>)
|
|
54 {
|
|
55 if ($go)
|
|
56 {
|
|
57 my $line = $_;
|
|
58 $line =~s/\n//g;
|
|
59 $line =~s/\r//g;
|
|
60 my @i = split(/\s+/,$line);
|
|
61 if ($line =~/^ /)
|
|
62 {
|
|
63 my $ind = $i[1];
|
|
64 my $pop = "Pop1";
|
8
|
65 #if ($ind=~/^d/){$pop="Pop2";}
|
0
|
66 if ($populations{$ind})
|
|
67 {
|
|
68 $pop = $populations{$ind};
|
|
69 }
|
|
70 print $OUT "$pop $ind ".$i[4]." ".$i[5]."\n";
|
|
71 }
|
|
72 if ($line =~/^\w/)
|
|
73 {
|
|
74 my $ind = $i[0];
|
|
75 my $pop = "Pop1";
|
8
|
76 #if ($ind=~/^d/){$pop="Pop2";}
|
0
|
77 if ($populations{$ind})
|
|
78 {
|
|
79 $pop = $populations{$ind};
|
|
80 }
|
|
81 print $OUT "$pop $ind ".$i[3]." ".$i[4]."\n";
|
|
82 }
|
|
83
|
|
84 }
|
|
85 if (/C1/){$go = 1;}
|
|
86 }
|
|
87 close($O);
|
|
88 close($OUT);
|
|
89
|
|
90
|
|
91 my $j = 0;
|
|
92 open(my $IBS,">$out.ibs_matrix.txt");
|
|
93 print $IBS "Individuals " . join("\t",@individuals)."\n";
|
|
94 open(my $O2,"$out.mibs");
|
|
95 while(<$O2>)
|
|
96 {
|
|
97 my $line = $_;
|
|
98 $line =~s/\n//g;
|
|
99 $line =~s/\r//g;
|
|
100 my @i = split(/\s+/,$line);
|
|
101 print $IBS $individuals[$j]. " ". join("\t",@i)."\n";
|
|
102 $j++;
|
|
103 }
|
|
104 close($O2);
|
|
105 close($IBS);
|
|
106
|
|
107
|
|
108
|
|
109
|
|
110
|
|
111
|