esm_variants / app.py
vasilisNt's picture
Update app.py
16ba247
raw
history blame
1.72 kB
import streamlit as st
import pandas as pd
import numpy as np
from zipfile import ZipFile
import plotly.express as px
import plotly.graph_objs as go
LLR_FILE='./sample gene scores.zip'
def load_LLR(uniprot_id):
'''Loads the LLRs for a given uniprot id. Returns a 20xL dataframe
rows are indexed by AA change,
(AAorder=['K','R','H','E','D','N','Q','T','S','C','G','A','V','L','I','M','P','Y','F','W'])
columns indexed by WT_AA+position e.g, "G 12"
Usage example: load_LLR('P01116') or load_LLR('P01116-2')'''
with ZipFile(LLR_FILE) as myzip:
data = myzip.open(myzip.namelist()[0]+uniprot_id+'_LLR.csv')
return pd.read_csv(data,index_col=0)
def plot_interactive(uniprot_id):
primaryLLR = load_LLR(uniprot_id)
is_dark = output.eval_js('document.documentElement.matches("[theme=dark]")')
template='plotly_dark' if is_dark else 'plotly_white'
fig = px.imshow(primaryLLR.values, x=primaryLLR.columns, y=primaryLLR.index, color_continuous_scale='Viridis_r',zmax=0,
labels=dict(y="Amino acid change", x="Protein sequence", color="LLR"),
template=template,
title='uniprot_id: '+uniprot_id)
fig.update_xaxes(tickangle=-90,range=[0,99],rangeslider=dict(visible=True),dtick=1)
fig.update_yaxes(dtick=1)
fig.update_layout({
'plot_bgcolor': 'rgba(0, 0, 0, 0)',
'paper_bgcolor': 'rgba(0, 0, 0, 0)',
},font={'family':'Arial','size':11},
hoverlabel=dict(font=dict(family='Arial', size=14)))
fig.update_traces(
hovertemplate="<br>".join([
"<b>%{x} %{y}</b>"+
" (%{z:.2f})",
])+'<extra></extra>'
)
return fig
st.plotly_chart(plot_interactive('A0AV02-2'), use_container_width=True)