/
generateGregorConf
executable file
·83 lines (71 loc) · 3.89 KB
/
generateGregorConf
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/env python3
# TheParkerLab
# Vivek Rai
# GPLv3
__description__ = """Generate a GREGOR config file using supplied options.
The Parker Lab
"""
import argparse
import glob
import sys
import os
def create_index_bed(bedfilename, annotfiles, annotdir):
with open(bedfilename, 'w') as f:
if annotfiles is not None:
for bed_file in annotfiles:
f.write("{path}\n".format(path=os.path.abspath(bed_file)))
elif annotdir is not None:
for bed_file in glob.glob(os.path.join(annotdir + "*.bed")):
f.write("{path}\n".format(path=os.path.abspath(bed_file)))
else:
print("NO OPTIONS: generated skeleton config file (gregor.conf) in current dir")
def getopts():
parser = argparse.ArgumentParser(description=__description__)
parser.add_argument('--outfile', type=str, default='gregor.conf',
help="""Name of output .conf file""")
parser.add_argument('--annotfiles', nargs='+', type=str,
help="""File with paths of annotation files to calculate enrichment in.""")
parser.add_argument('--annotdir', type=str,
help="""The directory with (unzipped) bed files if --annotfiles are not specified. Will take all .bed files in this directory""")
parser.add_argument('--snpfile', type=str,
help="""chr:pos formatted SNP files. IMPORTANT: filename should not contain '_'""")
parser.add_argument('--indexbed', type=str, default='indexbed.txt',
help="""Name of file to be created with paths of annotfiles""")
parser.add_argument('--refdir', type=str, default='/lab/data/sw/GREGOR/1.4.0/0.7',
help="""GREGOR reference. Default = /lab/data/sw/GREGOR/1.4.0/0.7 """)
parser.add_argument('--population', type=str, default='EUR',
help="""Population. Default = EUR """)
parser.add_argument('-r2', '--gregorR2Threshold', default='0.8',
help="""Minimum LD r2 for proxy SNPs (default: 0.8)""")
parser.add_argument('--ldwindow', type=int, default=1000000,
help="""Minimum LD r2 for proxy SNPs (default: 0.8)""")
parser.add_argument('-d', '--outdir', type=str,
help="""Name of the output directory""")
parser.add_argument('--neighbor', type=int, default=500,
help="""Min neighbors for GREGOR""")
parser.add_argument('--issorted', type=str, default="true",
help="""true or false if bed files are sorted""")
parser.add_argument('--topnbed', type=int, default=2, help="""Top n bed""")
parser.add_argument('--cores', type=str, default='6',
help="""Number of cores for each GREGOR job. (default: 6)""")
parser.add_argument('--batchtype', type=str, default='local',
help="""Batch job submission type (default: local)""")
return parser
if __name__ == '__main__':
parser = getopts()
args = parser.parse_args()
args.indexbed = os.path.abspath(args.indexbed)
create_index_bed(args.indexbed, args.annotfiles, args.annotdir)
with open(args.outfile, 'w') as f:
f.write("INDEX_SNP_FILE = {} \n".format(args.snpfile))
f.write("BED_FILE_INDEX = {} \n".format(args.indexbed))
f.write("REF_DIR = {} \n".format(args.refdir))
f.write("POPULATION = {} \n".format(args.population))
f.write("R2THRESHOLD = {} \n".format(args.gregorR2Threshold))
f.write("LDWINDOWSIZE = {} \n".format(args.ldwindow))
f.write("OUT_DIR = {} \n".format(args.outdir))
f.write("MIN_NEIGHBOR_NUM = {} \n".format(args.neighbor))
f.write("BEDFILE_IS_SORTED = {} \n".format(args.issorted))
f.write("TOPNBEDFILES = {} \n".format(args.topnbed))
f.write("JOBNUMBER = {} \n".format(args.cores))
f.write("BATCHTYPE = {} \n".format(args.batchtype))