-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
279 lines (247 loc) · 9.66 KB
/
utils.py
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
import json
import base64
import string
import random
import streamlit as st
import streamlit.components.v1 as components
from st_aggrid import JsCode
from st_pages import show_pages_from_config
from streamlit_extras.switch_page_button import switch_page
from streamlit_lottie import st_lottie, st_lottie_spinner
def get_random_key(size=6, chars=string.ascii_lowercase + string.digits):
return "".join(random.choice(chars) for _ in range(size))
@st.cache_data(show_spinner=False)
def set_pages():
show_pages_from_config()
def set_page_config():
try:
st.set_page_config(
page_title="TB gen",
page_icon="./assets/favicon.ico",
layout="wide",
initial_sidebar_state="expanded",
)
except st.errors.StreamlitAPIException as e:
if "can only be called once per app" in e.__str__():
# ignore this error
return
raise e
@st.cache_data(show_spinner=False)
def sidebar_image():
image_extension = "svg+xml"
st.markdown(
f"""
<style>
[data-testid="stSidebar"] > div:first-child {{
background: url(data:image/{image_extension};base64,{base64.b64encode(open('./assets/logo.svg', "rb").read()).decode()});
padding-top: 80px;
background-size: 200px;
background-repeat: no-repeat;
background-position: 20px 20px;
}}
</style>
""",
unsafe_allow_html=True,
)
@st.cache_data(show_spinner=False)
def author_link():
with st.sidebar.container():
st.markdown(
"""
<a href="https://www.researchgate.net/profile/Dmitry-Bespiatykh"><img
src="https://img.shields.io/badge/Dmitry_Bespiatykh-00CCBB?logo=researchgate&style=flat-square&labelColor=white&logoWidth=20&logoColor=00CCBB"
alt="RG"
/></a>
<a href="https://orcid.org/0000-0003-0867-5988"><img
src="https://img.shields.io/badge/0000_0003_0867_5988-A6CE39?logo=orcid&style=flat-square&labelColor=white&logoWidth=20"
alt="ORCiD"
/></a>
<a href="https://github.com/dbespiatykh"><img
src="https://img.shields.io/badge/dbespiatykh-181717?logo=github&style=flat-square&labelColor=white&logoWidth=20&logoColor=181717"
alt="GitHub"
/></a>
""",
unsafe_allow_html=True,
)
@st.cache_data(show_spinner=False)
def set_css():
with open("style.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
def home_page():
home = st.button("Home")
if home:
switch_page("home")
@st.cache_data(experimental_allow_widgets=True, show_spinner=False)
def read_index_html():
with open("index.html") as f:
components.html(
f.read(),
height=0,
width=0,
)
def lottie_success():
with open("./assets/lottiefiles/success.json") as f:
animation = json.load(f)
return st_lottie(animation, loop=False, key="success", height=150)
def lottie_error():
with open("./assets/lottiefiles/error.json") as f:
animation = json.load(f)
return st_lottie(animation, loop=True, key="error", height=100)
def lottie_warning():
with open("./assets/lottiefiles/warning.json") as f:
animation = json.load(f)
return st_lottie(animation, loop=True, key="warning", height=100)
def lottie_arrow():
with open("./assets/lottiefiles/arrow.json") as f:
animation = json.load(f)
return st_lottie(animation, loop=False, key="initial", height=100, speed=1.5)
def lottie_spinner():
with open("./assets/lottiefiles/spinner.json") as f:
animation = json.load(f)
return st_lottie_spinner(animation, loop=True, height=100, key=get_random_key())
# def back_button(anchor: str):
# link = f"#{anchor}"
# st.markdown(
# f"""
# <a
# style="text-decoration: none"
# href="{link}">
# <svg
# xmlns="http://www.w3.org/2000/svg"
# width="20"
# height="20"
# fill="#7A3777"
# class="bi bi-arrow-up-square-fill"
# viewBox="0 0 16 16">
# <path
# d="M2 16a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2zm6.5-4.5V5.707l2.146 2.147a.5.5 0 0 0 .708-.708l-3-3a.5.5 0 0 0-.708 0l-3 3a.5.5 0 1 0 .708.708L7.5 5.707V11.5a.5.5 0 0 0 1 0z"/>
# </svg>
# <span style="color: #a65aa3; font-weight: bold">Back to top</span>
# </a>
# """,
# unsafe_allow_html=True,
# )
@st.cache_data(show_spinner=False)
def get_cell_style():
cellstyle_jscode = JsCode(
"""
function(params){
if (params.value == 'A') {
return {
'color': '#C22005',
'font-weight': 'bold',
'font-family': 'sans-serif',
}
}
if (params.value == 'T') {
return{
'color': '#00BC0C',
'font-weight': 'bold',
'font-family': 'sans-serif',
}
}
if (params.value == 'G') {
return{
'color': '#BBAE0C',
'font-weight': 'bold',
'font-family': 'sans-serif',
}
}
if (params.value == 'C') {
return{
'color': '#0529C0',
'font-weight': 'bold',
'font-family': 'sans-serif',
}
}
var re = new RegExp("^L1");
if (re.test(params.value)){
return {
'color': '#006796',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#00679633',
}
}
var re = new RegExp("^L2|^Bmyc|^AA1|^lin2|2.2.1.2");
if (re.test(params.value)){
return {
'color': '#8A517E',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#8A517E33',
}
}
var re = new RegExp("^L3");
if (re.test(params.value)){
return {
'color': '#B56748',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#B5674833',
}
}
var re = new RegExp("^L4");
if (re.test(params.value)){
return {
'color': '#16592C',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#16592C33',
}
}
var re = new RegExp("^L5");
if (re.test(params.value)){
return {
'color': '#595480',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#59548033',
}
}
var re = new RegExp("^L6");
if (re.test(params.value)){
return {
'color': '#82181A',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#82181A33',
}
}
if (params.value == 'L7') {
return {
'color': '#69523D',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#69523D33',
}
}
if (params.value == 'L8') {
return {
'color': '#406094',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#40609433',
}
}
if (params.value == 'L9') {
return {
'color': '#3B8087',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#3B808733',
}
}
var re = new RegExp("^M.");
if (re.test(params.value)){
return {
'color': '#696969',
'font-weight': 'bold',
'font-family':' sans-serif',
'backgroundColor': '#69696933',
}
}
}
"""
)
return cellstyle_jscode