Commit f3b24dd2 authored by Carlos GO's avatar Carlos GO
Browse files

backbone fill

parent 5907ffb9
......@@ -7,6 +7,7 @@ import subprocess
import itertools
import networkx as nx
from Bio.PDB import *
FR3D_SCRIPT = "/home/flask/carnaval.git/Src/FR3D_Minimal"
faces = ['W', 'S', 'H']
......@@ -14,7 +15,7 @@ orientations = ['C', 'T']
VALID_EDGES = set(['B53'] + [orient + "".join(e1 + e2) for e1, e2 in itertools.product(faces, faces) for orient in orientations])
def parse_fr3d(fr3d_path):
def parse_fr3d(fr3d_path, pdb_path):
"""
Parse fr3d annotations and return a graph.
......@@ -24,20 +25,40 @@ def parse_fr3d(fr3d_path):
"""
G = nx.Graph()
nucs = {}
"""
with open(fr3d_path, "r") as fr3d:
for line in fr3d:
base_1, label, base_2 = line.split(",")
chain_1, pos_1, nuc_1 = base_1.split("_")[1:]
chain_2, pos_2, nuc_2 = base_2.split("_")[1:]
label = label.upper().strip()
label = label.upper().strip()[1:-1]
print(label, VALID_EDGES, label in VALID_EDGES)
if label in VALID_EDGES:
print("IN")
label = label[0] + sorted(label[1:])
G.add_edge((chain_1, pos_1), (chain_2, pos_2), label=label)
nucs[(chain_1, pos_1)] = nuc_1
nucs[(chain_2, pos_2)] = nuc_2
nx.set_node_attributes(G, nucs, 'nt')
"""
# use BioPython to fill in the backbones
parser = MMCIFParser(QUIET=True)
struc = parser.get_structure('', pdb_path)[0]
for chain in struc:
reslist = list(chain)
for i,residue in enumerate(reslist):
if i == 0:
continue
r1 = (chain.id, residue.id[1])
r2 = (chain.id, reslist[i-1].id[1])
try:
G[r1]
G[r2]
except:
continue
else:
G.add_edge(r1, r2, label='B53')
return G
def get_fr3d(pdb_path):
......@@ -64,10 +85,12 @@ def get_fr3d(pdb_path):
def get_graph(pdb_path):
fr3d_raw = get_fr3d(pdb_path)
graph = parse_fr3d(fr3d_raw)
# graph = parse_fr3d("", pdb_path)
graph = parse_fr3d(fr3d_raw, pdb_path)
print(graph.edges())
return graph
if __name__ == "__main__":
# get_graph("static/samples/1aju.cif")
get_graph("/home/www/rnabayespairing/static/samples/1aju.cif")
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment