Commit 6dee8ce2 authored by Carlos GO's avatar Carlos GO
Browse files

data zip fix

parent 53aab673
......@@ -3,6 +3,7 @@ import shutil
import uuid
import pickle
import traceback
import json
import threading
from flask import Flask
......@@ -13,6 +14,8 @@ from flask import redirect
from flask import url_for
import pandas as pd
import networkx as nx
import numpy as np
from werkzeug.utils import secure_filename
......@@ -43,14 +46,29 @@ class BPThreads(threading.Thread):
def run(self):
#130 rna3dmotif graphs.
rnamigos_result = launch(self.pdb_path, self.library)
hits, graph, fp_pred = launch(self.pdb_path, self.library)
rnamigos_result = (-1, traceback.format_exc())
pickle.dump(rnamigos_result, open(f"static/jobs/{self.job_id}/results.pickle", 'wb'))
#write arg dict to csv
df = pd.DataFrame.from_dict(hits)
job_path = os.path.join("static", "jobs", str(self.job_id))
df.to_csv(os.path.join(job_path, "hits.csv"))
data = nx.node_link_data(graph)
with open(os.path.join(job_path, 'graph.json'), 'w') as fp:
json.dump(data, fp)
np.savetxt(os.path.join(job_path, "fingerprint.txt"), fp_pred)
pickle.dump((hits, graph, fp_pred), open(os.path.join(job_path, "results.pickle"), 'wb'))
shutil.make_archive(job_path, 'zip', job_path)
shutil.make_archive(f"static/jobs/{self.job_id}", 'zip', f"static/jobs/{self.job_id}")
except Exception as e:
print("failed dump", e)
if self.sendto:
......@@ -128,7 +146,7 @@ def submitted():
def result_view(job_id=None):
#try to open results
result = pickle.load(open(f"static/jobs/{job_id}/results.pickle", "rb"))
result,_,_ = pickle.load(open(f"static/jobs/{job_id}/results.pickle", "rb"))
except Exception as e:
#if job not done yet print empty template
print("NOT DONE", e)
......@@ -140,7 +158,7 @@ def result_view(job_id=None):
# return f"job {job_id} is done {result}."
print("got results")
results = pickle.load(open(f'static/jobs/{job_id}/results.pickle', 'rb'))
results, _,_ = pickle.load(open(f'static/jobs/{job_id}/results.pickle', 'rb'))
print("rendering results")
......@@ -14,9 +14,9 @@ from rdkit.Chem.Draw import DrawingOptions
from rdkit.Chem import rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
DrawingOptions.bondLineWidth = 3.0
DrawingOptions.bondLineWidth = 1.0
def hash_smiles(smiles):
h = hashlib.blake2b(digest_size=8)
......@@ -65,9 +65,7 @@ def screen(fp_pred, library, n_hits=30):
hits = sorted(lib_dists, key=lambda x:x[1])[:n_hits]
hits_dicts = []
for (sm, fp), d in hits:
print(sm, fp, d)
img_path = os.path.join("static", "mol_drawings", f"{hash_smiles(sm)}.svg")
if not os.path.isfile(img_path):
hits_dicts.append({'smiles': sm, 'dist': d, 'fp': fp, 'smiles_hash': f"{hash_smiles(sm)}"})
......@@ -103,5 +101,4 @@ def index_to_vec(fp, nbits=1024):
if __name__ == "__main__":
lib = smiles_to_library("static/libraries/pdb_rna_smiles.txt")
pickle.dump(lib, open("static/libraries/pdb_rna.p", "wb"))
......@@ -54,17 +54,17 @@ def inference_on_graph(model, graph, edge_map, device='cpu'):
Do inference on one networkx graph.
graph = nx.to_undirected(graph)
graph_nx = graph.to_undirected()
one_hot = {edge: torch.tensor(edge_map[label]) for edge, label in
(nx.get_edge_attributes(graph, 'label')).items()}
(nx.get_edge_attributes(graph_nx, 'label')).items()}
one_hot_nucs = {node: torch.tensor(nuc_map[label], dtype=torch.float32) for node, label in
(nx.get_node_attributes(graph, 'nt')).items()}
(nx.get_node_attributes(graph_nx, 'nt')).items()}
nx.set_edge_attributes(graph, name='one_hot', values=one_hot)
nx.set_node_attributes(graph, name='one_hot', values=one_hot_nucs)
nx.set_edge_attributes(graph_nx, name='one_hot', values=one_hot)
nx.set_node_attributes(graph_nx, name='one_hot', values=one_hot_nucs)
g_dgl = dgl.DGLGraph()
g_dgl.from_networkx(nx_graph=graph, node_attrs=['one_hot'], edge_attrs=['one_hot'])
graph = send_graph_to_device(g_dgl, device)
g_dgl.from_networkx(nx_graph=graph_nx, node_attrs=['one_hot'], edge_attrs=['one_hot'])
graph_ready = send_graph_to_device(g_dgl, device)
return model(graph)
return model(graph_ready)
......@@ -16,6 +16,7 @@ def launch(pdb_path, library_path, n_hits=30, run='rnamigos-ismb'):
if pdb_path is None:
G = nx.read_gpickle(os.path.join("static", "samples", "1aju_arg.nx"))
_,ext = os.path.splittext(pdb_path)
......@@ -45,7 +46,7 @@ def launch(pdb_path, library_path, n_hits=30, run='rnamigos-ismb'):
hits = screen(fp_pred, library, n_hits=n_hits)
print("SCREEN DONE")
return hits
return hits,G, fp_pred
if __name__ == "__main__":
launch("hi", None)
width: 43%;
padding 10px;
padding 100px;
font-family: monospace;
font-family: monospace;
color: #424344;
......@@ -10,14 +10,14 @@ p{
text-align: left;
#svgMain {margin-left:auto; margin-right:auto; display:block; width:40em;}
#svgMain {margin-left:auto; margin-right:auto; display:block; width:50%;}
#query {
text-align: center;
width: 550px;
width: 10em;
......@@ -46,13 +46,10 @@ input{
background-color: red;
border: none;
color: white;
text-align: center;
padding: 20px;
cursor: pointer;
text-decoration: none;
display: block;
font-size: 16px;
margin: 20px auto;
margin: 30px 30px 30px;
-webkit-border-radius: 0px;
......@@ -77,6 +74,10 @@ th{
padding: 8px;
.codeblock {
word-wrap: break-word
pre code {
background-color: #eee;
border: 1px solid #999;
......@@ -84,6 +85,5 @@ pre code {
padding: 20px;
......@@ -113,6 +113,8 @@ When your query completes, we display a list of the 30 most similar ligands to t
You can then download the full list of distances to each element in the library by clicking the 'Download' button.
When you download the results, you will get hits.csv with a list of ligands and their distances to the prediction, graph.json which contains a JSON description of the base pairing network used to make the prediction, fingerprint.txt with is the predicted MACCS fingerprint.
<h1> Source Code </h1>
<a href="">GitLab</a><br>
......@@ -35,7 +35,7 @@ Carlos G. Oliver (cgoliver[at]protonmail(dotcom))<br>
<form action="/submitted" method="POST" form="inp" enctype="multipart/form-data">
<input type="file" id="pdb" name="pdb"><br><br>
<b> Step 2 </b> Upload Ligand Library (optional)<br>
<input type="file" id="library" name="library">
<input type="file" id="library" name="library"><br><br>
<input type="submit" id="query_submit" value="Find Ligands">
......@@ -44,8 +44,7 @@ Carlos G. Oliver (cgoliver[at]protonmail(dotcom))<br>
Augmented base pairing networks encode RNA-small molecule binding preferences<br>
Carlos Oliver, Vincent Mallet, Roman Sarrazin Gendron, Vladimir Reinharz, William L. Hamilton, Nicolas Moitessier, Jerome Waldispuhl<br>
bioRxiv 701326; doi:
bioRxiv 701326; doi: <br><br>
......@@ -24,7 +24,7 @@
<div id="download">
<a href="{{ url_for('static', filename='jobs/{}/results.csv'.format(job_id))}}"
<a href="{{ url_for('static', filename='jobs/{}.zip'.format(job_id))}}"
id="feedback-submit" download> Download Results
......@@ -53,7 +53,7 @@
{{ job_result }} <br>
Email for help.
Email for help.
{% endif %}
......@@ -62,17 +62,20 @@
<b> Open-Source Downloadable Software </b><br>
<a href="" target="_blank" style="text-decoration:none">GitLab</a>,
<a href="{{ url_for('static', filename='bayespairing_docker_image.tar')}}"
style="text-decoration:none" download> Docker Image <br><br>
<b> Source Code </b><br>
<a href="" target="_blank" style="text-decoration:none">GitLab</a><br>
<b> Citation </b><br>
Manuscript available soon.
<div id='codeblock'>
Augmented base pairing networks encode RNA-small molecule binding preferences<br>
Carlos Oliver, Vincent Mallet, Roman Sarrazin Gendron, Vladimir Reinharz, William L. Hamilton, Nicolas Moitessier, Jerome Waldispuhl<br>
bioRxiv 701326; doi:
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