def parse(self, yaml_dict, **kwargs): self._parse_sections(yaml_dict) for name, dic in yaml_dict.get("modules", {}).items(): self._parse_sections(dic) d = yaml_dict["controllers"] controllers = { name: self._resolve_class(name, "controller") for name in d } main_ctrl = yaml_dict["main_controller"] _type = main_ctrl.pop("type") main_ctrl_class = self._resolve_class(_type, "main") ctrl = main_ctrl_class( controllers.values(), sources=self.sources, transforms=self.transforms, opts=self.opts, views=self.views, loggers=self.loggers, client=default_client(), **kwargs, **main_ctrl, ) return ctrl
def main_app(client='default'): client = default_client() if client == 'default' else client logger = main_app.logger # ---------------------------------------------------------------------- # # SOURCES # ---------------------------------------------------------------------- # col_index = pd.MultiIndex.from_tuples([], names=('state', 'quantity')) df_peptides = pd.DataFrame(columns=col_index) col_index = pd.MultiIndex.from_tuples([], names=('state', 'exposure')) row_index = pd.RangeIndex(0, 1, name='r_number') df_rfu = pd.DataFrame(columns=col_index, index=row_index) col_index = pd.MultiIndex.from_tuples([], names=('fit_ID', 'state', 'quantity')) row_index = pd.RangeIndex(0, 1, name='r_number') df_rates = pd.DataFrame(columns=col_index, index=row_index) # todo make sure that proper-shaped df is used to initiate stream (and generalize for rectangles plot) col_index = pd.MultiIndex.from_tuples([], names=('fit_ID', 'state', 'quantity')) row_index = pd.RangeIndex(0, 1, name='r_number') df_global_fit = pd.DataFrame(columns=col_index, index=row_index) col_index = pd.MultiIndex.from_tuples([], names=('color_ID', 'state', 'quantity')) row_index = pd.RangeIndex(0, 1, name='r_number') df_colors = pd.DataFrame(columns=col_index, index=row_index) # Availble tables are predefined at launch, but are empty # this way GUI methods can add to them as multiindex subset # more tables can be added later by the gui tables = {'peptides': df_peptides, 'rfu': df_rfu, 'rates': df_rates, 'global_fit': df_global_fit, 'colors': df_colors} source = DataFrameSource(tables=tables, name='dataframe') #df = csv_to_dataframe(data_dir / 'ecSecB_apo_peptides.csv') #source.add_df(df, 'peptides', 'ecSecB_apo') src_list = [source] # ---------------------------------------------------------------------- # # TRANSFORMS # ---------------------------------------------------------------------- # # rescale_transform = RescaleTransform(field='deltaG', scale_factor=1e-3) # # cmap = mpl.cm.get_cmap('viridis') # norm = mpl.colors.Normalize(vmin=0, vmax=20) # cmap_transform = ApplyCmapTransform(cmap=cmap, norm=norm, field='deltaG') peptides_transform = PeptideLayoutTransform(value='rfu') reset_index_transform = ResetIndexTransform() trs_list = [peptides_transform, reset_index_transform] # ---------------------------------------------------------------------- # # FILTERS # ---------------------------------------------------------------------- # # unique_vals = list(np.sort(peptides_source.get_unique(table='peptides', field='exposure'))) multiindex_select_filter = MultiIndexSelectFilter(field='state', name='select_index', table='peptides', source=source) # unique_vals = list(np.sort(source.get_unique(table='peptides', field='exposure', state='ecSecB_apo'))) slider_exposure_filter = UniqueValuesFilter(field='exposure', name='exposure_slider', table='peptides', filters=[multiindex_select_filter], source=source) filter_list = [multiindex_select_filter, slider_exposure_filter] # ---------------------------------------------------------------------- # # OPTS # ---------------------------------------------------------------------- # additional_opts = {'color': 'value', 'colorbar': True, 'responsive': True, 'clim': (0, 1), 'framewise': True, 'xlabel': "Residue Number", 'ylabel': '', 'yticks': 0, **global_opts} cmap_opts = CmapOpts(opts=additional_opts, name='cmap') opts_list = [cmap_opts] # ---------------------------------------------------------------------- # # VIEWS # ---------------------------------------------------------------------- # view_list = [] rescale_transform = RescaleTransform(field='deltaG', scale_factor=1e-3) cmap = mpl.cm.get_cmap('viridis') norm = mpl.colors.Normalize(vmin=0, vmax=20) cmap_transform = ApplyCmapTransform(cmap=cmap, norm=norm, field='deltaG', name='cmap_transform') trs_list.append(rescale_transform) trs_list.append(cmap_transform) multiindex_select_global_fit_1 = MultiIndexSelectFilter(field='fit_ID', name='select_index_global_fit_lv1', table='global_fit', source=source) multiindex_select_global_fit_2 = MultiIndexSelectFilter(field='state', name='select_index_global_fit_lv2', table='global_fit', source=source, filters=[multiindex_select_global_fit_1]) filter_list += [multiindex_select_global_fit_1, multiindex_select_global_fit_2] opts = {'xlabel': 'Residue Number', 'ylabel': 'ΔG (kJ mol⁻¹)', 'colorbar': False, **global_opts} deltaG = hvPlotAppView(source=source, name='gibbs', x='r_number', y='deltaG', kind='scatter', c='color', table='global_fit', transforms=[cmap_transform, rescale_transform], streaming=True, filters=[multiindex_select_global_fit_1, multiindex_select_global_fit_2], responsive=True, opts=opts) #issue 154: deltaG units view_list.append(deltaG) coverage = hvRectangleAppView(source=source, name='coverage', table='peptides', opts=cmap_opts.opts, streaming=True, transforms=[peptides_transform], filters=[multiindex_select_filter, slider_exposure_filter]) view_list.append(coverage) multiindex_select_rates_1 = MultiIndexSelectFilter(field='fit_ID', name='select_index_rates_lv1', table='rates', source=source) multiindex_select_rates_2 = MultiIndexSelectFilter(field='state', name='select_index_rates_lv2', table='rates', source=source, filters=[multiindex_select_rates_1]) filter_list += [multiindex_select_rates_1, multiindex_select_rates_2] # perhaps consider derivedsource for the views opts = {'logy': True, 'xlabel': "Residue Number", 'ylabel': "Rate (min⁻¹)", 'colorbar': False, **global_opts} rates = hvPlotAppView(source=source, name='rates', x='r_number', y='rate', kind='scatter', # c='color' table='rates', streaming=True, responsive=True, opts=opts, transforms=[reset_index_transform], filters=[multiindex_select_rates_1, multiindex_select_rates_2] ) view_list.append(rates) multiindex_select_colors_1 = MultiIndexSelectFilter(field='color_ID', name='select_index_colors_lv1', table='colors', source=source) multiindex_select_colors_2 = MultiIndexSelectFilter(field='state', name='select_index_colors_lv2', table='colors', source=source, filters=[multiindex_select_colors_1]) filter_list += [multiindex_select_colors_1, multiindex_select_colors_2] protein_view = NGLView(source=source, name='protein', table='colors', filters=[multiindex_select_colors_1, multiindex_select_colors_2] ) view_list.append(protein_view) log_view = LoggingView(logger=logger, level=logging.INFO, name='Info log') debug_log_view = LoggingView(logger=logger, level=logging.DEBUG, name='Debug log') view_list.append(log_view) view_list.append(debug_log_view) sources = {src.name: src for src in src_list} transforms = {trs.name: trs for trs in trs_list} filters = {filt.name: filt for filt in filter_list} views = {view.name: view for view in view_list} opts = {opt.name: opt for opt in opts_list} control_panels = [ PeptideFileInputControl, CoverageControl, InitialGuessControl, FitControl, ClassificationControl, ProteinControl, GraphControl, # FitResultControl, FileExportControl, # ProteinViewControl, # OptionsControl ] if DEBUG: control_panels.append(DeveloperControl) ctrl = PyHDXController(control_panels, sources=sources, transforms=transforms, filters=filters, opts=opts, views=views, client=client, logger=logger) elvis = GoldenElvis(ExtendedGoldenTemplate, ExtendedGoldenDarkTheme, title=VERSION_STRING_SHORT) ctrl.logger.addHandler(get_default_handler(sys.stdout)) elvis.compose(ctrl, elvis.column( elvis.stack( elvis.view(ctrl.views['protein']), elvis.view(ctrl.views['coverage']), ), elvis.row( elvis.stack( elvis.view(ctrl.views['rates']), elvis.view(ctrl.views['gibbs']), ), elvis.stack( elvis.view(ctrl.views['Info log']), elvis.view(ctrl.views['Debug log']) ) ) ) ) return ctrl
directory = Path(__file__).parent test_data_dir = directory / 'test_data' guess = False # guess true requires dask cluster at config defined ip/port control = ('Full deuteration control', 0.167) data = read_dynamx(test_data_dir / 'ecSecB_apo.csv', test_data_dir / 'ecSecB_dimer.csv') pmt = PeptideMasterTable(data, drop_first=1, ignore_prolines=True, remove_nan=False) pmt.set_control(control) temperature, pH = 273.15 + 30, 8. hdxm = HDXMeasurement(pmt.get_state('SecB WT apo'), sequence=sequence, temperature=temperature, pH=pH) if guess: client = default_client() wt_avg_result = fit_rates_weighted_average(hdxm, bounds=(1e-2, 800)) output = wt_avg_result.output output.to_file(directory / 'test_data' / 'ecSecB_guess.txt') else: output = csv_to_protein(directory / 'test_data' / 'ecSecB_guess.txt') gibbs_guess = hdxm.guess_deltaG(output['rate']) fr_torch = fit_gibbs_global(hdxm, gibbs_guess, epochs=epochs, r1=2) fr_torch.output.to_file(directory / 'test_data' / 'ecSecB_torch_fit.txt') hdxm_dimer = HDXMeasurement(pmt.get_state('SecB his dimer apo'), sequence=sequence_dimer, temperature=temperature, pH=pH) hdx_set = HDXMeasurementSet([hdxm_dimer, hdxm])