-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample.py
More file actions
111 lines (95 loc) · 4.24 KB
/
Copy pathexample.py
File metadata and controls
111 lines (95 loc) · 4.24 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
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
105
106
107
108
109
110
111
# example.py
#
# Copyright 2017 Chichau Miau <zmiao@ebi.ac.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
import sys,os
import RNA_normalizer
from operator import attrgetter
RESIDUES_LIST = "data/residues.list"
ATOMS_LIST = "data/atoms.list"
def CleanFormat(f):
os.system( "mac2unix -q %s" %f )
os.system( "dos2unix -q %s" %f )
def normalize_structure(struct, out_file = None, index_file=None, extract_file = None):
pdb_normalizer = RNA_normalizer.PDBNormalizer( RESIDUES_LIST, ATOMS_LIST )
ok = pdb_normalizer.parse( struct, out_file )
if not ok:
sys.stderr.write("ERROR: structure not normalized!\n")
else:
sys.stderr.write("INFO: Normalization succeded!\n")
if not extract_file is None:
coords=open(index_file).read()
extract.extract_PDB(SOLUTION_NORMAL,coords, extract_file)
sys.stderr.write("INFO: structure extracted\n")
# PVALUE set according to Hajdin et al., RNA (7) 16, 2010, either "+" or "-"
def calc_RMSD(native_file, native_index, prediction_file, prediction_index, PVALUE = "-"):
res_struct = RNA_normalizer.PDBStruct()
res_struct.load( native_file, native_index )
res_raw_seq = res_struct.raw_sequence()
sol_struct = RNA_normalizer.PDBStruct()
sol_struct.load( prediction_file, prediction_index )
sol_raw_seq = sol_struct.raw_sequence()
if( sol_raw_seq != res_raw_seq ):
sys.stderr.write("ERROR Result sequence != Solution sequence!\n")
sys.stderr.write("DATA Solution sequence --> '%s'\n" %sol_raw_seq )
sys.stderr.write("DATA Result sequence --> '%s'\n" %res_raw_seq )
return(-1)
# computes the RMSD
comparer = RNA_normalizer.PDBComparer()
rmsd = comparer.rmsd( sol_struct, res_struct )
sys.stderr.write("INFO Partial RMSD --> %f\n" %rmsd )
pvalue = comparer.pvalue( rmsd, len(sol_raw_seq), PVALUE )
sys.stderr.write("INFO Partial P-Value --> %e\n" %pvalue )
return(rmsd, pvalue)
def InteractionNetworkFidelity(native_file, native_index, prediction_file, prediction_index):
res_struct = RNA_normalizer.PDBStruct()
res_struct.load( native_file, native_index )
res_raw_seq = res_struct.raw_sequence()
sol_struct = RNA_normalizer.PDBStruct()
sol_struct.load( prediction_file, prediction_index )
sol_raw_seq = sol_struct.raw_sequence()
if( sol_raw_seq != res_raw_seq ):
sys.stderr.write("ERROR Result sequence != Solution sequence!\n")
sys.stderr.write("DATA Solution sequence --> '%s'\n" %sol_raw_seq )
sys.stderr.write("DATA Result sequence --> '%s'\n" %res_raw_seq )
return(-1)
# computes the RMSD
comparer = RNA_normalizer.PDBComparer()
rmsd = comparer.rmsd( sol_struct, res_struct )
INF_ALL = comparer.INF( sol_struct, res_struct, type="ALL" )
DI_ALL = rmsd / INF_ALL
INF_WC = comparer.INF( sol_struct, res_struct, type="PAIR_2D" )
INF_NWC = comparer.INF( sol_struct, res_struct, type="PAIR_3D" )
INF_STACK = comparer.INF( sol_struct, res_struct, type="STACK" )
return (rmsd,DI_ALL, INF_ALL, INF_WC, INF_NWC,INF_STACK)
if __name__ == '__main__':
# Normalize PDB format, correct residue names and atom names.
normalize_structure('example/14_solution_0.pdb','example/14_solution_normalized.pdb')
# calculate RMSD for RNA structures
# require biopython
print(calc_RMSD("example/14_solution_0.pdb",
"example/14_solution_0.index",
"example/14_ChenPostExp_2.pdb",
"example/14_ChenPostExp_2.index"))
# calculate InteractionNetworkFidelity and Deformation Index for RNA structures
# need to have MA-annotate in the directory or set in mcannotate.py
print(InteractionNetworkFidelity("example/14_solution_0.pdb",
"example/14_solution_0.index",
"example/14_ChenPostExp_2.pdb",
"example/14_ChenPostExp_2.index"))