File size: 18,480 Bytes
89f9a8d f02c033 72f9629 89f9a8d 490595c 89f9a8d c0e52ad 89f9a8d afba6b8 d5d696e fc729c7 d5d696e fc729c7 b318bc6 bc3d031 372f84d bc3d031 afba6b8 501c3b1 afba6b8 bc3d031 40cf9b4 2f247b2 7f14dcf 63ce71b 490595c 63ce71b 1753f35 63ce71b ef4a36f 40cf9b4 ef4a36f 65c318c 818c6db 65c318c ef4a36f 818c6db ef4a36f 65c318c 499faaf 65c318c 499faaf b318bc6 65c318c 499faaf 2f247b2 b318bc6 499faaf 2f247b2 b318bc6 40cf9b4 ef4a36f 65c318c 9574464 ef4a36f 4f1ea03 b318bc6 65c318c ef4a36f 9574464 65c318c b318bc6 499faaf b318bc6 65c318c b318bc6 65c318c b318bc6 65c318c b318bc6 65c318c 499faaf 2f247b2 9574464 b318bc6 499faaf 2f247b2 b318bc6 2abf58c 9574464 499faaf 601b6c8 1753f35 490595c 63ce71b 9e6028d 601b6c8 63ce71b 9e6028d b318bc6 f02c033 71914fa f02c033 601b6c8 4f1ea03 b318bc6 601b6c8 4f1ea03 601b6c8 4f1ea03 499faaf 4f1ea03 3c1ebe4 4f1ea03 f02c033 7f14dcf 490595c f398b03 601b6c8 63ce71b 2f637fc 4f1ea03 daeb1af 8d25d5d daeb1af 8d25d5d daeb1af 39315d2 1753f35 daeb1af 1753f35 7f14dcf fc729c7 7f14dcf 2f247b2 7f14dcf 1753f35 7a60b00 7f14dcf daeb1af bc3d031 63ce71b 490595c 63ce71b 1182013 63ce71b bc3d031 40cf9b4 1c4e31a 2f637fc 1c4e31a bc3d031 5b730e0 bc3d031 |
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
import os
import sys
#import torch
import numpy as np
import pandas as pd
import streamlit as st
#import esm
from rdkit import Chem
from rdkit.Chem import Draw
sys.path.insert(0, os.path.abspath("src/"))
st.set_page_config(layout="wide")
basepath = os.path.dirname(__file__)
datapath = os.path.join(basepath, "data")
st.title('HyperDTI: Task-conditioned modeling of drug-target interactions.\n')
st.markdown('')
st.markdown(
"""
🧬 Github: [ml-jku/hyper-dti](https://https://github.com/ml-jku/hyper-dti) 📝 NeurIPS 2022 AI4Science workshop paper: [OpenReview](https://openreview.net/forum?id=dIX34JWnIAL)\n
"""
)
st.error('WARNING! This app is currently under development and should not be used!')
def about_page():
st.markdown(
"""
### About
HyperNetworks have been established as an effective technique to achieve fast adaptation of parameters for
neural networks. Recently, HyperNetwork predictions conditioned on descriptors of tasks have improved
multi-task generalization in various domains, such as personalized federated learning and neural architecture
search. Especially powerful results were achieved in few- and zero-shot settings, attributed to the increased
information sharing by the HyperNetwork. With the rise of new diseases fast discovery of drugs is needed which
requires models that are able to generalize drug-target interaction predictions in low-data scenarios.
In this work, we propose the HyperPCM model, a task-conditioned HyperNetwork approach for the problem of
predicting drug-target interactions in drug discovery. Our model learns to generate a QSAR model specialized on
a given protein target. We demonstrate state-of-the-art performance over previous methods on multiple
well-known benchmarks, particularly in zero-shot settings for unseen protein targets.
"""
)
st.image('figures/hyper-dti.png', caption='Overview of HyperPCM architecture.')
'''
def predict_dti():
st.markdown('## Predict drug-target interaction')
st.write('In the future this page can be used to predict interactions betweek a query drug compound and a query protein target by the HyperPCM mdoel.')
col1, col2 = st.columns(2)
with col1:
st.markdown('### Drug')
mol_col1, mol_col2 = st.columns(2)
with mol_col1:
smiles = st.text_input('Enter query SMILES', value='CC(=O)OC1=CC=CC=C1C(=O)O', placeholder='CC(=O)OC1=CC=CC=C1C(=O)O')
if smiles:
mol = Chem.MolFromSmiles(smiles)
mol_img = Chem.Draw.MolToImage(mol)
st.image(mol_img) #, width = 140)
with mol_col2:
selected_encoder = st.selectbox(
'Select encoder',('None', 'CDDD', 'MolBERT', 'Dummy')
)
if smiles:
if selected_encoder == 'CDDD':
from cddd.inference import InferenceModel
CDDD_MODEL_DIR = 'src/encoders/cddd'
cddd_model = InferenceModel(CDDD_MODEL_DIR)
drug_embedding = cddd_model.seq_to_emb([smiles])
#from huggingface_hub import hf_hub_download
#precomputed_embs = f'{selected_encoder}_encoding.csv'
#REPO_ID = "emmas96/Lenselink"
#embs_path = hf_hub_download(REPO_ID, precomputed_embs)
#embs = pd.read_csv(embs_path)
#embedding = embs[smiles]
elif selected_encoder == 'MolBERT':
from molbert.utils.featurizer.molbert_featurizer import MolBertFeaturizer
from huggingface_hub import hf_hub_download
CDDD_MODEL_DIR = 'encoders/molbert/last.ckpt'
REPO_ID = "emmas96/hyperpcm"
checkpoint_path = hf_hub_download(REPO_ID, MOLBERT_MODEL_DIR)
molbert_model = MolBertFeaturizer(checkpoint_path, max_seq_len=500, embedding_type='average-1-cat-pooled')
drug_embedding = molbert_model.transform([smiles])
elif selected_encoder == 'Dummy':
drug_embedding = [0,1,2,3,4,5]
else:
drug_embedding = None
st.image('figures/molecule_encoder.png')
st.warning('Choose encoder above...')
if drug_embedding is not None:
st.image('figures/molecule_encoder_done.png')
st.success('Encoding complete.')
with col2:
st.markdown('### Target')
prot_col1, prot_col2 = st.columns(2)
with prot_col1:
sequence = st.text_input('Enter query amino-acid sequence', value='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA', placeholder='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA')
if sequence == 'HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA':
st.image('figures/ex_protein.jpeg')
elif sequence:
st.error('Visualization comming soon...')
with prot_col2:
selected_encoder = st.selectbox(
'Select encoder for protein target',('None', 'SeqVec', 'UniRep', 'ESM-1b', 'ProtT5')
)
if sequence:
if selected_encoder == 'SeqVec':
with st.spinner('Encoding in progress...'):
from bio_embeddings.embed import SeqVecEmbedder
encoder = SeqVecEmbedder()
embeddings = encoder.embed_batch([sequence])
for emb in embeddings:
prot_embedding = encoder.reduce_per_protein(emb)
break
elif selected_encoder == 'UniRep':
with st.spinner('Encoding in progress...'):
from jax_unirep.utils import load_params
params = load_params()
from jax_unirep.featurize import get_reps
embedding, h_final, c_final = get_reps([sequence])
prot_embedding = embedding.mean(axis=0)
elif selected_encoder == 'ESM-1b':
with st.spinner('Encoding in progress...'):
from bio_embeddings.embed import ESM1bEmbedder
encoder = ESM1bEmbedder()
embeddings = encoder.embed_batch([sequence])
for emb in embeddings:
prot_embedding = encoder.reduce_per_protein(emb)
break
elif selected_encoder == 'ProtT5':
with st.spinner('Encoding in progress...'):
from bio_embeddings.embed import ProtTransT5XLU50Embedder
encoder = ProtTransT5XLU50Embedder()
embeddings = encoder.embed_batch([sequence])
for emb in embeddings:
prot_embedding = encoder.reduce_per_protein(emb)
break
else:
prot_embedding = None
st.image('figures/protein_encoder.png')
st.warning('Choose encoder above...')
if prot_embedding is not None:
st.image('figures/protein_encoder_done.png')
st.success('Encoding complete.')
if drug_embedding is None or prot_embedding is None:
st.warning('Waiting for both drug and target embeddings to be computed...')
else:
st.markdown('### Inference')
import time
progress_text = "HyperPCM predicts the interaction between the query drug compound toward the query protein target. Please wait."
my_bar = st.progress(0, text=progress_text)
for i in range(100):
time.sleep(0.1)
my_bar.progress(i + 1, text=progress_text)
my_bar.progress(100, text="HyperPCM predicts the interaction between the query drug compound toward the query protein target. Done.")
st.markdown('### Interaction')
st.write('HyperPCM predicts an activity of xxx pChEMBL.')
'''
def retrieval():
st.markdown('## Retrieve top-k most active drug compounds')
st.write('In the furute this page will retrieve the top-k drug compounds that are predicted to have the highest activity toward the given protein target from either the Lenselink or Davis datasets.')
st.markdown('### Target')
st.write(f'The top-{selected_k} most active drug coupounds from {selected_dataset} predicted by HyperPCM are: ')
dummy_smiles = ['CC(=O)OC1=CC=CC=C1C(=O)O', 'COc1cc(C=O)ccc1O', 'CC(=O)Nc1ccc(O)cc1', 'CC(=O)Nc1ccc(OS(=O)(=O)O)cc1', 'CC(=O)Nc1ccc(O[C@@H]2O[C@H](C(=O)O)[C@@H](O)[C@H](O)[C@H]2O)cc1']
cols = st.columns(5)
for j, col in enumerate(cols):
with col:
for i in range(int(selected_k/5)):
mol = Chem.MolFromSmiles(dummy_smiles[j])
mol_img = Chem.Draw.MolToImage(mol)
st.image(mol_img)
'''
col1, col2, col3, col4 = st.columns(4)
with col2:
sequence = st.text_input('Enter query amino-acid sequence', value='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA', placeholder='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA')
if sequence == 'HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA':
st.image('figures/ex_protein.jpeg')
elif sequence:
st.error('Visualization coming soon...')
with col3:
selected_encoder = st.selectbox(
'Select encoder for protein target',('SeqVec', 'None')
)
if sequence:
if selected_encoder == 'SeqVec':
st.image('figures/protein_encoder_done.png')
with st.spinner('Encoding in progress...'):
from bio_embeddings.embed import SeqVecEmbedder
encoder = SeqVecEmbedder()
embeddings = encoder.embed_batch([sequence])
for emb in embeddings:
prot_embedding = encoder.reduce_per_protein(emb)
break
st.success('Encoding complete.')
else:
prot_embedding = None
st.image('figures/protein_encoder.png')
st.warning('Choose encoder above...')
if prot_embedding is not None:
st.markdown('### Inference')
import time
progress_text = "HyperPCM predicts the QSAR model for the query protein target. Please wait."
my_bar = st.progress(0, text=progress_text)
for i in range(100):
time.sleep(0.1)
my_bar.progress(i + 1, text=progress_text)
my_bar.progress(100, text="HyperPCM predicts the QSAR model for the query protein target. Done.")
st.markdown('### Retrieval')
col1, col2 = st.columns(2)
with col1:
selected_dataset = st.selectbox(
'Select dataset from which the drug compounds should be retrieved',('Lenselink', 'Davis')
)
with col2:
selected_k = st.selectbox(
'Select the top-k number of drug compounds to retrieve',(5, 10, 15, 20)
)
st.write(f'The top-{selected_k} most active drug coupounds from {selected_dataset} predicted by HyperPCM are: ')
dummy_smiles = ['CC(=O)OC1=CC=CC=C1C(=O)O', 'COc1cc(C=O)ccc1O', 'CC(=O)Nc1ccc(O)cc1', 'CC(=O)Nc1ccc(OS(=O)(=O)O)cc1', 'CC(=O)Nc1ccc(O[C@@H]2O[C@H](C(=O)O)[C@@H](O)[C@H](O)[C@H]2O)cc1']
cols = st.columns(5)
for j, col in enumerate(cols):
with col:
for i in range(int(selected_k/5)):
mol = Chem.MolFromSmiles(dummy_smiles[j])
mol_img = Chem.Draw.MolToImage(mol)
st.image(mol_img)
'''
'''
def display_protein():
st.markdown('## Display protein structure')
st.write('In the future this page will display the ESM predicted sequence of a protein target.')
st.markdown('### Target')
sequence = st.text_input('Enter the amino-acid sequence of the query protein target', value='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA', placeholder='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA')
if sequence:
st.image('figures/ex_protein.jpeg')
model = esm.pretrained.esmfold_v1()
model = model.eval().cuda()
with torch.no_grad():
output = model.infer_pdb(sequence)
st.write(output)
with open("result.pdb", "w") as f:
f.write(output)
struct = bsio.load_structure("result.pdb", extra_fields=["b_factor"])
print(struct.b_factor.mean())
"""
model, alphabet = esm.pretrained.esm2_t33_650M_UR50D()
batch_converter = alphabet.get_batch_converter()
batch_labels, batch_strs, batch_tokens = batch_converter([("protein1", sequence),])
# Extract per-residue representations (on CPU)
with torch.no_grad():
results = model(batch_tokens, repr_layers=[12], return_contacts=True)
token_representations = results["representations"][12]
token_list = token_representations.tolist()[0][0][0]
client = Client(url=st.secrets["DB_URL"], user=st.secrets["USER"], password=st.secrets["PASSWD"])
result = client.fetch("SELECT seq, distance('topK=500')(representations, " + str(token_list) + ')'+ "as dist FROM default.esm_protein_indexer_768")
result_temp_seq = []
for i in result:
# result_temp_coords = i['seq']
result_temp_seq.append(i['seq'])
result_temp_seq = list(set(result_temp_seq))
if st.button(result_temp_seq[0]):
print(result_temp_seq[0])
elif st.button(result_temp_seq[1]):
print(result_temp_seq[1])
elif st.button(result_temp_seq[2]):
print(result_temp_seq[2])
elif st.button(result_temp_seq[3]):
print(result_temp_seq[3])
elif st.button(result_temp_seq[4]):
print(result_temp_seq[4])
start[2] = st.pyplot(visualize_3D_Coordinates(result_temp_coords).figure)
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post('https://api.esmatlas.com/foldSequence/v1/pdb/', headers=headers, data=sequence)
name = sequence[:3] + sequence[-3:]
pdb_string = response.content.decode('utf-8')
with open('predicted.pdb', 'w') as f:
f.write(pdb_string)
struct = bsio.load_structure('predicted.pdb', extra_fields=["b_factor"])
b_value = round(struct.b_factor.mean(), 4)
render_mol(pdb_string)
if residues_marker:
start[3] = showmol(render_pdb_resn(viewer = render_pdb(id = id_PDB),resn_lst = [residues_marker]))
else:
start[3] = showmol(render_pdb(id = id_PDB))
st.session_state['xq'] = st.session_state.model
# example proteins ["HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA"], ["AHKLFIGGLPNYLNDDQVKELLTSFGPLKAFNLVKDSATGLSKGYAFCEYVDINVTDQAIAGLNGMQLGDKKLLVQRASVGAKNA"]
"""
def display_context():
st.markdown('## Display context')
st.write('In the future this page will visualize the context module for a given protein, i.e., show important features and highly ranked / related proteins from the context.')
'''
def references():
st.markdown(
'''
## References
Schmidhuber, J., “Learning to control fast-weight memories: An alternative to dynamic recurrent networks.” Neural Computation, 1992.
Davis, M. I., et al. "Comprehensive analysis of kinase inhibitor selectivity." Nature Biotechnology 29.11 (2011): 1046-1051.
Ha, D., et al. “HyperNetworks”. ICLR, 2017.
Lenselink, E. B., et al. "Beyond the hype: deep neural networks outperform established methods using a ChEMBL bioactivity benchmark set." Journal of Cheminformatics 9.1 (2017): 1-14.
Alley, E. C., et al. "Unified rational protein engineering with sequence-based deep representation learning." Nature Methods 16.12 (2019): 1315-1322.
Chang, O., et al., “Principled weight initialization for hypernetworks.” ICLR, 2019.
Heinzinger, M., et al. "Modeling aspects of the language of life through transfer-learning protein sequences." BMC Bioinformatics 20.1 (2019): 1-17.
Winter, R., et al. "Learning continuous and data-driven molecular descriptors by translating equivalent chemical representations." Chemical Science 10.6 (2019): 1692-1701.
Fabian, B., et al. "Molecular representation learning with language models and domain-relevant auxiliary tasks." Workshop for ML4Molecules (2020).
Elnaggar, A., et al. "ProtTrans: Toward understanding the language of life through self-supervised learning." IEEE Transactions on Pattern Analysis and Machine Intelligence 44 (2021): 7112–7127.
Rives, A., et al. "Biological structure and function emerge from scaling unsupervised learning to 250 million protein sequences." Proceedings of the National Academy of Sciences 118.15 (2021): e2016239118.
Kim, P. T., et al. "Unsupervised Representation Learning for Proteochemometric Modeling." International Journal of Molecular Sciences 22.23 (2021): 12882.
Schimunek, J., et al., “Context-enriched molecule representations improve few-shot drug discovery.” ICLR, 2023.
'''
)
page_names_to_func = {
'About': about_page,
#'Predict DTI': predict_dti,
'Retrieve Top-k': retrieval,
#'Display Protein': display_protein,
#'Display Context': display_context,
#'References': references
}
selected_page = st.sidebar.selectbox('Choose function', page_names_to_func.keys())
st.sidebar.markdown('')
page_names_to_func[selected_page]()
|