def test_initial_guess_wt_average(self): result = fit_rates_weighted_average(self.reduced_hdxm) output = result.output assert output.size == 100 check_rates = csv_to_protein(output_dir / 'ecSecB_reduced_guess.csv') pd.testing.assert_series_equal(check_rates['rate'], output['rate'])
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]) gibbs_guess = hdx_set.guess_deltaG([output['rate'], output['rate']])
from pyhdx.batch_processing import load_from_yaml from pathlib import Path from pyhdx.fitting import fit_rates_weighted_average, fit_rates_half_time_interpolate import yaml from pyhdx.local_cluster import default_client current_dir = Path(__file__).parent data_dir = current_dir.parent / 'tests' / 'test_data' yaml_stream = Path(current_dir / 'yaml_files' / 'SecB.yaml').read_text() data_dict = yaml.safe_load(yaml_stream) # Requires local_cluster.py to be running (or other Dask client on default address in config) client = default_client() for name, dic in data_dict.items(): print(name) dic = data_dict[name] hdxm = load_from_yaml(dic, data_dir=data_dir) #Uncomment/adjust path to save sequence info + intrinsic rates #hdxm.coverage.protein.to_file(f'{name}_sequence_info.txt', fmt='pprint') fr = fit_rates_weighted_average(hdxm, client=client) fr.output.to_file(current_dir / 'guesses' / f'{name}_rates_guess.txt')
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) data = pmt.get_state('SecB WT apo') reduced_data = data[data['end'] < 40] hdxm_reduced = HDXMeasurement(reduced_data, temperature=temperature, pH=pH) result = fit_rates_weighted_average(hdxm_reduced) reduced_guess = result.output dataframe_to_file(output_dir / 'ecSecB_reduced_guess.csv', reduced_guess) dataframe_to_file(output_dir / 'ecSecB_reduced_guess.txt', reduced_guess, fmt='pprint') gibbs_guess = hdxm_reduced.guess_deltaG(reduced_guess['rate']) fr_torch = fit_gibbs_global(hdxm_reduced, gibbs_guess, epochs=epochs, r1=2) save_fitresult(output_dir / 'ecsecb_reduced', fr_torch) if guess: wt_avg_result = fit_rates_weighted_average(hdxm, bounds=(1e-2 / 60., 800 / 60.)) guess_output = wt_avg_result.output dataframe_to_file(output_dir / 'ecSecB_guess.csv', guess_output)
def test_initial_guess(self): result = fit_rates_weighted_average(self.reduced_series) output = result.output assert output.size == 100
#%% # Load the data of two Dynamx files, and combine the result to one table data = read_dynamx(input_dir / 'ecSecB_apo.csv', input_dir / 'ecSecB_dimer.csv') pmt = PeptideMasterTable(data, drop_first=1, ignore_prolines=True, remove_nan=False) pmt.set_control(('Full deuteration control', 0.167*60)) temperature, pH = 273.15 + 30, 8. hdxm = HDXMeasurement(pmt.get_state('SecB WT apo'), temperature=temperature, pH=pH) #%% if guess: client = default_client() wt_avg_result = fit_rates_weighted_average(hdxm, client=client) init_guess = wt_avg_result.output else: init_guess = csv_to_dataframe(test_data_dir / 'output' / 'ecSecB_guess.csv') gibbs_guess = hdxm.guess_deltaG(init_guess['rate']) #%% fr_torch = fit_gibbs_global(hdxm, gibbs_guess, **fit_kwargs) #Human readable output fr_torch.to_file(output_dir / 'SecB_fit_result.txt', fmt='pprint') #Machine readable output fr_torch.to_file(output_dir / 'SecB_fit_result.csv', fmt='csv')
guess = False epochs = 1000 root_dir = Path().resolve().parent test_data_dir = root_dir / 'tests' / 'test_data' input_file_path = test_data_dir / 'ecSecB_apo.csv' # Load the data of two Dynamx files, and combine the result to one table 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(('Full deuteration control', 0.167)) temperature, pH = 273.15 + 30, 8. series = HDXMeasurement(pmt.get_state('SecB WT apo'), temperature=temperature, pH=pH) if guess: client = default_client() wt_avg_result = fit_rates_weighted_average(series, client=client) init_guess = wt_avg_result.output else: init_guess = csv_to_protein(test_data_dir / 'ecSecB_guess.txt') gibbs_guess = series.guess_deltaG(init_guess['rate']) fr_torch = fit_gibbs_global(series, gibbs_guess, epochs=epochs) print(fr_torch.metadata['total_loss'])