annotate hapmap2mlmm/HapmapToMLMMFiles.pl @ 4:10627af23f10 draft

planemo upload
author gandres
date Tue, 15 Dec 2015 05:18:02 -0500
parents 420b57c3c185
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
2
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
3 use strict;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
4 use Switch;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
5 use Getopt::Long;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
6
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
7 my $usage = qq~Usage:$0 <args> [<opts>]
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
8 where <args> are:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
9 -h, --hapmap <Hapmap input file>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
10 -m, --map <Map output file>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
11 -g, --geno <Genotype output file>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
12 -p, --path <Path for transpose executable>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
13 ~;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
14 $usage .= "\n";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
15
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
16 my ($hapmap,$map,$geno,$path);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
17
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
18
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
19 GetOptions(
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
20 "geno=s" => \$geno,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
21 "map=s" => \$map,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
22 "hapmap=s" => \$hapmap,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
23 "path=s" => \$path,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
24 );
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
25
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
26
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
27 die $usage
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
28 if ( !$geno || !$map || !$hapmap || !$path);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
29
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
30 my $TRANSPOSE_EXE = "$path/transpose.awk";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
31
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
32 my @snps;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
33 my %chrom_pos;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
34 my $num_line = 0;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
35 open(my $O,">geno_transposed");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
36 open(my $H,$hapmap);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
37 while(<$H>)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
38 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
39 $num_line++;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
40 my $line = $_;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
41 chomp($line);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
42 $line =~s/\r//g;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
43 $line =~s/\n//g;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
44 my @infos = split(/\t/,$line);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
45 if ($num_line == 1)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
46 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
47 print $O "Ind_id";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
48 for (my $i = 11; $i <= $#infos; $i++)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
49 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
50 my $individual = $infos[$i];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
51 print $O " " . $individual;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
52 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
53 print $O "\n";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
54 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
55 elsif ($num_line > 1)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
56 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
57 my $snp = $infos[0];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
58 my $variation = $infos[1];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
59 my %scores;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
60 if ($variation =~/(\w)\/(\w)/)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
61 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
62 my $allele1 = $1;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
63 my $allele2 = $2;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
64 $scores{$allele1} = 0;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
65 $scores{$allele2} = 1;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
66 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
67 my $chrom = $infos[2];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
68 my $pos = $infos[3];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
69 $chrom_pos{$snp}{"chrom"} = $chrom;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
70 $chrom_pos{$snp}{"pos"} = $pos;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
71 push(@snps,$snp);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
72 print $O "$snp";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
73 for (my $i = 11; $i <= $#infos; $i++)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
74 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
75 my $genotype = $infos[$i];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
76 my @alleles = split("",$genotype);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
77 if ($genotype ne "NN")
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
78 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
79 my $score = $scores{$alleles[0]} + $scores{$alleles[1]};
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
80 print $O " $score";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
81 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
82 else
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
83 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
84 print $O " NA";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
85 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
86 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
87 print $O "\n";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
88 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
89 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
90 close($H);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
91 close($O);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
92
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
93 open(my $M,">$map");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
94 print $M "SNP Chr Pos\n";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
95 foreach my $snp(@snps)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
96 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
97 print $M "$snp " . $chrom_pos{$snp}{"chrom"} . " ". $chrom_pos{$snp}{"pos"} . "\n";
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
98 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
99 close($M);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
100
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
101 system("$TRANSPOSE_EXE geno_transposed >geno_transposed2");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
102
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
103 open(my $F,">$geno");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
104 open(my $G,"geno_transposed2");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
105 while(<$G>)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
106 {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
107 my $line = $_;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
108 $line =~s/ /\t/g;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
109 print $F $line;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
110 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
111 close($G);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
112 close($F);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
113
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
114 unlink("geno_transposed");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
115 unlink("geno_transposed2");
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
116
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
117