-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregate_magma_results.pl
executable file
·69 lines (57 loc) · 1.85 KB
/
aggregate_magma_results.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env perl
use strict;
use warnings;
use IO::File;
my $fof = IO::File->new($ARGV[0]) || die "Error: Cannot open $ARGV[0]!\n";
my $genes = {};
while(my $file = $fof->getline) {
chomp($file);
my $gwas = $file;
$gwas =~ s/\.genes\.out$//;
$gwas =~ s/^iPSYCH2015\_EUR\_//;
$gwas =~ s/\_CC//;
print STDERR "Processing $file .."."\n";
my $fh = IO::File->new($file) || die "Error: Cannot open Magma assoc file: $file!\n";
while(my $line = $fh->getline) {
chomp($line);
if($line =~ /^GENE/) {
next;
}
else {
my @lineContents = split(/\s+/, $line);
my $gene = $lineContents[0];
my $p_value = $lineContents[8];
if(!exists $genes->{$gene}) {
$genes->{$gene}->{chr} = $lineContents[1];
$genes->{$gene}->{start} = $lineContents[2];
$genes->{$gene}->{stop} = $lineContents[3];
$genes->{$gene}->{min_p} = $p_value;
$genes->{$gene}->{pheno} = "-";
}
else {
if($p_value < $genes->{$gene}->{min_p}) {
$genes->{$gene}->{min_p} = $p_value;
}
}
if($p_value <= 2.5e-5) {
if($genes->{$gene}->{pheno} eq "-") {
$genes->{$gene}->{pheno} = $gwas;
}
else {
$genes->{$gene}->{pheno} .= ";".$gwas;
}
}
}
}
$fh->close;
}
$fof->close;
print "GENE\tCHR\tSTART\tSTOP\tP\tPHENOTYPE\n";
for my $index(keys %$genes) {
print $index."\t";
print $genes->{$index}->{chr}."\t";
print $genes->{$index}->{start}."\t";
print $genes->{$index}->{stop}."\t";
print $genes->{$index}->{min_p}."\t";
print $genes->{$index}->{pheno}."\n";
}