-
Notifications
You must be signed in to change notification settings - Fork 4
/
case_study.py
307 lines (245 loc) · 10.9 KB
/
case_study.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
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__ = '[email protected]'
__status__ = 'Dev'
path_case_study_root_data = os.path.join('..', 'Data', 'cached', 'example_1')
path_case_study_genomics = os.path.join(path_case_study_root_data, 'genomics')
path_case_study_proteomics = os.path.join(
path_case_study_root_data, 'proteomics')
path_case_study_transcriptomics = os.path.join(
path_case_study_root_data, 'transcriptomics')
path_case_study_metabolomics = os.path.join(
path_case_study_root_data, 'metabolomics')
path_case_study_phy_che = os.path.join(
path_case_study_root_data, 'phy_che')
path_case_study_viz = os.path.join(
path_case_study_root_data, 'visualizations')
CALCULATED_DATA_SET_NAME = 'calculated.pkl'
CALCULATED_NOW_DATA_SET_NAME = 'calculated_now.pkl'
path_case_study_genomics_fasta = os.path.join(
path_case_study_genomics, 'rmags_filtered')
path_case_study_genomics_kegg = os.path.join(path_case_study_genomics, 'KEGG')
path_case_study_genomics_bins = os.path.join(path_case_study_genomics, 'Bins')
path_case_study_genomics_depths = os.path.join(
path_case_study_genomics, 'MG_Depths')
path_case_study_transcriptomics_depths = os.path.join(
path_case_study_transcriptomics, 'MT_Depths')
path_case_study_proteomics_fasta = os.path.join(
path_case_study_proteomics, 'set_of_78')
path_case_study_metabolomics_prec_1 = os.path.join(
path_case_study_metabolomics, CALCULATED_DATA_SET_NAME)
path_case_study_metabolomics_prec_2 = os.path.join(
path_case_study_metabolomics, CALCULATED_NOW_DATA_SET_NAME)
path_case_study_phy_che_prec_1 = os.path.join(
path_case_study_phy_che, CALCULATED_DATA_SET_NAME)
def upload_multiple(key_suffix):
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'}
}
default_case_study_data_set_types = {
'Metagenomics': 2,
'Metaproteomics': 0,
'Metatranscriptomics': 0,
'Metabolomics': 1,
'Physico-chemical': 0
}
selected_data_set_type = st.selectbox(
'What kind of data set do you want to see?',
options=list(available_data_set_types[key_suffix].keys()),
index=default_case_study_data_set_types[key_suffix],
key='Case_study_' + key_suffix)
if key_suffix == 'Metagenomics':
if selected_data_set_type == 'Raw FASTA files':
return_path = path_case_study_genomics_fasta
# elif selected_data_set_type == 'KEGG annotation files':
# return_path = path_case_study_genomics_kegg
elif selected_data_set_type == 'Depth-of-coverage':
return_path = path_case_study_genomics_depths
else:
return_path = path_case_study_genomics_bins
elif key_suffix == 'Metaproteomics':
return_path = path_case_study_proteomics_fasta
elif key_suffix == 'Metatranscriptomics':
return_path = path_case_study_transcriptomics_depths
elif key_suffix == 'Metabolomics':
if selected_data_set_type == 'Processed data set 1':
return_path = path_case_study_metabolomics_prec_1
elif selected_data_set_type == 'Processed data set 2':
return_path = path_case_study_metabolomics_prec_2
else:
pass
elif key_suffix == 'Physico-chemical':
if selected_data_set_type == 'Processed data set 1':
return_path = path_case_study_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 case_study_genomics():
key_suffix = 'Metagenomics'
cache_folder_path = path_case_study_genomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
key_suffix += '_CASE_STUDY'
return common.work_with_zip(
folder_path_or_df, data_set_type, cache_folder_path, key_suffix)
def case_study_proteomics():
key_suffix = 'Metaproteomics'
cache_folder_path = path_case_study_proteomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
key_suffix += '_CASE_STUDY'
return common.work_with_zip(
folder_path_or_df, data_set_type, cache_folder_path, key_suffix)
def case_study_metabolomics():
key_suffix = 'Metabolomics'
cache_folder_path = path_case_study_metabolomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
key_suffix += '_CASE_STUDY'
return common.work_with_csv(
folder_path_or_df, cache_folder_path, key_suffix)
def case_study_transcriptomics():
key_suffix = 'Metatranscriptomics'
cache_folder_path = path_case_study_transcriptomics
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
key_suffix += '_CASE_STUDY'
return common.work_with_zip(
folder_path_or_df, data_set_type, cache_folder_path, key_suffix)
def case_study_phy_che():
key_suffix = 'Physico-chemical'
cache_folder_path = path_case_study_phy_che
folder_path_or_df, data_set_type = upload_intro(
cache_folder_path, key_suffix)
key_suffix += '_CASE_STUDY'
return common.work_with_csv(
folder_path_or_df, cache_folder_path, key_suffix)
def create_main_case_study():
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)
case_study_omics_list = ['Metagenomics', 'Metabolomics', 'Metaproteomics',
'Metatranscriptomics', 'Physico-chemical']
# We use this specific omics for case study, as default values for
# multiselect widget
default_case_study_omics = ['Physico-chemical']
choose_omics = st.multiselect(
'What kind of omic data do you want to explore?',
case_study_omics_list, default=default_case_study_omics)
st.info('''**To demonstrate the usability of MOVIS, we presented a case study
based on one of the available examples. We focused on the built-in
Example 1 that contains metagenomics, metaproteomics,
metatranscriptomics, metabolomics, and physico-chemical data from
the biological wastewater treatment plant (BWWTP).
The data was collected in situ, at weekly intervals, and over 14
months. The end goal of this case study was to reveal if there were
any niche types, and if there were, how do they respond to the
substrate changes. The case study employs some functional omics
aspects, as presented in the original manuscript. We recommend that
users follow the omics order presented in the Case Study wiki page
(https://github.com/AAnzel/MOVIS/wiki/3.-Case-study), to unravel
the story of this data set.**''')
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 += case_study_genomics()
elif i == 'Metabolomics':
with column_list[curr_pos]:
curr_pos += 1
charts += case_study_metabolomics()
elif i == 'Metaproteomics':
with column_list[curr_pos]:
curr_pos += 1
charts += case_study_proteomics()
elif i == 'Metatranscriptomics':
with column_list[curr_pos]:
curr_pos += 1
charts += case_study_transcriptomics()
elif i == 'Physico-chemical':
with column_list[curr_pos]:
curr_pos += 1
charts += case_study_phy_che()
else:
pass
else:
for i in choose_omics:
if i == 'Metagenomics':
charts += case_study_genomics()
elif i == 'Metabolomics':
charts += case_study_metabolomics()
elif i == 'Metaproteomics':
charts += case_study_proteomics()
elif i == 'Metatranscriptomics':
charts += case_study_transcriptomics()
elif i == 'Physico-chemical':
charts += case_study_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_case_study_viz, i[1])
else:
pass
return None