def setup_class(cls): fpath_apo = input_dir / 'ecSecB_apo.csv' fpath_dimer = input_dir / 'ecSecB_dimer.csv' data = read_dynamx(fpath_apo, fpath_dimer) control = ('Full deuteration control', 0.167 * 60) cls.temperature, cls.pH = 273.15 + 30, 8. pf = PeptideMasterTable(data, drop_first=1, ignore_prolines=True, remove_nan=False) pf.set_control(control) cls.hdxm_apo = HDXMeasurement(pf.get_state('SecB WT apo'), temperature=cls.temperature, pH=cls.pH) cls.hdxm_dimer = HDXMeasurement(pf.get_state('SecB his dimer apo'), temperature=cls.temperature, pH=cls.pH) data = pf.get_state('SecB WT apo') reduced_data = data[data['end'] < 40] cls.reduced_hdxm = HDXMeasurement(reduced_data) cluster = LocalCluster() cls.address = cluster.scheduler_address
def setup_class(cls): fpath = input_dir / 'ecSecB_apo.csv' cls.pmt = PeptideMasterTable(read_dynamx(fpath)) cls.pmt.set_control(('Full deuteration control', 0.167 * 60)) d = cls.pmt.get_state('SecB WT apo') cls.temperature, cls.pH = 273.15 + 30, 8. cls.hdxm = HDXMeasurement(d, temperature=cls.temperature, pH=cls.pH)
def setup_class(cls): dtype = [('r_number', int), ('apple', float)] array1 = np.empty(15, dtype=dtype) array1['r_number'] = np.arange(15) + 3 array1['apple'] = np.ones(15) * 12 cls.array1 = array1 dtype = [('r_number', int), ('apple', float), ('grapes', float)] array2 = np.empty(17, dtype=dtype) array2['r_number'] = np.arange(17) + 6 array2['apple'] = np.ones(17) * 10 array2['grapes'] = np.ones(17) * 15 + np.random.rand(17) cls.array2 = array2 dtype = [('r_number', int), ('pear', float), ('banana', float)] array3 = np.empty(10, dtype=dtype) array3['r_number'] = np.arange(10) + 1 array3['pear'] = np.random.rand(10) + 20 array3['banana'] = -(np.random.rand(10) + 20) cls.array3 = array3 cls.protein = txt_to_protein(directory / 'test_data' / 'simulated_data_info.txt') fpath = directory / 'test_data' / 'ecSecB_apo.csv' pf1 = PeptideMasterTable(read_dynamx(fpath)) states = pf1.groupby_state(c_term=200) cls.series = states['SecB WT apo']
def setup_class(cls): fpath = directory / 'test_data' / 'ecSecB_apo.csv' cls.pmt = PeptideMasterTable(read_dynamx(fpath)) cls.pmt.set_control(('Full deuteration control', 0.167)) d = cls.pmt.get_state('SecB WT apo') cls.temperature, cls.pH = 273.15 + 30, 8. cls.series = HDXMeasurement(d, temperature=cls.temperature, pH=cls.pH)
def setup_class(cls): fpath = input_dir / 'ecSecB_apo.csv' cls.pmt = PeptideMasterTable(read_dynamx(fpath)) data = cls.pmt.get_state('SecB WT apo') cls.hdxm = HDXMeasurement(data) cls.sequence = 'MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLGEETAFLCEVQQGGIFSIAGIEGTQM' \ 'AHCLGAYCPNILFPYARECITSMVSRGTFPQLNLAPVNFDALFMNYLQQQAGEGTEEHQDA'
def setup_class(cls): fpath = directory / 'test_data' / 'ecSecB_apo.csv' cls.pmt = PeptideMasterTable(read_dynamx(fpath)) d = cls.pmt.groupby_state() cls.series = d['SecB WT apo'] cls.sequence = 'MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLGEETAFLCEVQQGGIFSIAGIEGTQM' \ 'AHCLGAYCPNILFPYARECITSMVSRGTFPQLNLAPVNFDALFMNYLQQQAGEGTEEHQDA'
def setup_class(cls): dtype = [('r_number', int), ('apple', float)] array1 = np.empty(15, dtype=dtype) array1['r_number'] = np.arange(15) + 3 array1['apple'] = np.ones(15) * 12 cls.array1 = array1 dtype = [('r_number', int), ('apple', float), ('grapes', float)] array2 = np.empty(17, dtype=dtype) array2['r_number'] = np.arange(17) + 6 array2['apple'] = np.ones(17) * 10 array2['grapes'] = np.ones(17) * 15 + np.random.rand(17) cls.array2 = array2 dtype = [('r_number', int), ('pear', float), ('banana', float)] array3 = np.empty(10, dtype=dtype) array3['r_number'] = np.arange(10) + 1 array3['pear'] = np.random.rand(10) + 20 array3['banana'] = -(np.random.rand(10) + 20) cls.array3 = array3 metadata = { 'temperature': 273.15, 'pH': 7.5, 'mutations': ['V123S', 'P234S'] } cls.protein = csv_to_protein(output_dir / 'ecSecB_info.csv') cls.protein.metadata = metadata fpath = input_dir / 'ecSecB_apo.csv' pf1 = PeptideMasterTable(read_dynamx(fpath)) cls.series = HDXMeasurement(pf1.get_state('SecB WT apo'), c_term=200)
def load_from_yaml(yaml_dict, data_dir=None): #name: load what from yaml? """ Creates a :class:`~pyhdx.fitting.KineticsFitting` object from dictionary input. Dictionary can be generated from .yaml format and should specifiy Parameters ---------- yaml_dict : :obj:`dict` Input dictionary specifying metadata and file location to load data_dir : :obj:`str` or pathlib.Path object Returns ------- kf : :class:`~pyhdx.fititng.KineticsFitting` :class:`~pyhdx.fititng.KineticsFitting` class as specified by input dict. """ if data_dir is not None: input_files = [Path(data_dir) / fname for fname in yaml_dict['filenames']] else: input_files = yaml_dict['filenames'] data = read_dynamx(*input_files) pmt = PeptideMasterTable(data, d_percentage=yaml_dict['d_percentage']) #todo add proline, n_term options if 'control' in yaml_dict.keys(): # Use a FD control for back exchange correction pmt.set_control(tuple(yaml_dict['control'])) elif 'be_percent' in yaml_dict.keys(): # Flat back exchange percentage for all peptides\ pmt.set_backexchange(yaml_dict['be_percent']) else: raise ValueError('No valid back exchange control method specified') try: c_term = yaml_dict.get('c_term', 0) or len(yaml_dict['sequence']) + 1 except KeyError: raise ValueError("Must specify either 'c_term' or 'sequence'") states = pmt.groupby_state(c_term=c_term) series = states[yaml_dict['series_name']] if yaml_dict['temperature_unit'].lower() == 'celsius': temperature = yaml_dict['temperature'] + 273.15 elif yaml_dict['temperature_unit'].lower() == 'kelvin': temperature = yaml_dict['temperature'] else: raise ValueError("Invalid option for 'temperature_unit', must be 'Celsius' or 'Kelvin'") kf = KineticsFitting(series, temperature=temperature, pH=yaml_dict['pH']) return kf
def setup_class(cls): cls.fpath = input_dir / 'ecSecB_apo.csv' data = read_dynamx(cls.fpath) control = ('Full deuteration control', 0.167*60) cls.temperature, cls.pH = 273.15 + 30, 8. pf = PeptideMasterTable(data, drop_first=1, ignore_prolines=True, remove_nan=False) pf.set_control(control) cls.hdxm = HDXMeasurement(pf.get_state('SecB WT apo'), temperature=cls.temperature, pH=cls.pH) initial_rates = csv_to_dataframe(output_dir / 'ecSecB_guess.csv') gibbs_guess = cls.hdxm.guess_deltaG(initial_rates['rate']) cls.fit_result = fit_gibbs_global(cls.hdxm, gibbs_guess, epochs=100, r1=2)
def setup_class(cls): fpath_apo = os.path.join(directory, 'test_data', 'ecSecB_apo.csv') fpath_dimer = os.path.join(directory, 'test_data', 'ecSecB_dimer.csv') data = read_dynamx(fpath_apo, fpath_dimer) control = ('Full deuteration control', 0.167) cls.temperature, cls.pH = 273.15 + 30, 8. pf = PeptideMasterTable(data, drop_first=1, ignore_prolines=True, remove_nan=False) pf.set_control(control) states = pf.groupby_state() cls.series_apo = states['SecB WT apo'] cls.series_dimer = states['SecB his dimer apo']
def load_folding_from_yaml(yaml_dict, data_dir=None): #name: load what from yaml? """ Creates a :class:`~pyhdx.fitting.KineticsFitting` object from dictionary input. Dictionary can be generated from .yaml format and should specifiy Parameters ---------- yaml_dict : :obj:`dict` Input dictionary specifying metadata and file location to load data_dir : :obj:`str` or pathlib.Path object Returns ------- kf : :class:`~pyhdx.fititng.KineticsFitting` :class:`~pyhdx.fititng.KineticsFitting` class as specified by input dict. """ if data_dir is not None: input_files = [Path(data_dir) / fname for fname in yaml_dict['filenames']] else: input_files = yaml_dict['filenames'] data = read_dynamx(*input_files) pmt = PeptideMasterTable(data, d_percentage=yaml_dict['d_percentage']) #todo add proline, n_term options #todo merge this with the other func where it checks for control names to determine what to apply pmt.set_control(control_100=tuple(yaml_dict['control_100']), control_0=tuple(yaml_dict['control_0'])) try: c_term = yaml_dict.get('c_term', 0) or len(yaml_dict['sequence']) + 1 except KeyError: raise ValueError("Must specify either 'c_term' or 'sequence'") states = pmt.groupby_state(c_term=c_term) series = states[yaml_dict['series_name']] if yaml_dict['temperature_unit'].lower() == 'celsius': temperature = yaml_dict['temperature'] + 273.15 elif yaml_dict['temperature_unit'].lower() == 'kelvin': temperature = yaml_dict['temperature'] else: raise ValueError("Invalid option for 'temperature_unit', must be 'Celsius' or 'Kelvin'") kf = KineticsFitting(series, temperature=temperature, pH=yaml_dict['pH']) return kf
def load_folding_from_yaml(yaml_dict, data_dir=None): #name: load what from yaml? """ """ raise NotImplementedError( 'Loading folding data from yaml currently not implemented') if data_dir is not None: input_files = [ Path(data_dir) / fname for fname in yaml_dict['filenames'] ] else: input_files = yaml_dict['filenames'] data = read_dynamx(*input_files) pmt = PeptideMasterTable(data, d_percentage=yaml_dict['d_percentage'] ) #todo add proline, n_term options #todo merge this with the other func where it checks for control names to determine what to apply pmt.set_control(control_1=tuple(yaml_dict['control_1']), control_0=tuple(yaml_dict['control_0'])) try: c_term = yaml_dict.get('c_term', 0) or len(yaml_dict['sequence']) + 1 except KeyError: raise ValueError("Must specify either 'c_term' or 'sequence'") states = pmt.groupby_state(c_term=c_term) series = states[yaml_dict['series_name']] if yaml_dict['temperature_unit'].lower() == 'celsius': temperature = yaml_dict['temperature'] + 273.15 elif yaml_dict['temperature_unit'].lower() == 'kelvin': temperature = yaml_dict['temperature'] else: raise ValueError( "Invalid option for 'temperature_unit', must be 'Celsius' or 'Kelvin'" ) kf = KineticsFitting(series, temperature=temperature, pH=yaml_dict['pH']) return kf
def test_fmt_export(self): # testing fmt_export data = read_dynamx(self.fpath) with pytest.raises(ValueError): fmt_export(data, delimiter=',', width="foo") fmt, hdr = fmt_export(data, delimiter=',', width=0) assert 'protein' in hdr fmt, hdr = fmt_export(data, delimiter=',', width='auto') assert 'protein' in hdr fmt, hdr = fmt_export(data, header=False) assert len(hdr) == 0 data = np.genfromtxt(self.fpath, skip_header=1, delimiter=',', dtype=[('foo', 'V'), ('bar', 'V')]) with pytest.raises(TypeError): fmt_export(data, delimiter=',', width=0)
def test_read_dynamx(self): data = read_dynamx(self.fpath) assert data.size == 567 assert data['start'][0] == 9 assert data['end'][0] == 18 data = read_dynamx(self.fpath, intervals=('exclusive', 'inclusive')) assert data['start'][0] == 10 data = read_dynamx(self.fpath, intervals=('inclusive', 'exclusive')) assert data['end'][0] == 17 with pytest.raises(ValueError): data = read_dynamx(self.fpath, intervals=('foo', 'inclusive')) with pytest.raises(ValueError): data = read_dynamx(self.fpath, intervals=('inclusive', 'bar')) with open(self.fpath, mode='r') as f: data = read_dynamx(StringIO(f.read())) assert data.size == 567
def test_read_dynamx(self): df = read_dynamx(self.fpath) assert df.shape[0] == 567 assert df['start'][0] == 9 assert df['end'][0] == 18 df = read_dynamx(self.fpath, intervals=('exclusive', 'inclusive')) assert df['start'][0] == 10 assert np.sum(df['exposure']) == 441632.55024 assert np.sum(df['uptake']) == 1910.589614 df = read_dynamx(self.fpath, intervals=('inclusive', 'exclusive')) assert df['end'][0] == 17 with pytest.raises(ValueError): df = read_dynamx(self.fpath, intervals=('foo', 'inclusive')) with pytest.raises(ValueError): df = read_dynamx(self.fpath, intervals=('inclusive', 'bar')) with open(self.fpath, mode='r') as f: df = read_dynamx(StringIO(f.read())) assert df.shape[0] == 567
def setup_class(cls): fpath = directory / 'test_data' / 'ecSecB_apo.csv' cls.pf1 = PeptideMasterTable(read_dynamx(fpath))
def load_from_yaml_v040b2(yaml_dict, data_dir=None, **kwargs): # pragma: no cover """ This is the legacy version to load yaml files of PyHDX v0.4.0b2 Creates a :class:`~pyhdx.models.HDXMeasurement` object from dictionary input. Dictionary can be generated from .yaml format. See templates/yaml_files/SecB.yaml for format specification. Parameters ---------- yaml_dict : :obj:`dict` Input dictionary specifying experimental metadata and file location to load data_dir : :obj:`str` or pathlib.Path object Returns ------- hdxm : :class:`~pyhdx.models.HDXMeasurement` Output data object as specified by `yaml_dict`. """ if data_dir is not None: input_files = [ Path(data_dir) / fname for fname in yaml_dict["filenames"] ] else: input_files = yaml_dict["filenames"] data = read_dynamx(*input_files) pmt = PeptideMasterTable(data, d_percentage=yaml_dict["d_percentage"] ) # todo add proline, n_term options if "control" in yaml_dict.keys( ): # Use a FD control for back exchange correction pmt.set_control(tuple(yaml_dict["control"])) elif ("be_percent" in yaml_dict.keys() ): # Flat back exchange percentage for all peptides\ pmt.set_backexchange(yaml_dict["be_percent"]) else: raise ValueError("No valid back exchange control method specified") if yaml_dict["temperature_unit"].lower() == "celsius": temperature = yaml_dict["temperature"] + 273.15 elif yaml_dict["temperature_unit"].lower() == "kelvin": temperature = yaml_dict["temperature"] else: raise ValueError( "Invalid option for 'temperature_unit', must be 'Celsius' or 'Kelvin'" ) sequence = yaml_dict.get("sequence", "") c_term = yaml_dict.get("c_term", 0) n_term = yaml_dict.get("n_term", 1) if not (c_term or sequence): raise ValueError("Must specify either 'c_term' or 'sequence'") state_data = pmt.get_state([yaml_dict["series_name"]]) hdxm = HDXMeasurement(state_data, temperature=temperature, pH=yaml_dict["pH"], sequence=sequence, n_term=n_term, c_term=c_term, **kwargs) return hdxm
def load_from_yaml(yaml_dict, data_dir=None, **kwargs): #name: load what from yaml? #todo perhas classmethod on HDXMeasurement object? """ Creates a :class:`~pyhdx.models.HDXMeasurement` object from dictionary input. Dictionary can be generated from .yaml format and should specify Parameters ---------- yaml_dict : :obj:`dict` Input dictionary specifying metadata and file location to load data_dir : :obj:`str` or pathlib.Path object Returns ------- hdxm : :class:`~pyhdx.models.HDXMeasurement` Output data object as specified by `yaml_dict`. """ if data_dir is not None: input_files = [ Path(data_dir) / fname for fname in yaml_dict['filenames'] ] else: input_files = yaml_dict['filenames'] data = read_dynamx(*input_files) pmt = PeptideMasterTable(data, d_percentage=yaml_dict['d_percentage'] ) #todo add proline, n_term options if 'control' in yaml_dict.keys( ): # Use a FD control for back exchange correction pmt.set_control(tuple(yaml_dict['control'])) elif 'be_percent' in yaml_dict.keys( ): # Flat back exchange percentage for all peptides\ pmt.set_backexchange(yaml_dict['be_percent']) else: raise ValueError('No valid back exchange control method specified') if yaml_dict['temperature_unit'].lower() == 'celsius': temperature = yaml_dict['temperature'] + 273.15 elif yaml_dict['temperature_unit'].lower() == 'kelvin': temperature = yaml_dict['temperature'] else: raise ValueError( "Invalid option for 'temperature_unit', must be 'Celsius' or 'Kelvin'" ) sequence = yaml_dict.get('sequence', '') c_term = yaml_dict.get('c_term', 0) n_term = yaml_dict.get('n_term', 1) if not (c_term or sequence): raise ValueError("Must specify either 'c_term' or 'sequence'") state_data = pmt.get_state([yaml_dict['series_name']]) hdxm = HDXMeasurement(state_data, temperature=temperature, pH=yaml_dict['pH'], sequence=sequence, n_term=n_term, c_term=c_term, **kwargs) return hdxm
def yaml_to_hdxm(yaml_dict, data_dir=None, data_filters=None, **kwargs): # todo perhas classmethod on HDXMeasurement object? """ Creates a :class:`~pyhdx.models.HDXMeasurement` object from dictionary input. Dictionary can be generated from .yaml format. See templates/yaml_files/SecB.yaml for format specification. Parameters ---------- yaml_dict : :obj:`dict` Input dictionary specifying experimental metadata and file location to load data_dir : :obj:`str` or pathlib.Path object Returns ------- hdxm : :class:`~pyhdx.models.HDXMeasurement` Output data object as specified by `yaml_dict`. """ if data_dir is not None: input_files = [ Path(data_dir) / fname for fname in yaml_dict["filenames"] ] else: input_files = yaml_dict["filenames"] data = read_dynamx(*input_files) pmt = PeptideMasterTable(data, drop_first=yaml_dict.get('drop_first', 1), d_percentage=yaml_dict['d_percentage'] ) #todo add proline, n_term options if 'control' in yaml_dict.keys( ): # Use a FD control for back exchange correction # todo control should be set from an external file control_state = yaml_dict["control"]["state"] exposure_value = yaml_dict["control"]["exposure"]["value"] exposure_units = yaml_dict["control"]["exposure"]["unit"] control_exposure = exposure_value * time_factors[exposure_units] pmt.set_control((control_state, control_exposure)) elif ("be_percent" in yaml_dict.keys() ): # Flat back exchange percentage for all peptides\ pmt.set_backexchange(yaml_dict["be_percent"]) else: raise ValueError("No valid back exchange control method specified") temperature = yaml_dict["temperature"]["value"] try: t_offset = temperature_offsets[yaml_dict["temperature"]["unit"]] except KeyError: t_offset = temperature_offsets[yaml_dict["temperature"] ["unit"].lower()] temperature += t_offset sequence = yaml_dict.get("sequence", "") c_term = yaml_dict.get("c_term") n_term = yaml_dict.get("n_term") or 1 if not (c_term or sequence): raise ValueError("Must specify either 'c_term' or 'sequence'") state_data = pmt.get_state(yaml_dict["state"]) data_filters = data_filters or [] for filter in data_filters: state_data = filter(state_data) hdxm = HDXMeasurement(state_data, temperature=temperature, pH=yaml_dict["pH"], sequence=sequence, n_term=n_term, c_term=c_term, **kwargs) return hdxm
def setup_class(cls): fpath = input_dir / 'ecSecB_apo.csv' cls.pmt = PeptideMasterTable(read_dynamx(fpath))
"""Run this file to renew the fit results which is used to test against""" torch.manual_seed(43) np.random.seed(43) epochs = 1000 sequence = 'MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLGEETAFLCEVQQGGIFSIAGIEGTQMAHCLGAYCPNILFPYARECITSMVSRGTFPQLNLAPVNFDALFMNYLQQQAGEGTEEHQDA' sequence_dimer = 'MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLGEETAFLCEVQQGGIFSIAGIEGTQMAHCLGAYCPNILFPAARECIASMVARGTFPQLNLAPVNFDALFMNYLQQQAGEGTEEHQDA' 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')
def setup_class(cls): fpath = directory / 'test_data' / 'ecSecB_apo.csv' cls.pmt = PeptideMasterTable(read_dynamx(fpath)) d = cls.pmt.groupby_state() cls.series = d['SecB WT apo']
from pyhdx.alignment import align_dataframes import numpy as np mock_alignment = { 'dimer': 'MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVY--------------EVVLRVTVTASLGEETAFLCEVQQGGIFSIAGIEGTQMAHCLGA----YCPNILFPAARECIASMVARGTFPQLNLAPVNFDALFMNYLQQQAGEGTEEHQDA-----------------', 'apo': 'MSEQNNTEMTFQIQRIYTKDI------------SFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLG-------------------EETAFLCEVQQGGIFSIAGIEGTQMAHCLGAYCPNILFPYARECITSMVSRG----TFPQLNLAPVNFDALFMNYLQQQAGEGTEEHQDA', } current_dir = Path(__file__).parent output_dir = current_dir / 'output' output_dir.mkdir(exist_ok=True) test_data_dir = current_dir.parent / 'tests' / 'test_data' input_dir = test_data_dir / 'input' data = read_dynamx(input_dir / 'ecSecB_apo.csv', input_dir / 'ecSecB_dimer.csv') pmt = PeptideMasterTable(data) pmt.set_control(('Full deuteration control', 0.167 * 60)) st1 = HDXMeasurement(pmt.get_state('SecB his dimer apo'), pH=8, temperature=273.15 + 30) st2 = HDXMeasurement(pmt.get_state('SecB WT apo'), pH=8, temperature=273.15 + 30) guess = csv_to_protein(test_data_dir / 'output' / 'ecSecB_guess.csv') hdx_set = HDXMeasurementSet([st1, st2]) gibbs_guess = hdx_set.guess_deltaG([guess['rate'], guess['rate']])
import matplotlib.pyplot as plt import numpy as np from matplotlib import cm from pyhdx.fileIO import csv_to_protein, read_dynamx, dataframe_to_file, save_fitresult from pyhdx.fitting import fit_gibbs_global_batch from pyhdx.fitting_torch import CheckPoint from pyhdx.models import PeptideMasterTable, HDXMeasurement, HDXMeasurementSet current_dir = Path(__file__).parent #current_dir = Path().cwd() / 'templates' # pycharm scientific compat output_dir = current_dir / 'output' output_dir.mkdir(exist_ok=True) data_dir = current_dir.parent / 'tests' / 'test_data' data = read_dynamx(data_dir / 'input' / 'ecSecB_apo.csv', data_dir / 'input' / 'ecSecB_dimer.csv') pmt = PeptideMasterTable(data) pmt.set_control(('Full deuteration control', 0.167*60)) st1 = HDXMeasurement(pmt.get_state('SecB his dimer apo'), pH=8, temperature=273.15 + 30) st2 = HDXMeasurement(pmt.get_state('SecB WT apo'), pH=8, temperature=273.15 + 30) hdx_set = HDXMeasurementSet([st1, st2]) guess = csv_to_protein(data_dir / 'output' / 'ecSecB_guess.csv') gibbs_guess = hdx_set[0].guess_deltaG(guess['rate']) # Example fit with only 5000 epochs and high learning rate # Checkpoint stores model history every `epoch_step` epochs checkpoint = CheckPoint(epoch_step=250)
from pyhdx.fileIO import read_dynamx, txt_to_np, fmt_export from pyhdx.models import PeptideMasterTable from numpy.lib.recfunctions import append_fields import numpy as np array = txt_to_np('test_data/simulated_data.csv', delimiter=',') data = read_dynamx('test_data/simulated_data.csv') print(array.dtype.names) print(data.dtype.names) pmt = PeptideMasterTable(array, drop_first=0, ignore_prolines=False, remove_nan=False) print(pmt.data.dtype.names) uptake = pmt.data['ex_residues'] * pmt.data['scores'] / 100 for u, m in zip(uptake, pmt.data['ex_residues']): print(u, m) extended = append_fields(pmt.data, ['uptake'], [uptake], usemask=False) fields = ('start', 'end', 'exposure', 'state', 'sequence', 'ex_residues', 'uptake') dtype = [(name, extended[name].dtype) for name in fields] export = np.empty_like(uptake, dtype=dtype) for name in fields: export[name] = extended[name] fmt, hdr = fmt_export(export, delimiter=',', width=0) np.savetxt('test.txt', export, fmt=fmt, header=hdr) new_data = read_dynamx('test.txt')