-
Notifications
You must be signed in to change notification settings - Fork 4
/
example_1.py
276 lines (217 loc) · 9.36 KB
/
example_1.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
import os
import streamlit as st
import pandas as pd
import common
__author__ = 'Aleksandar Anžel'
__copyright__ = ''
__credits__ = ['Aleksandar Anžel', 'Georges Hattab']
__license__ = 'GNU General Public License v3.0'
__version__ = '1.0'
__maintainer__ = 'Aleksandar Anžel'
__email__ = 'aleksandar.anzel@uni-marburg.de'
__status__ = 'Dev'
path_example_1_root_data = os.path.join('..', 'Data', 'cached', 'example_1')
path_example_1_genomics = os.path.join(path_example_1_root_data, 'genomics')
path_example_1_proteomics = os.path.join(
path_example_1_root_data, 'proteomics')
path_example_1_transcriptomics = os.path.join(
path_example_1_root_data, 'transcriptomics')
path_example_1_metabolomics = os.path.join(
path_example_1_root_data, 'metabolomics')
path_example_1_phy_che = os.path.join(
path_example_1_root_data, 'phy_che')
path_example_1_viz = os.path.join(
path_example_1_root_data, 'visualizations')
CALCULATED_DATA_SET_NAME = 'calculated.pkl'
CALCULATED_NOW_DATA_SET_NAME = 'calculated_now.pkl'
path_example_1_genomics_fasta = os.path.join(
path_example_1_genomics, 'rmags_filtered')
path_example_1_genomics_kegg = os.path.join(path_example_1_genomics, 'KEGG')
path_example_1_genomics_bins = os.path.join(path_example_1_genomics, 'Bins')
path_example_1_genomics_depths = os.path.join(
path_example_1_genomics, 'MG_Depths')
path_example_1_transcriptomics_depths = os.path.join(
path_example_1_transcriptomics, 'MT_Depths')
path_example_1_proteomics_fasta = os.path.join(
path_example_1_proteomics, 'set_of_78')
path_example_1_metabolomics_prec_1 = os.path.join(
path_example_1_metabolomics, CALCULATED_DATA_SET_NAME)
path_example_1_metabolomics_prec_2 = os.path.join(
path_example_1_metabolomics, CALCULATED_NOW_DATA_SET_NAME)
path_example_1_phy_che_prec_1 = os.path.join(
path_example_1_phy_che, CALCULATED_DATA_SET_NAME)
def upload_multiple(key_suffix):
# TODO: Add KEGG data set, since it is not yet ready for production
# 'KEGG annotation files': 'KEGG',
available_data_set_types = {
'Metagenomics': {
'Raw FASTA files': 'FASTA',
'BINS annotation files': 'BINS',
'Depth-of-coverage': 'DEPTH'},
'Metaproteomics': {
'Raw FASTA files': 'FASTA'},
'Metatranscriptomics': {
'Depth-of-coverage': 'DEPTH'},
'Metabolomics': {
'Processed data set 1': 'CALC',
'Processed data set 2': 'CALC'},
'Physico-chemical': {
'Processed data set 1': 'CALC'}
}
selected_data_set_type = st.selectbox(
'What kind of data set do you want to see?',
list(available_data_set_types[key_suffix].keys()),
key='Example_1_' + key_suffix)
if key_suffix == 'Metagenomics':
if selected_data_set_type == 'Raw FASTA files':
return_path = path_example_1_genomics_fasta
# elif selected_data_set_type == 'KEGG annotation files':
# return_path = path_example_1_genomics_kegg
elif selected_data_set_type == 'Depth-of-coverage':
return_path = path_example_1_genomics_depths
else:
return_path = path_example_1_genomics_bins
elif key_suffix == 'Metaproteomics':
return_path = path_example_1_proteomics_fasta
elif key_suffix == 'Metatranscriptomics':
return_path = path_example_1_transcriptomics_depths
elif key_suffix == 'Metabolomics':
if selected_data_set_type == 'Processed data set 1':
return_path = path_example_1_metabolomics_prec_1
elif selected_data_set_type == 'Processed data set 2':
return_path = path_example_1_metabolomics_prec_2
else:
pass
elif key_suffix == 'Physico-chemical':
if selected_data_set_type == 'Processed data set 1':
return_path = path_example_1_phy_che_prec_1
else:
pass
else:
pass
return (return_path,
available_data_set_types[key_suffix][selected_data_set_type])
def upload_intro(folder_path, key_suffix):
st.header(key_suffix + ' data')
st.markdown('')
return_path = None
return_path, data_set_type = upload_multiple(key_suffix)
if return_path is None:
st.warning('Upload your data set')
# We return DataFrame if we work with tabular data format or precalculated
# We return folder_path if we work with archived data
# Data_set_type is always returned
if data_set_type == 'CALC':
return_path_or_df = common.get_cached_dataframe(return_path)
else:
return_path_or_df = return_path
return return_path_or_df, data_set_type
def example_1_genomics():
key_suffix = 'Metagenomics'
cache_folder_path = path_example_1_genomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
return common.work_with_zip(
folder_path_or_df, data_set_type, cache_folder_path, key_suffix)
def example_1_proteomics():
key_suffix = 'Metaproteomics'
cache_folder_path = path_example_1_proteomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
return common.work_with_zip(
folder_path_or_df, data_set_type, cache_folder_path, key_suffix)
def example_1_metabolomics():
key_suffix = 'Metabolomics'
cache_folder_path = path_example_1_metabolomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
return common.work_with_csv(
folder_path_or_df, cache_folder_path, key_suffix)
def example_1_transcriptomics():
key_suffix = 'Metatranscriptomics'
cache_folder_path = path_example_1_transcriptomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
return common.work_with_zip(
folder_path_or_df, data_set_type, cache_folder_path, key_suffix)
def example_1_phy_che():
key_suffix = 'Physico-chemical'
cache_folder_path = path_example_1_phy_che
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
return common.work_with_csv(
folder_path_or_df, cache_folder_path, key_suffix)
def create_main_example_1():
col_1, col_2 = st.columns([1, 2])
col_1.info('''
This data set comes from the following paper:
**Herold, M., Martínez Arbas, S., Narayanasamy, S. et al.
Integration of time-series meta-omics data reveals how microbial
ecosystems respond to disturbance. Nat Commun 11, 5281(2020).
https://doi.org/10.1038/s41467-020-19006-2**. Analyzed samples
were collected from a biological wastewater treatment plant in
Schifflange, Luxembourg (49.513414, 6.017925). A precise location
is shown on the map located on the right.
It contains **metagenomics**, **metabolomics**, **metaproteomics**,
and **physico-chemical** data. The code used to parse the data can
be found here: [GitLab]
(https://git-r3lab.uni.lu/malte.herold/laots_niche_ecology_analysis)
''')
col_2.map(pd.DataFrame({'lat': [49.513414], 'lon': [6.017925]}),
zoom=8, use_container_width=True)
example_1_omics_list = ['Metagenomics', 'Metabolomics', 'Metaproteomics',
'Metatranscriptomics', 'Physico-chemical']
choose_omics = st.multiselect(
'What kind of omic data do you want to explore?', example_1_omics_list)
num_of_columns = len(choose_omics)
charts = [] # An empty list to hold all pairs (visualizations, key)
if num_of_columns >= 2:
column_list = st.columns(num_of_columns)
curr_pos = 0
for i in choose_omics:
if i == 'Metagenomics':
with column_list[curr_pos]:
curr_pos += 1
charts += example_1_genomics()
elif i == 'Metabolomics':
with column_list[curr_pos]:
curr_pos += 1
charts += example_1_metabolomics()
elif i == 'Metaproteomics':
with column_list[curr_pos]:
curr_pos += 1
charts += example_1_proteomics()
elif i == 'Metatranscriptomics':
with column_list[curr_pos]:
curr_pos += 1
charts += example_1_transcriptomics()
elif i == 'Physico-chemical':
with column_list[curr_pos]:
curr_pos += 1
charts += example_1_phy_che()
else:
pass
else:
for i in choose_omics:
if i == 'Metagenomics':
charts += example_1_genomics()
elif i == 'Metabolomics':
charts += example_1_metabolomics()
elif i == 'Metaproteomics':
charts += example_1_proteomics()
elif i == 'Metatranscriptomics':
charts += example_1_transcriptomics()
elif i == 'Physico-chemical':
charts += example_1_phy_che()
else:
pass
st.markdown('---')
for i in charts:
type_of_chart = type(i[0])
with st.spinner('Visualizing...'):
if 'altair' in str(type_of_chart):
st.altair_chart(i[0], use_container_width=True)
common.save_chart(i[0], path_example_1_viz, i[1])
else:
pass
return None