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