-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcontacts_to_distograms.py
49 lines (39 loc) · 1.41 KB
/
contacts_to_distograms.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
import numpy as np
from argparse import ArgumentParser
def parse_arguments():
parser = ArgumentParser(description='Generate distograms for binary contacts')
parser.add_argument('--csv',
help='CSV with contacts: i j FDR',
required=True)
parser.add_argument('--cutoff',
help='cutoff in A',
required=False,
default=10,
type=float)
parser.add_argument('--output',
help='Output CSV with distogram restraints',
required=True)
args = parser.parse_args()
return args
distogram_bins = np.arange(2.3125,42,0.3125)
def get_uniform(cutoff, fdr):
d = np.ones(128)
maximum_bin = np.argmax(distogram_bins > cutoff)
d[:maximum_bin] /= np.sum(d[:maximum_bin])
d[:maximum_bin] *= 1 - fdr
d[maximum_bin:] /= np.sum(d[maximum_bin:])
d[maximum_bin:] *= fdr
return d
def main():
args = parse_arguments()
contacts = np.loadtxt(args.csv)
if contacts.size <= 1:
contacts = np.array([contacts])
with open(args.output, 'w') as f:
for i,j,fdr in contacts:
line = [i,j]
distogram = get_uniform(args.cutoff, fdr)
line += list(distogram)
f.write(' '.join([str(e) for e in line]) + '\n')
if __name__ == "__main__":
main()