annotate tools/human_genome_variation/gpass.pl @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env perl
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 use strict;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 use warnings;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 use File::Basename;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 use File::Temp qw/ tempfile /;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 $ENV{'PATH'} .= ':' . dirname($0);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 #this is a wrapper for gpass that converts a linkage pedigree file to input
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 #for this program
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 my($map, $ped, $out, $fdr) = @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 if (!$map or !$ped or !$out or !$fdr) { die "missing args\n"; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 my($fh, $name) = tempfile();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 #by default this file is removed when these variable go out of scope
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 print $fh "map=$map ped=$ped\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 close $fh; #converter will overwrite, just keep name
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 #run converter
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 system("lped_to_geno.pl $map $ped > $name") == 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 or die "system lped_to_geno.pl $map $ped > $name failed\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 #system("cp $name tmp.middle");
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 #run GPASS
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 system("gpass $name -o $out -fdr $fdr 1>/dev/null") == 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 or die "system gpass $name -o $out -fdr $fdr, failed\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 #merge SNP data with results
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 merge();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 exit;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 ########################################
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 #merge the input and output files so have SNP data with result
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 sub merge {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 open(FH, $out) or die "Couldn't open $out, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 my %res;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 my @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 while (<FH>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 chomp;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 my $line = $_;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 if ($line =~ /^(\d+)/) { $res{$1} = $line; push(@ind, $1); }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 else { $res{'index'} = $line; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 close FH;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 if (!@ind) { return; } #no results, leave alone
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 @ind = sort { $a <=> $b } @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 $res{'index'} =~ s/Index/#ID\tchr\tposition/;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 #read input file to get SNP data
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 open(FH, $name) or die "Couldn't open $name, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 my $i = 0; #index is 0 based not counting header line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 my $c = shift @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 while (<FH>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 chomp;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 if (/^ID/) { next; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 my @f = split(/\s+/);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62 if ($i == $c) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 $res{$i} =~ s/^$i/$f[0]\t$f[1]\t$f[2]/;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64 if (!@ind) { last; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 $c = shift @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 $i++;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 close FH;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70 #now reprint results with SNP data included
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 open(FH, ">", $out) or die "Couldn't write to $out, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72 print FH $res{'index'}, "\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 delete $res{'index'};
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 foreach $i (keys %res) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75 print FH $res{$i}, "\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 close FH;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79