#! /usr/bin/perl -w
use strict;

open OUT,">$ARGV[0].haQTL.All.hg38.manhattan.txt" or die $!;
print OUT "SNP\tchr\tpos\tp_val\n";
for(my $i=1;;$i++){
	last if $i>22;
	open IN,"gzip -dc $ARGV[0]/chr$i.H3K27ac.cisQTL.Pval1e+00.top*var.txt.gz|" or die $!;   # the permutation output from FastQTL

while(<IN>){
	chomp;
	my @sp=split /\s+/;
	my @pos=split /_/,$sp[5];
	$pos[0]=~ s/chr//;
	print "$ARGV[0]\t$_" if /NA/;
	next if /NA/;
        print OUT "$sp[5]\t$pos[0]\t$pos[1]\t$sp[-1]\n";
}
close IN;

}





