-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatch_coloc_interpret.py
136 lines (120 loc) · 4.37 KB
/
dispatch_coloc_interpret.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import sys
import pickle
import subprocess
import time
import numpy as np
def dispatch(script_path, genes_dir, genes_list_path, all_sig, status_dir, gwas_names, plasma_run_name, coloc_run_name, gene_map_path, cluster_map_path, out_path, memory, fails_only=False):
jobs = []
for name in gwas_names:
os.makedirs(os.path.join(status_dir, name), exist_ok=True)
status_path = os.path.join(status_dir, name, "coloc_interpret_status.txt")
if fails_only and os.path.isfile(status_path):
with open(status_path) as status_file:
if status_file.read() == "Complete":
continue
if not fails_only:
with open(status_path, "w") as status_file:
status_file.write("")
err_name = os.path.join(status_dir, name, "coloc_%j.out")
cmd = [
"sbatch", "--mem={0}".format(memory), "-J", name, "-o", err_name, "-x", "node12,node13",
script_path, genes_dir, genes_list_path, all_sig, gene_map_path, name, plasma_run_name, coloc_run_name, cluster_map_path, out_path, status_path
]
print(" ".join(cmd))
jobs.append(cmd)
timeout = "sbatch: error: Batch job submission failed: Socket timed out on send/recv operation"
limit = "sbatch: error: QOSMaxSubmitJobPerUserLimit"
for i in jobs:
while True:
try:
submission = subprocess.run(i, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(str(submission.stdout, 'utf-8').rstrip())
break
except subprocess.CalledProcessError as e:
# print(e.stdout) ####
err = str(e.stderr, 'utf-8').rstrip()
print(err)
if err == timeout:
print("Retrying Submit")
continue
elif err.startswith(limit):
print("Waiting for queue to clear...")
time.sleep(600)
else:
raise e
if __name__ == '__main__':
curr_path = os.path.abspath(os.path.dirname(__file__))
script_path = os.path.join(curr_path, "coloc_interpret.py")
gene_map_path = "/agusevlab/awang/ensembl/id_to_name.pickle"
data_path_kellis = "/agusevlab/awang/sc_kellis"
cluster_map_path_kellis = os.path.join(data_path_kellis, "cluster_map_429.pickle")
genes_dir_kellis = os.path.join(data_path_kellis, "genes_429")
out_path_kellis = "/agusevlab/awang/ase_finemap_results/sc_results/kellis_429/colocalization"
gwas_dir = "/agusevlab/awang/gwas_data"
gwas_names = [i.split(".")[0] for i in os.listdir(gwas_dir)]
status_dir_kellis = os.path.join(data_path_kellis, "statuses_2/coloc_interpret")
genes_list_path = os.path.join(data_path_kellis, "list_429_all.pickle")
dispatch(
script_path,
genes_dir_kellis,
genes_list_path,
"False",
status_dir_kellis,
gwas_names,
"combined",
"coloc",
gene_map_path,
cluster_map_path_kellis,
out_path_kellis,
10000,
fails_only=False
)
# dispatch(
# script_path,
# genes_dir_kellis,
# genes_list_path,
# "False",
# status_dir_kellis,
# gwas_names,
# "combined",
# "coloc",
# gene_map_path,
# cluster_map_path_kellis,
# out_path_kellis,
# 10000,
# fails_only=True
# )
groups = [
"Female",
"Male",
"AgeUnder80",
"Age80To90",
"AgeOver90",
"ReaganNeg",
"ReaganPos",
"Cerad1",
"Cerad2",
"Cerad3",
"Cerad4",
]
# groups = groups[:4] ####
# groups = groups[4:] ####
genes_list_path = os.path.join(data_path_kellis, "list_429_sig.pickle")
for group in groups:
out_path_group = os.path.join("/agusevlab/awang/ase_finemap_results/sc_results/kellis_429/colocalization_clinical", group)
dispatch(
script_path,
genes_dir_kellis,
genes_list_path,
"False",
status_dir_kellis,
gwas_names,
f"clinical_coloc_{group}",
f"clinical_coloc_res_{group}",
gene_map_path,
cluster_map_path_kellis,
out_path_group,
10000,
fails_only=False
)