Esempio n. 1
0
    def test_batch_fit_delta(self, tmp_path):
        yaml_file = input_dir / 'data_states_deltas.yaml'
        yaml_dict = yaml.safe_load(yaml_file.read_text())
        hdxm_set = yaml_to_hdxmset(yaml_dict, data_dir=input_dir)
        guess_output = csv_to_dataframe(output_dir / 'ecSecB_guess.csv')

        gibbs_guess = hdxm_set[0].guess_deltaG(guess_output['rate'])

        # broadcast single guess over samples
        fr_global = fit_gibbs_global_batch(hdxm_set, gibbs_guess, epochs=200)
        output = fr_global.output

        check = csv_to_dataframe(output_dir / 'ecsecb_delta_batch' /
                                 'fit_result.csv')
        states = check.columns.unique(level=0)

        for state in states:
            from pandas.testing import assert_series_equal

            result = output[state]['dG']
            test = check[state]['dG']

            assert_series_equal(result, test, rtol=0.1)

        errors = fr_global.get_squared_errors()
        assert errors.shape == (hdxm_set.Ns, hdxm_set.Np, hdxm_set.Nt)
        assert not np.any(np.isnan(errors))
Esempio n. 2
0
    def test_load_from_yaml(self):
        yaml_pth = Path(input_dir / 'data_states.yaml')
        data_dict = yaml.safe_load(yaml_pth.read_text())

        hdxm = yaml_to_hdxm(data_dict['SecB_tetramer'], data_dir=input_dir)
        assert isinstance(hdxm, HDXMeasurement)

        assert hdxm.metadata['temperature'] == data_dict['SecB_tetramer'][
            'temperature']['value'] + 273.15
        assert hdxm.name == 'SecB WT apo'

        hdxm_set = yaml_to_hdxmset(data_dict, data_dir=input_dir)
        assert isinstance(hdxm_set, HDXMeasurementSet)
        assert hdxm_set.names == list(data_dict.keys())
Esempio n. 3
0
from pyhdx.local_cluster import default_client
from pyhdx.fileIO import csv_to_protein
from pyhdx.models import HDXMeasurementSet
from pyhdx.support import pprint_df_to_file
from pyhdx import VERSION_STRING

current_dir = Path(__file__).parent
test_data_dir = current_dir.parent / 'tests' / 'test_data'
input_dir = test_data_dir / 'input'
yaml_stream = Path(current_dir / 'yaml_files' / 'SecB.yaml').read_text()
data_dict = yaml.safe_load(yaml_stream)

output_dir = current_dir / 'fit'
output_dir.mkdir(exist_ok=True)

hdx_set = yaml_to_hdxmset(data_dict, data_dir=input_dir)

rates_list = [
    csv_to_protein(current_dir / 'guesses' / f'{name}_rates_guess.csv')['rate']
    for name in data_dict.keys()
]
gibbs_guess = hdx_set.guess_deltaG(rates_list)

log_file = output_dir / f"fitting_log.txt"
now = datetime.now()
date = f'# {now.strftime("%Y/%m/%d %H:%M:%S")} ({int(now.timestamp())})'

lines = [VERSION_STRING, date]

r2 = 0.5
for r1 in [0, 0.01, 0.25, 0.5, 1]:
Esempio n. 4
0
"""Obtain ΔG for ecSecB tetramer and dimer"""
from pathlib import Path
from pyhdx.batch_processing import yaml_to_hdxmset
from pyhdx.fileIO import csv_to_dataframe, save_fitresult
from pyhdx.fitting import fit_gibbs_global_batch
import yaml

cwd = Path(__file__).parent

data_dir = cwd / 'test_data' / 'input'
output_dir = cwd / 'test_data' / 'output'

yaml_dict = yaml.safe_load(Path(data_dir / 'data_states.yaml').read_text())

hdx_set = yaml_to_hdxmset(yaml_dict, data_dir=data_dir)

initial_guess_rates = csv_to_dataframe(output_dir / 'ecSecB_guess.csv')

guesses = hdx_set[0].guess_deltaG(initial_guess_rates['rate'])
fit_kwargs = yaml.safe_load(Path(data_dir / 'fit_settings.yaml').read_text())

fr = fit_gibbs_global_batch(hdx_set, guesses, **fit_kwargs)
save_fitresult(output_dir / 'ecsecb_tetramer_dimer', fr)