-
Notifications
You must be signed in to change notification settings - Fork 13
/
ENCODE_processing_summary.py
507 lines (428 loc) · 20.9 KB
/
ENCODE_processing_summary.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#!/usr/bin/env python
# -*- coding: latin-1 -*-
''' Prepare a summary for different datatypes for ENCODE3
'''
import os.path
import copy
import argparse
import encodedcc
import collections
from encodedcc import get_ENCODE
EPILOG = '''
The output of this program is for consumption by a googlesheet.
'''
def getArgs():
parser = argparse.ArgumentParser(
description=__doc__, epilog=EPILOG,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--datatype',
help="The datatype of interest: CHIP, WGBS, Accessibility, RNA, RBP")
parser.add_argument('--status',
default='released',
help="released or unreleased Default is released")
parser.add_argument('--grant',
help="specify the PI last name of the grant of interest, ENCODE2 will mimic ENCODE3")
parser.add_argument('--key',
default='default',
help="The keypair identifier from the keyfile. \
Default is --key=default")
parser.add_argument('--keyfile',
default=os.path.expanduser("~/keypairs.json"),
help="The keypair file. Default is --keyfile=%s" % (os.path.expanduser("~/keypairs.json")))
parser.add_argument('--debug',
default=False,
action='store_true',
help="Print debug messages. Default is False.")
args = parser.parse_args()
return args
def make_matrix(rows, columns, headers, queries, basic_query, connection):
matrix = {}
for row in rows:
matrix[row] = [row]
for col in headers:
query = basic_query + queries[row] + columns[col]
res = get_ENCODE(query, connection, frame='object')
link = connection.server + query
total = res['total']
func = '=HYPERLINK(' + '"' + link + '",' + repr(total) + ')'
matrix[row].append(func)
print('\t'.join(matrix[row]))
print(' ')
print(' ')
def make_rna_report(connection, columns, rows):
basic_query = 'search/?type=Experiment'
assays = collections.OrderedDict([
('Standard RNA-seq', '&assay_title=RNA-seq'),
('PolyA RNA', '&assay_title=polyA+mRNA+RNA-seq'),
('PolyA depleted RNA', '&assay_title=polyA+depleted+RNA-seq'),
('Small RNA', '&assay_title=small+RNA-seq'),
('RAMPAGE and CAGE', '&assay_title=CAGE&assay_title=RAMPAGE'),
('single cell', '&assay_title=single+cell+RNA-seq'),
])
micro_assays = {
'microRNA seq': '&assay_title=microRNA-seq',
'microRNA counts': '&assay_title=microRNA+counts',
}
labels = [
'Total',
'Released',
'Released with issues',
'Unreleased',
'Mapped on GRCh38 or mm10',
'Uniformly Processed on hg19-v19',
'Cannot be currently processed',
'In processing queue',
'Unreleased files in a released experiment',
'Missing GRCh38',
'missing fastqs'
]
micro_labels = [
'Total',
'Released',
'Released with issues',
'Unreleased',
'Submitted on GRCh38 or mm10',
'Submitted on hg19'
]
headers = list(columns.keys())
for assay in assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + assays[assay]
make_matrix(labels, columns, headers, rows,
new_basic_query, connection)
for assay in micro_assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + micro_assays[assay]
make_matrix(micro_labels, columns, headers,
rows, new_basic_query, connection)
def make_methyl_report(connection, columns, rows):
basic_query = 'search/?type=Experiment'
assays = collections.OrderedDict([
('WGBS', '&assay_title=WGBS'),
('RRBS', '&assay_title=RRBS'),
('Array', '&assay_title=DNAme+array'),
])
labels = [
'Total',
'Released',
'Released with issues',
'Unreleased',
'Mapped on GRCh38 or mm10',
'Mapped on hg19',
'Cannot be currently processed',
'In processing queue',
'Unreleased files in a released experiment'
]
headers = list(columns.keys())
for assay in assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + assays[assay]
make_matrix(labels, columns, headers, rows,
new_basic_query, connection)
def make_3d_report(connection, columns, rows):
basic_query = 'search/?type=Experiment'
assays = collections.OrderedDict([
('HIC', '&assay_title=Hi-C'),
('Chia-PET', '&assay_title=ChIA-PET')
])
labels = [
'Total',
'Released',
'Released with issues',
'Unreleased',
'Submitted on GRCh38 or mm10',
'Submitted on hg19',
'Unreleased files in a released experiment'
]
headers = list(columns.keys())
for assay in assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + assays[assay]
make_matrix(labels, columns, headers, rows,
new_basic_query, connection)
def make_chip_report(connection, columns, queries):
basic_query = 'search/?type=Experiment&assay_term_name=ChIP-seq'
catagories = collections.OrderedDict([
('controls', '&target.investigated_as=control'),
('histone mods', '&target.investigated_as=histone'),
('H3K27ac and H3K4me3', '&target.label=H3K4me3&target.label=H3K27ac'),
('other targets', '&target.investigated_as%21=control&target.investigated_as%21=histone')
])
rows_basic = [
'Total',
'Released',
'Unreleased',
'Released with antibody issues',
'Released with NOT COMPLIANT issues',
'Released with ERROR issues',
'Unreplicated',
'Mapped on GRCh38 or mm10',
'Unmapped on GRCh38 or mm10',
'Peaks called on GRCh38 or mm10',
'Missing GRCh38 or mm10 peaks',
'Mapped on hg19',
'Unmapped on hg19',
'Peaks called on hg19',
'Cannot be currently processed',
'In processing queue',
'Unreleased files in a released experiment',
'missing fastqs'
]
headers = list(columns.keys())
for catagory in catagories.keys():
print(catagory, '--------------------------------------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + catagories[catagory]
rows = copy.copy(rows_basic)
if catagory == 'controls':
rows.remove('Unreplicated')
rows.remove('Peaks called on GRCh38 or mm10')
rows.remove('Released with antibody issues')
rows.remove('Missing GRCh38 or mm10 peaks')
make_matrix(rows, columns, headers, queries,
new_basic_query, connection)
def make_dna_report(connection, columns, rows):
basic_query = 'search/?type=Experiment'
assays = collections.OrderedDict([
('DNase', '&assay_title=DNase-seq'),
('ATAC', '&assay_title=ATAC-seq'),
])
labels = [
'Total',
'Unreleased',
'Released',
'With ERROR issues',
'With NOT COMPLIANT issues',
'Processed on Dnase Grch38 or mm10',
'Processed on Dnase hg19',
'Cannot be currently processed',
'In processing queue',
'Unreleased files in a released experiment',
'missing fastqs'
]
unreleased_labels = [
'Total',
'Unreleased',
'Unreleased with ERROR issues',
'Unreleased with NOT COMPLIANT issues',
'Mapped on GRCh38 or mm10',
'Mapped on hg19',
'Cannot be currently processed',
'In processing queue',
'Unreleased files in a released experiment',
'missing fastqs'
]
headers = list(columns.keys())
for assay in assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + assays[assay]
make_matrix(labels, columns, headers, rows,
new_basic_query, connection)
def make_rbp_report(connection, rows):
basic_query = 'search/?type=Experiment&award.project=ENCODE'
assays = collections.OrderedDict([
('eCLIP', '&assay_title=eCLIP'),
('iCLIP', '&assay_title=iCLIP'),
('RIP-seq', '&assay_title=RIP-seq'),
('Bind-n-Seq', '&assay_title=RNA+Bind-n-Seq'),
])
seq_assays = collections.OrderedDict([
('shRNA knockdown', '&assay_title=shRNA+RNA-seq'),
('CRISPR', '&assay_title=CRISPR+RNA-seq'),
('siRNA knockdown', '&assay_title=siRNA+RNA-seq'),
('total knockdowns',
'&assay_title=CRISPR+RNA-seq&assay_title=shRNA+RNA-seq&assay_title=siRNA+RNA-seq')
])
labels = [
'Total',
'Released',
'Released with antibody issues',
'Released with ERROR issues',
'Released with NOT COMPLIANT',
'Unreleased',
'Submitted on GRCh38',
'Submitted on hg19',
'Unreleased files in a released experiment',
'Missing signal files'
]
seq_labels = [
'Total',
'Released',
'Released with ERROR issues',
'Released with NOT COMPLIANT',
'Unreleased',
'Processed on GRCh38',
'Mapped on hg19',
'In processing queue',
'Unreleased files in a released experiment',
]
columns = {
'ENCODE3-experiments': '&award.rfa=ENCODE3&target.investigated_as!=control',
'ENCODE3-controls': '&award.rfa=ENCODE3&target.investigated_as=control',
'ENCODE2-experiments': '&award.rfa=ENCODE2&target.investigated_as!=control',
'ENCODE2-controls': '&award.rfa=ENCODE2&target.investigated_as=control',
'Total': '&award.rfa=ENCODE3&award.rfa=ENCODE2',
}
headers = [
'ENCODE3-experiments',
'ENCODE3-controls',
'ENCODE2-experiments',
'ENCODE2-controls',
'Total'
]
for assay in assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + assays[assay]
make_matrix(labels, columns, headers, rows,
new_basic_query, connection)
for assay in seq_assays.keys():
print(assay, '--------')
print('\t'.join([''] + headers))
new_basic_query = basic_query + seq_assays[assay]
make_matrix(seq_labels, columns, headers,
rows, new_basic_query, connection)
def main():
args = getArgs()
key = encodedcc.ENC_Key(args.keyfile, args.key)
connection = encodedcc.ENC_Connection(key)
labs = {
'stam': '&lab.title=John+Stamatoyannopoulos%2C+UW&lab.title=Job+Dekker%2C+UMass',
'bernstein': '&lab.title=Bradley+Bernstein%2C+Broad',
'gingeras': '&lab.title=Yijun+Ruan%2C+GIS&lab.title=Thomas+Gingeras%2C+CSHL&lab.title=Piero+Carninci%2C+RIKEN',
'snyder': '&lab.title=Michael+Snyder%2C+Stanford&lab.title=Sherman+Weissman%2C+Yale&lab.title=Kevin+White%2C+UChicago&lab.title=Peggy+Farnham%2C+USC'
}
# ----------- QUERIES ----------------------------------------------------
unreplicated_query = '&replication_type=unreplicated'
replicated_query = '&replication_type!=unreplicated'
not_pipeline_query = '&files.analysis_step_version.analysis_step.pipelines.title%21=Transcription+factor+ChIP-seq'
no_peaks_query = '&files.file_type!=bigBed+narrowPeak'
concordance_query = '&searchTerm=IDR%3Afail' # '&searchTerm=IDR%3Afail'
unrunnable_query = '&internal_status=unrunnable'
pipeline_query = '&files.analysis_step_version.analysis_step.pipelines.title=Transcription+factor+ChIP-seq'
read_depth_query = '&audit.NOT_COMPLIANT.category=insufficient+read+depth'
read_depth_query_3 = '&audit.WARNING.category=low+read+depth'
complexity_query = '&audit.NOT_COMPLIANT.category=insufficient+library+complexity'
read_length_query = '&files.read_length=271272&files.read_length=657265&files.read_length=25&files.read_length=31&files.read_length=30'
no_concerns_query = '&internal_status%21=requires+lab+review&internal_status%21=unrunnable&internal_status%21=pipeline+error'
human_query = '&replicates.library.biosample.donor.organism.scientific_name=Homo+sapiens'
mouse_query = '&replicates.library.biosample.donor.organism.scientific_name=Mus+musculus'
unknown_org_query = '&replicates.library.biosample.donor.organism.scientific_name%21=Homo+sapiens&replicates.library.biosample.donor.organism.scientific_name%21=Mus+musculus'
ENCODE2_query = '&award.rfa=ENCODE2&award.rfa=ENCODE2-Mouse'
ENCODE3_query = '&award.rfa=ENCODE3'
ROADMAP_query = '&award.rfa=Roadmap'
total_query = '&status=released&status=submitted&status=started&status=ready+for+review'
released_query = '&status=released'
proposed_query = '&status=proposed'
unreleased_query = '&status=submitted&status=ready+for+review&status=started'
concerns_query = '&internal_status=requires+lab+review&internal_status=unrunnable&internal_status=pipeline+error&status!=deleted&status!=revoked'
antibody_query = '&audit.NOT_COMPLIANT.category=not+characterized+antibody'
orange_audits_query = '&audit.NOT_COMPLIANT.category=missing+controlled_by&audit.NOT_COMPLIANT.category=insufficient+read+depth&audit.NOT_COMPLIANT.category=missing+documents&audit.NOT_COMPLIANT.category=control+insufficient+read+depth&audit.NOT_COMPLIANT.category=unreplicated+experiment&audit.NOT_COMPLIANT.category=poor+library+complexity&audit.NOT_COMPLIANT.category=severe+bottlenecking&audit.NOT_COMPLIANT.category=insufficient+replicate+concordance&audit.NOT_COMPLIANT.category=missing+possible_controls&audit.NOT_COMPLIANT.category=missing+input+control'
red_audits_query = '&audit.ERROR.category=control+extremely+low+read+depth&audit.ERROR.category=missing+raw+data+in+replicate&audit.ERROR.category=missing+donor&audit.ERROR.category=inconsistent+library+biosample&audit.ERROR.category=inconsistent+replicate&audit.ERROR.category=replicate+with+no+library&audit.ERROR.category=technical+replicates+with+not+identical+biosample&&audit.ERROR.category=missing+paired_with&audit.ERROR.category=missing+possible_controls&audit.ERROR.category=inconsistent+control&audit.ERROR.category=missing+antibody'
orange_audits_query2 = '&audit.NOT_COMPLIANT.category=insufficient+read+length&audit.NOT_COMPLIANT.category=control+low+read+depth&audit.NOT_COMPLIANT.category=insufficient+read+depth&audit.NOT_COMPLIANT.category=missing+documents&audit.NOT_COMPLIANT.category=unreplicated+experiment&audit.NOT_COMPLIANT.category=missing+possible_controls&audit.NOT_COMPLIANT.category=missing+spikeins&audit.NOT_COMPLIANT.category=missing+RNA+fragment+size'
peaks_query = '&files.file_type=bigBed+narrowPeak'
missing_signal_query = '&files.file_type!=bigWig&target.investigated_as!=control'
grch38_query = '&files.assembly=GRCh38'
v19_query = '&files.genome_annotation=V19'
not_v19_query = '&files.genome_annotation!=V19'
hg19_query = '&files.assembly=hg19'
mm10_query = '&files.assembly=mm10'
hg19_vis_query = '&assembly=hg19'
grch38_vis_query = '&assembly=GRCh38'
not_grch38_vis_query = '&assembly!=GRCh38'
mm10_vis_query = '&assembly=mm10'
not_mm10_vis_query = '&assembly!=mm10'
not_grch38_query = '&files.assembly!=GRCh38'
not_hg19_query = '&files.assembly!=hg19'
not_mm10_query = '&files.assembly!=mm10'
uniform_query = '&files.lab.name=encode-processing-pipeline'
requires_query = '&internal_status=requires+lab+review'
submitted_query = '&files.lab.name!=encode-processing-pipeline'
audits_query = '&audit.NOT_COMPLIANT.category=missing+controlled_by&audit.NOT_COMPLIANT.category=insufficient+read+depth&audit.NOT_COMPLIANT.category=missing+documents&audit.NOT_COMPLIANT.category=unreplicated+experiment&assay_slims=Transcription&audit.NOT_COMPLIANT.category=missing+possible_controls&audit.NOT_COMPLIANT.category=missing+spikeins&audit.NOT_COMPLIANT.category=missing+RNA+fragment+size'
processing_query = '&internal_status=pipeline+ready&internal_status=processing'
mismatched_file_query = '&audit.INTERNAL_ACTION.category=mismatched+file+status'
dnase_pipeline = "&files.analysis_step_version.analysis_step.pipelines.title=DNase-HS+pipeline+%28paired-end%29&files.analysis_step_version.analysis_step.pipelines.title=DNase-HS+pipeline+%28single-end%29&files.file_type=bigBed+broadPeak"
lab_query = labs.get(args.grant)
filters = {
'released': released_query,
'unreleased': total_query
}
row_queries = {
'Total': total_query,
'Released': released_query,
'Released with issues': released_query + audits_query,
'Released with antibody issues': released_query + antibody_query,
'Released with NOT COMPLIANT issues': released_query + orange_audits_query,
'Released with NOT COMPLIANT': released_query + orange_audits_query2,
'Released with ERROR issues': released_query + red_audits_query,
'With ERROR issues': red_audits_query + filters[args.status],
'With NOT COMPLIANT issues': orange_audits_query + filters[args.status],
'Unreleased': unreleased_query,
'Proposed': proposed_query,
'Processed on GRCh38': grch38_query + filters[args.status],
'Processed on Dnase Grch38 or mm10': dnase_pipeline + grch38_vis_query + mm10_vis_query + filters[args.status],
'Mapped on GRCh38 or mm10': grch38_query + mm10_query + filters[args.status],
'Unmapped on GRCh38 or mm10': not_grch38_query + not_mm10_query + filters[args.status],
'Submitted on GRCh38': grch38_query + filters[args.status],
'Submitted on GRCh38 or mm10': grch38_query + mm10_query + filters[args.status],
'Uniformly Processed on hg19-v19': v19_query + filters[args.status],
'Mapped on hg19': hg19_query + uniform_query + filters[args.status],
'Unmapped on hg19': not_hg19_query + filters[args.status],
'Processed on Dnase hg19': dnase_pipeline + hg19_vis_query + filters[args.status],
'Peaks called on hg19': hg19_vis_query + uniform_query + filters[args.status],
'Peaks called on GRCh38 or mm10': grch38_vis_query + mm10_vis_query + filters[args.status],
'Submitted on hg19': hg19_query + filters[args.status],
'Processed on mm10': mm10_query + filters[args.status],
'Submitted on mm10': mm10_query + filters[args.status],
'Cannot be currently processed': concerns_query + filters[args.status],
'In processing queue': processing_query + filters[args.status],
'Unreleased files in a released experiment': mismatched_file_query,
'Missing GRCh38 or mm10 peaks': not_grch38_vis_query + not_mm10_vis_query + replicated_query + filters[args.status],
'Missing hg19': not_hg19_query + not_mm10_query + filters[args.status],
'Missing hg19-v19': not_v19_query + not_mm10_query + filters[args.status],
'Missing signal files': total_query + missing_signal_query,
'missing fastqs': '&files.file_format!=fastq' + total_query,
'Unreplicated': unreplicated_query + filters[args.status]
}
columns = collections.OrderedDict([
('ENCODE3-human', ENCODE3_query + human_query),
('ENCODE3-mouse', ENCODE3_query + mouse_query),
('ENCODE2-human', ENCODE2_query + human_query),
('ENCODE2-mouse', ENCODE2_query + mouse_query),
# ('Organism Unknown', ENCODE3_query + unknown_org_query),
('ROADMAP', ROADMAP_query),
('Total', '&award.rfa=ENCODE3' + ROADMAP_query + ENCODE2_query)
])
if args.grant:
columns = collections.OrderedDict([
('ENCODE3-human', ENCODE3_query + human_query + lab_query),
('ENCODE3-mouse', ENCODE3_query + mouse_query + lab_query),
('ENCODE2-human', ENCODE2_query + human_query + lab_query),
('ENCODE2-mouse', ENCODE2_query + mouse_query + lab_query),
# ('Organism Unknown', ENCODE3_query + unknown_org_query),
('ROADMAP', ROADMAP_query + lab_query),
('Total', '&award.rfa=ENCODE3' + \
ROADMAP_query + ENCODE2_query + lab_query)
])
if args.datatype == 'CHIP':
make_chip_report(connection, columns, row_queries)
elif args.datatype == 'RNA':
make_rna_report(connection, columns, row_queries)
elif args.datatype == 'METHYL':
make_methyl_report(connection, columns, row_queries)
elif args.datatype == '3D':
make_3d_report(connection, columns, row_queries)
elif args.datatype == 'Accessibility':
make_dna_report(connection, columns, row_queries)
elif args.datatype == 'RBP':
make_rbp_report(connection, row_queries)
else:
print('unimplemented')
if __name__ == '__main__':
main()