-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-process.py
347 lines (295 loc) · 18.2 KB
/
pre-process.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import subprocess
import pandas as pd
from pathlib import Path
import json
import numpy as np
export_path = "export PATH=$PATH:/gpfs/data/rsingh47/masif/sratoolkit.2.11.1-centos_linux64/bin"
call_pipeline_base = "caper run /gpfs/data/rsingh47/masif/chip-seq-pipeline2/chip.wdl -i /gpfs/data/rsingh47/masif/pipeline_raw_data"
def generate_fastq(sra_numbers, output_path):
# this will download the .sra files to ~/ncbi/public/sra/ (will create directory if not present)
# for sra_id in sra_numbers:
# print ("Currently downloading: " + sra_id)
# prefetch = "prefetch " + sra_id
# print ("The command used was: " + prefetch)
# subprocess.call(prefetch, shell=True)
# this will extract the .sra files from above into a folder named 'fastq'
for sra_id in sra_numbers:
print ("Generating fastq for: " + sra_id)
fastq_dump = "fastq-dump --outdir " + output_path + " --dumpbase --clip " + sra_id
print ("The command used was: " + fastq_dump)
subprocess.call(fastq_dump, shell=True)
def process_srr_val(srr_val):
cleaned_srr_arr = []
if not(pd.isna(srr_val)):
split_srr = srr_val.split(";")
for x in split_srr:
x = x.strip()
cleaned_srr_arr.append(x)
print(cleaned_srr_arr)
return cleaned_srr_arr
def run_pipeline(histone_str, path = "/gpfs/data/rsingh47/masif/ChromAge/GEO_metadata_age_copy.csv"):
with open(path, 'rb') as f:
df = pd.read_csv(f)
df = df.sort_values(by="Age", ascending=False)
# arr = df["H3K27ac SRR list"]
# arr1 = df["H3K4me3 SRR list"]
# arr2 = df["H3K4me1 SRR list"]
# arr3 = df["H3K27me3 SRR list"]
# arr4 = df["H3K9me3 SRR list"]
# arr5 = df["H3K36me3 SRR list"]
# print(len(arr[~pd.isna(arr)]))
# print(len(arr1[~pd.isna(arr1)]))
# print(len(arr2[~pd.isna(arr2)]))
# print(len(arr3[~pd.isna(arr3)]))
# print(len(arr4[~pd.isna(arr4)]))
# print(len(arr5[~pd.isna(arr5)]))
# return
print("Finished reading data!")
check = False
for i in range(df.shape[0]):
control_srr_1 = process_srr_val(df["Control SRR list 1"][i])
control_srr_2 = process_srr_val(df["Control SRR list 2"][i])
h3k4me3_srr = process_srr_val(df["H3K4me3 SRR list"][i]) ## h3k4me3, h3k27ac are more important
h3k4me3_GEO = process_srr_val(df["H3K4me3 GEO"][i])
h3k27ac_srr = process_srr_val(df["H3K27ac SRR list"][i])
h3k27ac_GEO = process_srr_val(df["H3K27ac GEO"][i])
h3k4me1_srr = process_srr_val(df["H3K4me1 SRR list"][i])
h3k4me1_GEO = process_srr_val(df["H3K4me1 GEO"][i])
h3k27me3_srr = process_srr_val(df["H3K27me3 SRR list"][i])
h3k27me3_GEO = process_srr_val(df["H3K27me3 GEO"][i])
h3k9me3_srr = process_srr_val(df["H3K9me3 SRR list"][i])
h3k9me3_GEO = process_srr_val(df["H3K9me3 GEO"][i])
h3k36me3_srr = process_srr_val(df["H3K36me3 SRR list"][i])
h3k36me3_GEO = process_srr_val(df["H3K36me3 GEO"][i])
paired_end = df["SE or PE"][i]
if (paired_end == "SE"):
paired_end = False
else:
paired_end = True
h3k4me3_json = dict()
h3k27ac_json = dict()
h3k4me1_json = dict()
h3k27me3_json = dict()
h3k9me3_json = dict()
h3k36me3_json = dict()
generic_json = {
"chip.pipeline_type" : "histone",
"chip.genome_tsv" : "/gpfs/data/rsingh47/masif/chip-seq-pipeline2/genome/hg38.tsv",
}
CONTROL_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/control/"
H3K4me3_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/h3k4me3/"
H3K27ac_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/h3k27ac/"
H3K4me1_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/h3k4me1/"
H3K27me3_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/h3k27me3/"
H3K9me3_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/h3k9me3/"
H3K36me3_DIR = "/gpfs/data/rsingh47/masif/pipeline_raw_data/h3k36me3/"
if (histone_str == 'H3K4me3'):
if (len(h3k4me3_srr) > 0):
h3k4me3_json = generic_json
h3k4me3_json["chip.paired_end"] = paired_end
h3k4me3_json["chip.title"] = "h3k4me3_json_" + h3k4me3_GEO[0]
h3k4me3_json["chip.description"] = "Example_" + h3k4me3_GEO[0] + " h3k4me3_json"
h3k4me3_json["chip.fastqs_rep1_R1"] = []
for x in range (len(h3k4me3_srr)):
if not(Path(H3K4me3_DIR + h3k4me3_srr[x] + ".fastq").is_file()):
generate_fastq([h3k4me3_srr[x]], H3K4me3_DIR)
h3k4me3_json["chip.fastqs_rep1_R1"].append(H3K4me3_DIR + h3k4me3_srr[x] + ".fastq")
h3k4me3_json["chip.ctl_fastqs_rep1_R1"] = []
for x in range (len(control_srr_1)):
if not(Path(CONTROL_DIR + control_srr_1[x] + ".fastq").is_file()):
generate_fastq([control_srr_1[x]], CONTROL_DIR)
h3k4me3_json["chip.ctl_fastqs_rep1_R1"].append(CONTROL_DIR + control_srr_1[x] + ".fastq")
if len(control_srr_2) > 0:
h3k4me3_json["chip.ctl_fastqs_rep2_R1"] = []
for x in range (len(control_srr_2)):
if not(Path(CONTROL_DIR + control_srr_2[x] + ".fastq").is_file()):
generate_fastq([control_srr_2[x]], CONTROL_DIR)
h3k4me3_json["chip.ctl_fastqs_rep2_R1"].append(CONTROL_DIR + control_srr_2[x] + ".fastq")
print(h3k4me3_json)
jsonFile = open(H3K4me3_DIR + "h3k4me3_" + h3k4me3_GEO[0] + ".json", "w")
jsonFile.write(json.dumps(h3k4me3_json))
jsonFile.close()
if (histone_str == 'H3K27ac'):
if (len(h3k27ac_srr) > 0):
h3k27ac_json = generic_json
h3k27ac_json["chip.paired_end"] = paired_end
h3k27ac_json["chip.title"] = "h3k27ac_json_" + h3k27ac_GEO[0]
h3k27ac_json["chip.description"] = "Example_" + h3k27ac_GEO[0] + " h3k27ac_json"
h3k27ac_json["chip.fastqs_rep1_R1"] = []
for x in range (len(h3k27ac_srr)):
if not(Path(H3K27ac_DIR + h3k27ac_srr[x] + ".fastq").is_file()):
generate_fastq([h3k27ac_srr[x]], H3K27ac_DIR)
h3k27ac_json["chip.fastqs_rep1_R1"].append(H3K27ac_DIR + h3k27ac_srr[x] + ".fastq")
h3k27ac_json["chip.ctl_fastqs_rep1_R1"] = []
for x in range (len(control_srr_1)):
if not(Path(CONTROL_DIR + control_srr_1[x] + ".fastq").is_file()):
generate_fastq([control_srr_1[x]], CONTROL_DIR)
h3k27ac_json["chip.ctl_fastqs_rep1_R1"].append(CONTROL_DIR + control_srr_1[x] + ".fastq")
if len(control_srr_2) > 0:
h3k27ac_json["chip.ctl_fastqs_rep2_R1"] = []
for x in range (len(control_srr_2)):
if not(Path(CONTROL_DIR + control_srr_2[x] + ".fastq").is_file()):
generate_fastq([control_srr_2[x]], CONTROL_DIR)
h3k27ac_json["chip.ctl_fastqs_rep2_R1"].append(CONTROL_DIR + control_srr_2[x] + ".fastq")
print(h3k27ac_json)
jsonFile = open(H3K27ac_DIR + "h3k27ac_" + h3k27ac_GEO[0] + ".json", "w")
jsonFile.write(json.dumps(h3k27ac_json))
jsonFile.close()
if (histone_str == 'H3K4me1'):
if (len(h3k4me1_srr) > 0):
h3k4me1_json = generic_json
h3k4me1_json["chip.paired_end"] = paired_end
h3k4me1_json["chip.title"] = "h3k4me1_json_" + h3k4me1_GEO[0]
h3k4me1_json["chip.description"] = "Example_" + h3k4me1_GEO[0] + " h3k4me1_json"
h3k4me1_json["chip.fastqs_rep1_R1"] = []
for x in range (len(h3k4me1_srr)):
if not(Path(H3K4me1_DIR + h3k4me1_srr[x] + ".fastq").is_file()):
generate_fastq([h3k4me1_srr[x]], H3K4me1_DIR)
h3k4me1_json["chip.fastqs_rep1_R1"].append(H3K4me1_DIR + h3k4me1_srr[x] + ".fastq")
h3k4me1_json["chip.ctl_fastqs_rep1_R1"] = []
for x in range (len(control_srr_1)):
if not(Path(CONTROL_DIR + control_srr_1[x] + ".fastq").is_file()):
generate_fastq([control_srr_1[x]], CONTROL_DIR)
h3k4me1_json["chip.ctl_fastqs_rep1_R1"].append(CONTROL_DIR + control_srr_1[x] + ".fastq")
if len(control_srr_2) > 0:
h3k4me1_json["chip.ctl_fastqs_rep2_R1"] = []
for x in range (len(control_srr_2)):
if not(Path(CONTROL_DIR + control_srr_2[x] + ".fastq").is_file()):
generate_fastq([control_srr_2[x]], CONTROL_DIR)
h3k4me1_json["chip.ctl_fastqs_rep2_R1"].append(CONTROL_DIR + control_srr_2[x] + ".fastq")
print(h3k4me1_json)
jsonFile = open(H3K4me1_DIR + "h3k4me1_" + h3k4me1_GEO[0] + ".json", "w")
jsonFile.write(json.dumps(h3k4me1_json))
jsonFile.close()
if (histone_str == 'H3K27me3'):
if (len(h3k27me3_srr) > 0):
h3k27me3_json = generic_json
h3k27me3_json["chip.paired_end"] = paired_end
h3k27me3_json["chip.title"] = "h3k27me3_json_" + h3k27me3_GEO[0]
h3k27me3_json["chip.description"] = "Example_" + h3k27me3_GEO[0] + "h3k27me3_json"
h3k27me3_json["chip.fastqs_rep1_R1"] = []
for x in range (len(h3k27me3_srr)):
if not(Path(H3K27me3_DIR + h3k27me3_srr[x] + ".fastq").is_file()):
generate_fastq([h3k27me3_srr[x]], H3K27me3_DIR)
h3k27me3_json["chip.fastqs_rep1_R1"].append(H3K27me3_DIR + h3k27me3_srr[x] + ".fastq")
h3k27me3_json["chip.ctl_fastqs_rep1_R1"] = []
for x in range (len(control_srr_1)):
if not(Path(CONTROL_DIR + control_srr_1[x] + ".fastq").is_file()):
generate_fastq([control_srr_1[x]], CONTROL_DIR)
h3k27me3_json["chip.ctl_fastqs_rep1_R1"].append(CONTROL_DIR + control_srr_1[x] + ".fastq")
if len(control_srr_2) > 0:
h3k27me3_json["chip.ctl_fastqs_rep2_R1"] = []
for x in range (len(control_srr_2)):
if not(Path(CONTROL_DIR + control_srr_2[x] + ".fastq").is_file()):
generate_fastq([control_srr_2[x]], CONTROL_DIR)
h3k27me3_json["chip.ctl_fastqs_rep2_R1"].append(CONTROL_DIR + control_srr_2[x] + ".fastq")
print(h3k27me3_json)
jsonFile = open(H3K27me3_DIR + "h3k27me3_" + h3k27me3_GEO[0] + ".json", "w")
jsonFile.write(json.dumps(h3k27me3_json))
jsonFile.close()
if (histone_str == 'H3K9me3'):
if (len(h3k9me3_srr) > 0):
h3k9me3_json = generic_json
h3k9me3_json["chip.paired_end"] = paired_end
h3k9me3_json["chip.title"] = "h3k9me3_json_" + h3k9me3_GEO[0]
h3k9me3_json["chip.description"] = "Example_" + h3k9me3_GEO[0] + "h3k9me3_json"
h3k9me3_json["chip.fastqs_rep1_R1"] = []
for x in range (len(h3k9me3_srr)):
if not(Path(H3K9me3_DIR + h3k9me3_srr[x] + ".fastq").is_file()):
generate_fastq([h3k9me3_srr[x]], H3K9me3_DIR)
h3k9me3_json["chip.fastqs_rep1_R1"].append(H3K9me3_DIR + h3k9me3_srr[x] + ".fastq")
h3k9me3_json["chip.ctl_fastqs_rep1_R1"] = []
for x in range (len(control_srr_1)):
if not(Path(CONTROL_DIR + control_srr_1[x] + ".fastq").is_file()):
generate_fastq([control_srr_1[x]], CONTROL_DIR)
h3k9me3_json["chip.ctl_fastqs_rep1_R1"].append(CONTROL_DIR + control_srr_1[x] + ".fastq")
if len(control_srr_2) > 0:
h3k9me3_json["chip.ctl_fastqs_rep2_R1"] = []
for x in range (len(control_srr_2)):
if not(Path(CONTROL_DIR + control_srr_2[x] + ".fastq").is_file()):
generate_fastq([control_srr_2[x]], CONTROL_DIR)
h3k9me3_json["chip.ctl_fastqs_rep2_R1"].append(CONTROL_DIR + control_srr_2[x] + ".fastq")
print(h3k9me3_json)
jsonFile = open(H3K9me3_DIR + "h3k9me3_" + h3k9me3_GEO[0] + ".json", "w")
jsonFile.write(json.dumps(h3k9me3_json))
jsonFile.close()
if (histone_str == 'H3K36me3'):
if (len(h3k36me3_srr) > 0):
h3k36me3_json = generic_json
h3k36me3_json["chip.paired_end"] = paired_end
h3k36me3_json["chip.title"] = "h3k36me3_json_" + h3k36me3_GEO[0]
h3k36me3_json["chip.description"] = "Example_" + h3k36me3_GEO[0] + "h3k36me3_json"
h3k36me3_json["chip.fastqs_rep1_R1"] = []
for x in range (len(h3k36me3_srr)):
if not(Path(H3K36me3_DIR + h3k36me3_srr[x] + ".fastq").is_file()):
generate_fastq([h3k36me3_srr[x]], H3K36me3_DIR)
h3k36me3_json["chip.fastqs_rep1_R1"].append(H3K36me3_DIR + h3k36me3_srr[x] + ".fastq")
h3k36me3_json["chip.ctl_fastqs_rep1_R1"] = []
for x in range (len(control_srr_1)):
if not(Path(CONTROL_DIR + control_srr_1[x] + ".fastq").is_file()):
generate_fastq([control_srr_1[x]], CONTROL_DIR)
h3k36me3_json["chip.ctl_fastqs_rep1_R1"].append(CONTROL_DIR + control_srr_1[x] + ".fastq")
if len(control_srr_2) > 0:
h3k36me3_json["chip.ctl_fastqs_rep2_R1"] = []
for x in range (len(control_srr_2)):
if not(Path(CONTROL_DIR + control_srr_2[x] + ".fastq").is_file()):
generate_fastq([control_srr_2[x]], CONTROL_DIR)
h3k36me3_json["chip.ctl_fastqs_rep2_R1"].append(CONTROL_DIR + control_srr_2[x] + ".fastq")
print(h3k36me3_json)
jsonFile = open(H3K36me3_DIR + "h3k36me3_" + h3k36me3_GEO[0] + ".json", "w")
jsonFile.write(json.dumps(h3k36me3_json))
jsonFile.close()
if (histone_str == 'H3K4me3'):
if (len(h3k4me3_json) != 0):
h3k4me3_pipeline_call = call_pipeline_base + "/h3k4me3/" + "h3k4me3_" + h3k4me3_GEO[0] + ".json"
print ("Running the encode pipeline for" + str(h3k4me3_json))
print ("The command used was: " + h3k4me3_pipeline_call)
subprocess.call(h3k4me3_pipeline_call, shell=True)
subprocess.call("sh extract_output.sh", shell=True)
if (histone_str == 'H3K27ac'):
if (len(h3k27ac_json) != 0):
h3k27ac_pipeline_call = call_pipeline_base + "/h3k27ac/" + "h3k27ac_" + h3k27ac_GEO[0] + ".json"
print ("Running the encode pipeline for" + str(h3k27ac_json))
print ("The command used was: " + h3k27ac_pipeline_call)
subprocess.call(h3k27ac_pipeline_call, shell=True)
subprocess.call("sh extract_output.sh", shell=True)
if (histone_str == 'H3K4me1'):
if (len(h3k4me1_json) != 0):
h3k4me1_pipeline_call = call_pipeline_base + "/h3k4me1/" + "h3k4me1_" + h3k4me1_GEO[0] + ".json"
print ("Running the encode pipeline for" + str(h3k4me1_json))
print ("The command used was: " + h3k4me1_pipeline_call)
subprocess.call(h3k4me1_pipeline_call, shell=True)
subprocess.call("sh extract_output.sh", shell=True)
if (histone_str == 'H3K27me3'):
if (len(h3k27me3_json) != 0):
h3k27me3_pipeline_call = call_pipeline_base + "/h3k27me3/" + "h3k27me3_" + h3k27me3_GEO[0] + ".json"
print ("Running the encode pipeline for" + str(h3k27me3_json))
print ("The command used was: " + h3k27me3_pipeline_call)
subprocess.call(h3k27me3_pipeline_call, shell=True)
subprocess.call("sh extract_output.sh", shell=True)
if (histone_str == 'H3K9me3'):
if (len(h3k9me3_json) != 0):
h3k9me3_pipeline_call = call_pipeline_base + "/h3k9me3/" + "h3k9me3_" + h3k9me3_GEO[0] + ".json"
print ("Running the encode pipeline for" + str(h3k9me3_json))
print ("The command used was: " + h3k9me3_pipeline_call)
subprocess.call(h3k9me3_pipeline_call, shell=True)
subprocess.call("sh extract_output.sh", shell=True)
if (histone_str == 'H3K36me3'):
if (len(h3k36me3_json) != 0):
h3k36me3_pipeline_call = call_pipeline_base + "/h3k36me3/" + "h3k36me3_" + h3k36me3_GEO[0] + ".json"
print ("Running the encode pipeline for" + str(h3k36me3_json))
print ("The command used was: " + h3k36me3_pipeline_call)
subprocess.call(h3k36me3_pipeline_call, shell=True)
subprocess.call("sh extract_output.sh", shell=True)
print("ROW " + str(i) + " finished")
local_path = "/Users/haider/Documents/Fall-2021/ChromAge/GEO_metadata.csv"
run_pipeline(histone_str='H3K27ac')
# json_example = {
# "chip.pipeline_type" : "histone",
# "chip.genome_tsv" : "/gpfs/home/masif/data/masif/chip-seq-pipeline2/genome/hg38.tsv",
# "chip.fastqs_rep1_R1" : ["/gpfs/home/masif/data/masif/chip-seq-pipeline2/example_input_j"],
# "chip.ctl_fastqs_rep1_R1" : ["/gpfs/home/masif/data/masif/chip-seq-pipeline2/example_inp"],
# "chip.paired_end" : False,
# "chip.title" : "CHROMAGE001",
# "chip.description" : "Example1 ChromAge"
# }