Julietanku's picture
Update app.py
a3b045d verified
import datasets
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode
st.set_page_config(layout='wide')
# parse out gene_ids from URL query args to it's possible to link to this page
query_params = st.query_params
if "gene_id" in query_params.keys():
gene_id = query_params["gene_id"]
else:
gene_id = "B9J08_001120"
st.markdown("""
# Druggable Candida auris Genome
**DrAG** is a database of candidate compounds for targeting Candida auris, the emerging fungal pathogen
For each C. auris gene we have a number of compound linked in ChEMBL and IUPHAR.
* Full network and dataset: https://huggingface.co/datasets/julietanku/DrAG
## Look up compounds for a C.auris gene:
Put in the ``B9J08_######`` gene_id for a gene and expand the table to get the predicted compounds""")
DrAG_hits_ChEMBL = datasets.load_dataset(
path = "julietanku/DrAG",
data_files = {"DrAG_hits_ChEMBL": "cau_targets_to_chembl_cpds_20240131.parquet"})
DrAG_hits_ChEMBL = DrAG_hits_ChEMBL["DrAG_hits_ChEMBL"].to_pandas()
DrAG_hits_IUPHAR = datasets.load_dataset(
path = "julietanku/DrAG",
data_files = {"DrAG_hits_IUPHAR": "Cau_vs_IUPHAR_cpds_imp.parquet"})
DrAG_hits_IUPHAR = DrAG_hits_IUPHAR["DrAG_hits_IUPHAR"].to_pandas()
col1, col2, col3 = st.columns(spec = [0.3, 0.2, 0.5])
with col1:
gene_ids= st.text_area(
label = "Gene IDs",
value = f"{gene_id}",
max_chars = None,
height = None,
help = "B9J08 Gene ID e.g. B9J08_004214, B9J08_001120")
gene_ids= gene_ids.split("\n")
gene_ids=[gene_id.strip() for gene_id in gene_ids] ### Striping the blank space/character in the query box before searching###
###radio buttons###
with col2:
database_name=st.radio(
label='select the database to search',
options=['ChEMBL','IUPHAR'],
captions=['ChEMBL drug list','IUPHAR drug list'] )
if database_name=="ChEMBL":
DrAG_hits = DrAG_hits_ChEMBL[DrAG_hits_ChEMBL['feature_name'].isin(gene_ids)]
elif database_name=="IUPHAR":
DrAG_hits = DrAG_hits_IUPHAR[DrAG_hits_IUPHAR['feature_name_1.y'].isin(gene_ids)]
else:
raise Exception('Database was not recognised')
DrAG_hits.reset_index()
with col3:
st.text('') # help alignment with input box
st.download_button(
label = "Download data as TSV",
data = DrAG_hits.to_csv(sep ='\t').encode('utf-8'),
file_name = f"DrAG_hits_{gene_id}.tsv",
mime = "text/csv")
# third column is padding only
######### Table #########
CGD_link_renderer = JsCode("""
class UrlCellRenderer {
init(params) {
this.eGui = document.createElement('a');
this.eGui.innerText = params.value;
this.eGui.setAttribute('href', "http://candidagenome.org/cgi-bin/locus.pl?locus="+params.value);
this.eGui.setAttribute('style', "text-decoration:none");
this.eGui.setAttribute('target', "_blank");
}
getGui() {
return this.eGui;
}
}
""")
ChEMBL_link_renderer = JsCode("""
class UrlCellRenderer {
init(params) {
this.eGui = document.createElement('a');
this.eGui.innerText = params.value;
this.eGui.setAttribute('href', "http://ebi.ac.uk/chembl/compound_report_card/"+params.value);
this.eGui.setAttribute('style', "text-decoration:none");
this.eGui.setAttribute('target', "_blank");
}
getGui() {
return this.eGui;
}
}
""")
IUPHAR_link_renderer = JsCode("""
class UrlCellRenderer {
init(params) {
this.eGui = document.createElement('a');
this.eGui.innerText = params.value;
this.eGui.setAttribute('href', "https://www.guidetopharmacology.org/GRAC/LigandDisplayForward?ligandId="+params.value);
this.eGui.setAttribute('style', "text-decoration:none");
this.eGui.setAttribute('target', "_blank");
}
getGui() {
return this.eGui;
}
}
""")
if database_name=="ChEMBL":
grid_option_builder = GridOptionsBuilder()
grid_option_builder.configure_auto_height()
grid_option_builder.configure_default_column(
filterable=False,
groupable=False,
editable=False,
wrapText=True,
autoHeight=True)
grid_option_builder.configure_column("feature_name", header_name="feature_name", pinned="left", cellRenderer=CGD_link_renderer, width=550)
grid_option_builder.configure_column("sac_ortholog", header_name="sac_ortholog", pinned="left", width=500)
grid_option_builder.configure_column("description", header_name="description", width=1650)
grid_option_builder.configure_column("uniprot_accn", header_name="uniprot_accn", width=500)
grid_option_builder.configure_column("EValue", header_name="EValue", pinned="left", width=500)
grid_option_builder.configure_column("chembl_id", header_name="chembl_id", pinned="left", cellRenderer=ChEMBL_link_renderer, width=550)
grid_option_builder.configure_selection(selection_mode=False, use_checkbox=False)
elif database_name=="IUPHAR":
grid_option_builder = GridOptionsBuilder()
grid_option_builder.configure_auto_height()
grid_option_builder.configure_default_column(
filterable=False,
groupable=False,
editable=False,
wrapText=True,
autoHeight=True)
grid_option_builder.configure_column("feature_name", header_name="feature_name_1.y", pinned="left", cellRenderer=CGD_link_renderer, width=550)
grid_option_builder.configure_column("Ligand", header_name="Compound", pinned="left", width=500)
grid_option_builder.configure_column("Ligand ID", header_name="Compound ID", cellRenderer=IUPHAR_link_renderer, width=550)
grid_option_builder.configure_column("Target UniProt ID", header_name="uniprot_accn", width=500)
grid_option_builder.configure_column("EValue.y", header_name="EValue", pinned="left", width=500)
grid_option_builder.configure_column("SMILES", header_name="Compound SMILES", pinned="left", width=1650)
grid_option_builder.configure_selection(selection_mode=False, use_checkbox=False)
else:
raise Exception('Database was not recognised')
AgGrid(
data = DrAG_hits,
gridOptions = grid_option_builder.build(),
fit_columns_on_grid_load=True,
theme="streamlit",
allow_unsafe_jscode=True)