-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_var_npy.py
76 lines (57 loc) · 2.12 KB
/
build_var_npy.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
#!/usr/bin/env python3
"""Imputation challenge scoring script
Author:
Jin Lee ([email protected])
"""
import numpy
import pyBigWig
from score_metrics import normalize_dict
from bw_to_npy import write_dict_to_npy, load_npy
from logger import log
def build_var_dict(npys, chroms):
y_all = {}
for c in chroms:
y_all[c] = []
for f in npys:
y_dict = load_npy(f)
y_dict_norm = normalize_dict(y_dict, chroms)
for c in chroms:
y_all[c].append(y_dict_norm[c])
var = {}
for c in chroms:
var[c] = numpy.std(numpy.array(y_all[c]), axis=0) ** 2
return var
def parse_arguments():
import argparse
parser = argparse.ArgumentParser(
description='ENCODE Imputation Challenge variance .npy builder')
parser.add_argument('npy', nargs='+',
help='Binned truth .npy file')
parser.add_argument('--out-npy-prefix', required=True,
help='Output prefix for .npy or .npz')
p_score = parser.add_argument_group(
title='Scoring parameters')
p_score.add_argument('--chrom', nargs='+',
default=['all'],
help='List of chromosomes to be combined to be '
'scored. '
'Set as "all" (default) to score for all '
'chromosomes. '
'(e.g. "all" or "chr3 chr21") '
'It should be "all" to write scores to DB file')
p_score.add_argument('--window-size', default=25, type=int,
help='Window size for bigwig in bp')
args = parser.parse_args()
# some submission files have whitespace in path...
for i, f in enumerate(args.npy):
args.npy[i] = f.strip("'")
if args.chrom == ['all']:
args.chrom = ['chr' + str(i) for i in range(1, 23)] + ['chrX']
return args
def main():
args = parse_arguments()
var = build_var_dict(args.npy, args.chrom)
write_dict_to_npy(var, args.out_npy_prefix)
log.info('All done')
if __name__ == '__main__':
main()