55"""
66
77
8-
98import sys
109from pathlib import Path
1110
2120from pyhdx .web .utils import load_state , fix_multiindex_dtypes
2221from 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
3029sys ._excepthook = sys .excepthook
3433
3534
3635import traceback as tb
36+
37+
3738def 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
5254sys .excepthook = my_exception_hook
5355
@@ -57,57 +59,71 @@ def my_exception_hook(exctype, value, traceback):
5759cwd = Path (__file__ ).parent
5860root_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" ]
6567file_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
6973state_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
7478def 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+
8693def 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+
98115def 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
120136def 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
0 commit comments