forked from LBME/slider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGivenDubiousResolvedResiduesReturnSequenceVariability.py
executable file
·78 lines (68 loc) · 2.37 KB
/
GivenDubiousResolvedResiduesReturnSequenceVariability.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 20 September 2021
# Author : Rafael Borges
# Objective: Given Dubious and Resolved log files from SLIDER_VENOM with residues and their RSCC,
# return variability of sequences
# USAGE: GivenDubiousResolvedResiduesReturnSequenceVariability.py Dubious.log Resolved.log OutputFile
# OutputFile should be a new path
# RETURNS: a file with amino acid possibilities (line) by residue number (column)
from __future__ import print_function
import sys,os #,time
inputDub = sys.argv[1]
inputRes = sys.argv[2]
outfile = sys.argv[3]
with open (inputDub) as f: frDub=f.readlines()
with open (inputRes) as f: frRes=f.readlines()
dicall={}
vrscc1=0.0
for l in frDub[1:]:
l=l.split()
if len(l)>1:
if l[2]!='MainCh':
#print(l)
# try:
ch=l[0]
resn=int(l[1])
restype=l[2][0]
vrscc2=float(l[3])
#print (vrscc1,vrscc2)
if ch not in dicall: dicall[ch]={}
if resn not in dicall[ch]: dicall[ch][resn]=[]
if vrscc1<vrscc2: vrscc1=float(vrscc2)
if restype not in dicall[ch][resn] and vrscc1-vrscc2<3.0:
dicall[ch][resn].append(restype)
#print (dicall[ch])
#time.sleep(1)
# except:
# pass
# exit()
else: vrscc1=0.0
for l in frRes[1:]:
l=l.split()
if len(l)>1:
#print(l, l[1])
ch=l[0]
resn=int(l[1])
restype=l[2][0]
if ch not in dicall: dicall[ch] = {}
if resn not in dicall[ch]: dicall[ch][resn] = []
if restype not in dicall[ch][resn]: dicall[ch][resn].append(restype)
if len(dicall)>1:
dicall['all']={}
for ch in dicall:
for resn in dicall[ch]:
if resn not in dicall['all']: dicall['all'][resn]=[]
for restype in dicall[ch][resn]:
if restype not in dicall['all'][resn]: dicall['all'][resn].append(restype)
with open(outfile,'w') as fo:
for ch in dicall:
if len(dicall)>1: fo.write('>'+ch+'\n')
variabN=0
for resn in dicall[ch]:
if len(dicall[ch][resn])>variabN: variabN=len(dicall[ch][resn])
for i in range(variabN):
for resn in sorted(dicall[ch]):
try: fo.write(dicall[ch][resn][i])
except: fo.write(' ')
fo.write('\n')