annotate tools/human_genome_variation/mergeSnps.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
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 #this merges the significance output with the SNPs so users get more than an index
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 my($out, $snp) = @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 if (!$out or !$snp) { die "missing args\n"; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 #merge SNP data with results
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 merge();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 exit;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 ########################################
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 #merge the input and output files so have SNP data with result
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 sub merge {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 open(FH, $out) or die "Couldn't open $out, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 my %res;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 my @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 while (<FH>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 chomp;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 my $line = $_;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 #0: 10 score= 14.224153 , df= 2 , p= 0.040760 , N=50
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 if ($line =~ /^(\d+):\s+(.*)/) { $res{$1} = $2; push(@ind, $1); }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 close FH;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 if (!@ind) { return; } #no results, leave alone
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 @ind = sort { $a <=> $b } @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 #read input file to get SNP data
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 open(FH, $snp) or die "Couldn't open $snp, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 my $i = 0; #0 based, not counting ID line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 my $c = shift @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 while (<FH>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 chomp;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 if (/^ID/) { next; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 my @f = split(/\s+/);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 if ($i == $c) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 $res{$i} = "$f[0]\t$f[1]\t$f[2]\t$res{$i}";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 if (!@ind) { last; }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 $c = shift @ind;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 $i++;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 close FH;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 #now reprint results with SNP data included
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 open(FH, ">", $out) or die "Couldn't write to $out, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 print FH "ID\tchr\tposition\tresults\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 foreach $i (keys %res) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 print FH $res{$i}, "\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 close FH;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57