-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContact_score_analysis_old.py
More file actions
60 lines (44 loc) · 1.81 KB
/
Contact_score_analysis_old.py
File metadata and controls
60 lines (44 loc) · 1.81 KB
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
import os
import glob
import time
files = glob.glob("*.txt")
list_aa = ['ala ','ARG ','ALA ','arg ','ARG ','asn ', 'ASN ','asp ', 'ASP ','glu ', 'GLU ','gln ', 'GLN ','his ', 'HIS ','leu ', 'LEU ','met ', 'MET ','phe ', 'PHE ','pro ', 'PRO ','ser ', 'SER ','thr ', 'THR ','trp ', 'TRP ','tyr ', 'TYR ','val ', 'VAL ', 'LYS ', 'lys ', 'CYS ', 'cys ', 'ILE ','ile ']
list_1 = []
for file in files:
file_open = open(file,"r")
file_read = file_open.read()
n = 0
while n+1 < len(file_read):
residue_file = file_read[n-2] + file_read[n-1] + file_read[n] + file_read[n+1]
if residue_file in list_aa:
if file_read[n+4] != " " and file_read[n+3]!= " ":
list_1.append(file_read[n-2] + file_read[n-1] + file_read[n]+ file_read[n+1] + file_read[n+2] + file_read[n+3] + file_read[n+4])
elif file_read[n+4] == " ":
list_1.append(file_read[n-2] + file_read[n-1] + file_read[n]+ file_read[n+1] + file_read[n+2] + file_read[n+3])
elif file_read[n+3] == " ":
list_1.append(file_read[n-2] + file_read[n-1] + file_read[n]+ file_read[n+1] + file_read[n+2])
n += 1
list_2 = []
for elements in list_1:
if elements not in list_2:
list_2.append(elements)
print (list_2)
for elements in list_2:
os.system('grep "' + elements + '" ' + " * > " + elements[:3] + "_" + elements[4:] + ".out")
files = glob.glob("*.out")
combined_file = open("combined_file.txt","w")
for file in files:
open_file = open(file,"r")
read_file = open_file.read()
split_file = read_file.split('\n')
write_file = open(file,"a")
list_1 = []
for lines in split_file:
if lines != "":
inverse = 1 / float(lines[-5:])
list_1.append(inverse)
sum = 0
for elements in list_1:
sum = sum + elements
write_file.write(str(sum))
combined_file.write(file[:-4]+ " = " + str(sum) + "\n")