Skip to content

Commit ee24eac

Browse files
authored
Refactor loading data (#305)
* refactor loading data * fix batch processing test * cleanup and removing old code * remove deprecated import * cleanup imports * fix gui tests * template imports * allow filtering exposure by float * fix typo * fix column order * update examples * types * add global metadata * ran black
1 parent dc82a4a commit ee24eac

File tree

88 files changed

+408775
-8265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+408775
-8265
lines changed

dev/deps/_requirements.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from typing import Optional
2424

2525

26-
2726
#%%
2827
# Pycharm scientific mode compat
2928
if "__file__" not in locals():
@@ -144,5 +143,4 @@ def make_requirements_files(extras: Optional[list[str]] = None):
144143
conda_file = Path(f"pinned/py38_{os}_conda.yml")
145144
pip_file = Path(f"pinned/py38_{os}_pip.txt")
146145

147-
148146
conda_to_pip(conda_file, pip_file)

dev/gui/dev_gui_secB.py

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77

8-
98
import sys
109
from pathlib import Path
1110

@@ -21,10 +20,10 @@
2120
from pyhdx.web.utils import load_state, fix_multiindex_dtypes
2221
from pyhdx.config import cfg, reset_config
2322

24-
#def printfunc(args):
25-
# 1/0
23+
# def printfunc(args):
24+
# 1/0
2625

27-
#sys.stdout = printfunc
26+
# sys.stdout = printfunc
2827

2928

3029
sys._excepthook = sys.excepthook
@@ -34,6 +33,8 @@
3433

3534

3635
import traceback as tb
36+
37+
3738
def my_exception_hook(exctype, value, traceback):
3839
# Print the error and traceback
3940
# https://stackoverflow.com/questions/43039048/pyqt5-fails-with-cryptic-message/43039363#43039363
@@ -48,6 +49,7 @@ def my_exception_hook(exctype, value, traceback):
4849
sys._excepthook(exctype, value, traceback)
4950
sys.exit(1)
5051

52+
5153
# Set the exception hook to our wrapping function
5254
sys.excepthook = my_exception_hook
5355

@@ -57,57 +59,71 @@ def my_exception_hook(exctype, value, traceback):
5759
cwd = Path(__file__).parent
5860
root_dir = cwd.parent.parent
5961

60-
web_data_dir = root_dir / 'tests' / 'test_data' / 'output' / 'web'
61-
input_data_dir = root_dir / 'tests' / 'test_data' / 'input'
62+
web_data_dir = root_dir / "tests" / "test_data" / "output" / "web"
63+
input_data_dir = root_dir / "tests" / "test_data" / "input"
6264

6365

64-
filenames = ['ecSecB_apo.csv', 'ecSecB_dimer.csv']
66+
filenames = ["ecSecB_apo.csv", "ecSecB_dimer.csv"]
6567
file_dict = {fname: (input_data_dir / fname).read_bytes() for fname in filenames}
6668

67-
batch_fname = 'data_states_deltas.yaml' # secb apo / dimer but artificial delta C/N tail
69+
# batch_fname = 'data_states_deltas.yaml' # secb apo / dimer but artificial delta C/N tail, needs additional files
70+
batch_fname = "data_states.yaml" #
71+
6872

6973
state_spec = yaml.safe_load(Path(input_data_dir / batch_fname).read_text())
7074
# pdb_string = (web_data_dir / '1qyn.pdb').read_text()
71-
pdb_string = (web_data_dir / '5JTR_mod.pdb').read_text()
75+
pdb_string = (web_data_dir / "5JTR_mod.pdb").read_text()
7276

7377

7478
def reload_tables():
75-
src = ctrl.sources['main']
76-
src.add_table('peptides', csv_to_dataframe(web_data_dir / 'peptides.csv'))
77-
src.add_table('d_uptake', csv_to_dataframe(web_data_dir / 'd_uptake.csv'))
78-
src.add_table('rfu', csv_to_dataframe(web_data_dir / 'rfu.csv'))
79-
src.add_table('dG', csv_to_dataframe(web_data_dir / 'dG.csv'))
80-
src.add_table('ddG_comparison', csv_to_dataframe(web_data_dir / 'ddG_comparison.csv'))
81-
src.add_table('rates', csv_to_dataframe(web_data_dir / 'rates.csv'))
82-
src.param.trigger('updated')
79+
src = ctrl.sources["main"]
80+
src.add_table("peptides", csv_to_dataframe(web_data_dir / "peptides.csv"))
81+
src.add_table("d_uptake", csv_to_dataframe(web_data_dir / "d_uptake.csv"))
82+
src.add_table("rfu", csv_to_dataframe(web_data_dir / "rfu.csv"))
83+
src.add_table("dG", csv_to_dataframe(web_data_dir / "dG.csv"))
84+
src.add_table(
85+
"ddG_comparison", csv_to_dataframe(web_data_dir / "ddG_comparison.csv")
86+
)
87+
src.add_table("rates", csv_to_dataframe(web_data_dir / "rates.csv"))
88+
src.param.trigger("updated")
8389

8490
# ctrl.views['protein'].object = pdb_string
8591

92+
8693
def reload_dashboard():
87-
source = ctrl.sources['dataframe']
88-
for ds in ['peptides', 'peptides_mse', 'd_calc', 'rfu', 'rates', 'global_fit', 'losses']:
89-
df = csv_to_dataframe(web_data_dir / f'{ds}.csv')
94+
source = ctrl.sources["dataframe"]
95+
for ds in [
96+
"peptides",
97+
"peptides_mse",
98+
"d_calc",
99+
"rfu",
100+
"rates",
101+
"global_fit",
102+
"losses",
103+
]:
104+
df = csv_to_dataframe(web_data_dir / f"{ds}.csv")
90105
source.add_df(df, ds)
91106

92-
#Temporary workaround for comment characters in csv files
93-
ds = 'colors'
94-
df = pd.read_csv(web_data_dir / f'{ds}.csv', header=[0, 1, 2], index_col=0,
95-
skiprows=3)
107+
# Temporary workaround for comment characters in csv files
108+
ds = "colors"
109+
df = pd.read_csv(
110+
web_data_dir / f"{ds}.csv", header=[0, 1, 2], index_col=0, skiprows=3
111+
)
96112
source.add_df(df, ds)
97113

114+
98115
def init_batch():
99-
input_control = ctrl.control_panels['PeptideFileInputControl']
100-
input_control.input_mode = 'Batch'
116+
input_control = ctrl.control_panels["PeptideFileInputControl"]
117+
input_control.input_mode = "Batch"
118+
119+
file_dict = {fname: (input_data_dir / fname).read_bytes() for fname in filenames}
120+
input_control.widgets["input_files"].filename = list(file_dict.keys())
101121
input_control.input_files = list(file_dict.values())
102-
input_control.widgets['input_files'].filename = list(file_dict.keys())
103122

104123
input_control.batch_file = Path(input_data_dir / batch_fname).read_bytes()
105124
input_control._action_load_datasets()
106125

107-
input_control.batch_file = Path(input_data_dir / batch_fname).read_bytes()
108-
input_control._action_add_dataset()
109-
110-
fit_control = ctrl.control_panels['FitControl']
126+
fit_control = ctrl.control_panels["FitControl"]
111127

112128
fit_control.r1 = 0.05
113129
fit_control.r2 = 0.1
@@ -119,7 +135,7 @@ def init_batch():
119135

120136
def init_dashboard():
121137
n = 2 # change this to control the number of HDX measurements added
122-
input_control = ctrl.control_panels['PeptideFileInputControl']
138+
input_control = ctrl.control_panels["PeptideFileInputControl"]
123139

124140
for i, (k, v) in enumerate(state_spec.items()):
125141
if i == n:
@@ -132,9 +148,9 @@ def init_dashboard():
132148
d_uptake_control = ctrl.control_panels["DUptakeFitControl"]
133149
d_uptake_control.repeats = 2
134150

135-
ctrl.sources['pdb'].add_from_string(pdb_string, '1qyn')
151+
ctrl.sources["pdb"].add_from_string(pdb_string, "1qyn")
136152

137-
src = ctrl.sources['main']
153+
src = ctrl.sources["main"]
138154
# df = csv_to_dataframe(web_data_dir / 'd_uptake.csv')
139155
# df.columns = fix_multiindex_dtypes(df.columns)
140156
# src.add_table('d_uptake', df)
@@ -146,7 +162,6 @@ def init_dashboard():
146162

147163
# src.updated = True
148164

149-
150165
# guess_control = ctrl.control_panels['InitialGuessControl']
151166
# guess_control._action_fit()
152167
#
@@ -170,23 +185,39 @@ def init_dashboard():
170185
# diff = ctrl.control_panels['DifferentialControl']
171186
# diff._action_add_comparison()
172187

173-
174188
# if n > 1:
175189
# diff = ctrl.control_panels['DifferentialControl']
176190
# diff._action_add_comparison()
177191

178192

179-
#pn.state.onload(reload_dashboard)
180-
#pn.state.onload(reload_tables)
181-
pn.state.onload(init_dashboard)
182-
#pn.state.onload(init_batch)
193+
def init_manual():
194+
input_control = ctrl.control_panels["PeptideFileInputControl"]
195+
196+
file_dict = {fname: (input_data_dir / fname).read_bytes() for fname in filenames}
197+
input_control.widgets["input_files"].filename = list(file_dict.keys())
198+
input_control.input_files = list(file_dict.values())
199+
200+
input_control.fd_state = "Full deuteration control"
201+
input_control.fd_exposure = 10.020000000000001
202+
203+
input_control.exp_state = "SecB WT apo"
204+
183205

206+
# pn.state.onload(reload_dashboard)
207+
# pn.state.onload(reload_tables)
208+
# pn.state.onload(init_dashboard)
209+
pn.state.onload(init_batch)
210+
# pn.state.onload(init_manual)
184211

185-
if __name__ == '__main__':
212+
if __name__ == "__main__":
186213
Path(cfg.assets_dir).mkdir(exist_ok=True, parents=True)
187-
pn.serve(tmpl, show=True, static_dirs={'pyhdx': STATIC_DIR, "assets": str(cfg.assets_dir)})
214+
pn.serve(
215+
tmpl,
216+
show=True,
217+
static_dirs={"pyhdx": STATIC_DIR, "assets": str(cfg.assets_dir)},
218+
)
188219

189-
elif __name__.startswith('bokeh_app'):
220+
elif __name__.startswith("bokeh_app"):
190221
Path(cfg.assets_dir).mkdir(exist_ok=True, parents=True)
191222
tmpl.servable()
192223

dev/gui/dev_mwe_app.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ def my_exception_hook(exctype, value, traceback):
5656
views = {v: ctrl.views[v] for v in views_names}
5757
# [v.update() for v in views.values()]
5858

59-
tmpl = elvis.compose(
60-
elvis.row(
61-
elvis.view("xy_scatter"),
62-
elvis.view("xy_line")
63-
)
64-
)
59+
tmpl = elvis.compose(elvis.row(elvis.view("xy_scatter"), elvis.view("xy_line")))
6560

6661

6762
def reload_tables():

dev/gui/dev_rfu_app.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
sys._excepthook = sys.excepthook
2424

2525
import traceback as tb
26+
27+
2628
def my_exception_hook(exctype, value, traceback):
2729
# Print the error and traceback
2830
# https://stackoverflow.com/questions/43039048/pyqt5-fails-with-cryptic-message/43039363#43039363
@@ -37,6 +39,7 @@ def my_exception_hook(exctype, value, traceback):
3739
sys._excepthook(exctype, value, traceback)
3840
sys.exit(1)
3941

42+
4043
# Set the exception hook to our wrapping function
4144
sys.excepthook = my_exception_hook
4245

@@ -45,19 +48,19 @@ def my_exception_hook(exctype, value, traceback):
4548

4649
cwd = Path(__file__).parent
4750
root_dir = cwd.parent.parent
48-
data_dir = root_dir / 'tests' / 'test_data' / 'input'
51+
data_dir = root_dir / "tests" / "test_data" / "input"
4952

5053

5154
# batch_fname = 'data_states.yaml' # standard secb apo / dimer dataset
5255
# batch_fname = 'data_states_red.yaml' # reduced number of pepties
53-
batch_fname = 'PpiX_states.yaml' # secb apo / dimer but artificial delta C/N tail
56+
batch_fname = "PpiX_states.yaml" # secb apo / dimer but artificial delta C/N tail
5457

5558
state_spec = yaml.safe_load(Path(data_dir / batch_fname).read_text())
5659

5760

5861
def init_dashboard():
5962
n = 2 # change this to control the number of HDX measurements added
60-
input_control = ctrl.control_panels['PeptideRFUFileInputControl']
63+
input_control = ctrl.control_panels["PeptideRFUFileInputControl"]
6164
for i, (k, v) in enumerate(state_spec.items()):
6265
if i == n:
6366
break
@@ -66,23 +69,26 @@ def init_dashboard():
6669

6770
input_control._action_load_datasets()
6871

69-
70-
7172
# if n > 1:
7273
# diff = ctrl.control_panels['DifferentialControl']
7374
# diff._action_add_comparison()
7475

75-
#pn.state.onload(reload_dashboard)
76-
#pn.state.onload(reload_tables)
76+
77+
# pn.state.onload(reload_dashboard)
78+
# pn.state.onload(reload_tables)
7779
pn.state.onload(init_dashboard)
78-
#pn.state.onload(init_batch)
80+
# pn.state.onload(init_batch)
7981

8082

81-
if __name__ == '__main__':
83+
if __name__ == "__main__":
8284
Path(cfg.assets_dir).mkdir(exist_ok=True, parents=True)
83-
pn.serve(tmpl, show=True, static_dirs={'pyhdx': STATIC_DIR, "assets": str(cfg.assets_dir)})
85+
pn.serve(
86+
tmpl,
87+
show=True,
88+
static_dirs={"pyhdx": STATIC_DIR, "assets": str(cfg.assets_dir)},
89+
)
8490

85-
elif __name__.startswith('bokeh_app'):
91+
elif __name__.startswith("bokeh_app"):
8692
Path(cfg.assets_dir).mkdir(exist_ok=True, parents=True)
8793
tmpl.servable()
8894

docs/bk/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def setup(app):
7272
master_doc = "index"
7373

7474
# General information about the project.
75-
project = u"PyHDX"
76-
copyright = u"2022, Jochem Smit"
77-
author = u"Jochem Smit"
75+
project = "PyHDX"
76+
copyright = "2022, Jochem Smit"
77+
author = "Jochem Smit"
7878

7979
# The version info for the project you're documenting, acts as replacement
8080
# for |version| and |release|, also used in various other places throughout
@@ -150,15 +150,15 @@ def setup(app):
150150
# (source start file, target name, title, author, documentclass
151151
# [howto, manual, or own class]).
152152
latex_documents = [
153-
(master_doc, "pyhdx.tex", u"PyHDX Documentation", u"Jochem Smit", "manual"),
153+
(master_doc, "pyhdx.tex", "PyHDX Documentation", "Jochem Smit", "manual"),
154154
]
155155

156156

157157
# -- Options for manual page output ------------------------------------
158158

159159
# One entry per manual page. List of tuples
160160
# (source start file, name, description, authors, manual section).
161-
man_pages = [(master_doc, "pyhdx", u"PyHDX Documentation", [author], 1)]
161+
man_pages = [(master_doc, "pyhdx", "PyHDX Documentation", [author], 1)]
162162

163163

164164
# -- Options for Texinfo output ----------------------------------------
@@ -170,7 +170,7 @@ def setup(app):
170170
(
171171
master_doc,
172172
"pyhdx",
173-
u"PyHDX Documentation",
173+
"PyHDX Documentation",
174174
author,
175175
"pyhdx",
176176
"Derive ΔG for single residues from HDX-MS data",

0 commit comments

Comments
 (0)