@@ -0,0 +1,1575 @@
+#!/usr/bin/env python2%0A%0Afrom __future__ import print_function, division, absolute_import%0A%0Aimport gzip%0Aimport glob%0Aimport heapq%0Aimport re%0Aimport os.path%0Aimport json%0A%0Adef parse_marker_id(marker_id):%0A    chr1, pos1, ref, alt, chr2, pos2 = re.match(r'(%5B%5E:%5D+):(%5B0-9%5D+)_(%5B-ATCG%5D+)/(%5B-ATCG%5D+)_(%5B%5E:%5D+):(%5B0-9%5D+)', marker_id).groups()%0A    assert chr1 == chr2%0A    assert pos1 == pos2%0A    return chr1, int(pos1), ref, alt%0A%0Afiles_to_convert = glob.glob('/var/pheweb_data/gwas-single-pheno/*.vcf.gz')%0Afor filename in files_to_convert:%0A    basename = os.path.basename(filename)%0A    dest_filename = '/var/pheweb_data/gwas-json/%7B%7D.json'.format(basename.rstrip('.vcf.gz'))%0A    if os.path.exists(dest_filename):%0A        continue%0A    print('%7B%7D -%3E %7B%7D'.format(filename, dest_filename))%0A%0A    with gzip.open(filename) as f:%0A        variants = (line.rstrip('%5Cn').split('%5Ct') for line in f)%0A        variants = ((v%5B0%5D, int(v%5B1%5D), v%5B2%5D, float(v%5B3%5D), float(v%5B4%5D), float(v%5B5%5D)) for v in variants) # chrom, pos, marker_id, maf, pval, beta%0A        top_variants = heapq.nsmallest(2000, variants, key=lambda v:v%5B4%5D)%0A%0A    rv = %5B%5D%0A    for variant in top_variants:%0A        chrom, pos, ref, alt = parse_marker_id(variant%5B2%5D)%0A        assert chrom == variant%5B0%5D%0A        assert pos == variant%5B1%5D%0A%0A        rv.append(%7B%0A            'chrom': chrom,%0A            'pos': pos,%0A            'ref': ref,%0A            'alt': alt,%0A            'maf': variant%5B3%5D,%0A            'pval': variant%5B4%5D,%0A            # TODO: include beta%0A        %7D)%0A%0A    with open(dest_filename, 'w') as f:%0A        json.dump(rv, f, sort_keys=True, indent=0)%0A

Make GWAS json for each pheno