annotate MDSplot/MDSbasedOnIBSmatrix.pl @ 12:88748d846a20 draft

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