-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmp2rr.py
104 lines (86 loc) · 2.92 KB
/
dmp2rr.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
#!/usr/bin/python
################################################################################################################################
# this program generates distance-based input (rr) file from distance map histogram (rawdistpred.current) generated by DMPfold #
################################################################################################################################
import operator
import os
import math
import sys
import optparse # for option sorting
import random
from decimal import *
getcontext().prec = 4
parser = optparse.OptionParser()
parser.add_option('-d', dest='dist',
default = '', # default empty
help = 'name of raw distance map (DMPfold distogram)')
parser.add_option('-a', dest='fasta',
default = '', # default empty
help = 'name of fasta file')
parser.add_option('-r', dest='rr',
default = 'out', # default out
help = 'name of output contact map')
(options,args) = parser.parse_args()
dist = options.dist
fasta = options.fasta
rr = options.rr
try:
ffasta = open(fasta, 'r')
flines = ffasta.readlines()
except IOError:
sys.exit()
print ('skipping..')
frr = open(rr, 'w')
frr.write(flines[1].strip())
frr.write('\n')
try:
f = open(dist, 'r')
lines = f.readlines()
rrList = []
for line in lines:
line = line.split()
try:
res1 = int(line[0])
res2 = int(line[1])
except ValueError:
print ('value error..')
continue
count = 0
for i in range(2, 14):
th = i
count += (float(line[i])) #Decimal(float(line[i]))
if (count >= 0.85):
break
if (th <= 9):
th = 8
elif (th > 9 and th <= 11):
th = 10
elif (th > 11 and th <= 13):
th = 12
if (count < 0.0001):
count = 0.0001
rrList.append([str(res1), str(res2), str(th), str(count)])
f.close()
dict1 = {}
for x in rrList:
dict1[(x[0], x[1], x[2])] = x[3]
sorted_rr = sorted(dict1.items(), key=operator.itemgetter(1))
sorted_rr.reverse()
count = 0
for sr in sorted_rr:
(i, j, th), p = sr[0], sr[1]
frr.write(str(i))
frr.write(' ')
frr.write(str(j))
frr.write(' ')
frr.write('0')
frr.write(' ')
frr.write(th)
frr.write(' ')
frr.write(str(p))
frr.write('\n')
count += 1
except IOError:
print ('skippig..')
ffasta.close()
frr.close()