vasilisNt commited on
Commit
985a7dc
1 Parent(s): 022fa9d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ import pandas as pd
4
+ import numpy as np
5
+ from zipfile import ZipFile
6
+
7
+ import plotly.express as px
8
+ import plotly.graph_objs as go
9
+
10
+ LLR_FILE='/content/sample gene scores.zip'
11
+
12
+ def load_LLR(uniprot_id):
13
+ '''Loads the LLRs for a given uniprot id. Returns a 20xL dataframe
14
+ rows are indexed by AA change,
15
+ (AAorder=['K','R','H','E','D','N','Q','T','S','C','G','A','V','L','I','M','P','Y','F','W'])
16
+ columns indexed by WT_AA+position e.g, "G 12"
17
+ Usage example: load_LLR('P01116') or load_LLR('P01116-2')'''
18
+ with ZipFile(LLR_FILE) as myzip:
19
+ data = myzip.open(myzip.namelist()[0]+uniprot_id+'_LLR.csv')
20
+ return pd.read_csv(data,index_col=0)
21
+
22
+
23
+ def plot_interactive(uniprot_id):
24
+ primaryLLR = load_LLR(uniprot_id)
25
+ is_dark = output.eval_js('document.documentElement.matches("[theme=dark]")')
26
+ template='plotly_dark' if is_dark else 'plotly_white'
27
+
28
+ fig = px.imshow(primaryLLR.values, x=primaryLLR.columns, y=primaryLLR.index, color_continuous_scale='Viridis_r',zmax=0,
29
+ labels=dict(y="Amino acid change", x="Protein sequence", color="LLR"),
30
+ template=template,
31
+ title='uniprot_id: '+uniprot_id)
32
+ fig.update_xaxes(tickangle=-90,range=[0,99],rangeslider=dict(visible=True),dtick=1)
33
+ fig.update_yaxes(dtick=1)
34
+ fig.update_layout({
35
+ 'plot_bgcolor': 'rgba(0, 0, 0, 0)',
36
+ 'paper_bgcolor': 'rgba(0, 0, 0, 0)',
37
+ },font={'family':'Arial','size':11},
38
+ hoverlabel=dict(font=dict(family='Arial', size=14)))
39
+
40
+ fig.update_traces(
41
+ hovertemplate="<br>".join([
42
+ "<b>%{x} %{y}</b>"+
43
+ " (%{z:.2f})",
44
+ ])+'<extra></extra>'
45
+ )
46
+ return fig
47
+
48
+
49
+ st.plotly_chart(plot_interactive('A0AV02-2'), use_container_width=True)