Skip to content

Commit 5b21c26

Browse files
authored
Merge pull request #232 from Jhsmit/web_plots
Plot updates
2 parents 6bdc32c + 43629d1 commit 5b21c26

27 files changed

+2195
-743
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
pip install codecov
2424
pip install pytest
2525
pip install pytest-cov
26-
pip install -r requirements.txt
27-
pip install -e .
26+
pip install -e .[web,pdf]
2827
- name: Test with pytest
2928
run: |
3029
pytest --cov=./

dev/gui/dev_gui_secB.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,58 @@
99
import pickle
1010
from pyhdx.web.apps import main_app
1111
from pyhdx.web.base import DEFAULT_COLORS, STATIC_DIR
12+
from pyhdx.web.utils import load_state
1213
from pyhdx.web.sources import DataSource
1314
from pyhdx.batch_processing import yaml_to_hdxm
1415
from pyhdx.fileIO import csv_to_protein
1516
import panel as pn
1617
import numpy as np
1718
from pathlib import Path
1819
import pandas as pd
20+
import yaml
1921

2022
ctrl = main_app()
2123
directory = Path(__file__).parent
2224
root_dir = directory.parent.parent
23-
data_dir = root_dir / 'tests' / 'test_data'
25+
data_dir = root_dir / 'tests' / 'test_data' / 'input'
2426
test_dir = directory / 'test_data'
2527

2628
fpath_1 = root_dir / 'tests' / 'test_data' / 'ecSecB_apo.csv'
2729
fpath_2 = root_dir / 'tests' / 'test_data' / 'ecSecB_dimer.csv'
2830

29-
fpaths = [fpath_1, fpath_2]
30-
files = [p.read_bytes() for p in fpaths]
31+
yaml_dict = yaml.safe_load(Path(data_dir / 'data_states.yaml').read_text())
3132

33+
# fpaths = [fpath_1, fpath_2]
34+
# files = [p.read_bytes() for p in fpaths]
35+
#
36+
#
37+
# d1 = {
38+
# 'filenames': ['ecSecB_apo.csv', 'ecSecB_dimer.csv'],
39+
# 'd_percentage': 95,
40+
# 'control': ('Full deuteration control', 0.167),
41+
# 'series_name': 'SecB WT apo',
42+
# 'temperature': 30,
43+
# 'temperature_unit': 'celsius',
44+
# 'pH': 8.,
45+
# 'c_term': 165
46+
# }
47+
#
48+
# d2 = {
49+
# 'filenames': ['ecSecB_apo.csv', 'ecSecB_dimer.csv'],
50+
# 'd_percentage': 95,
51+
# 'control': ('Full deuteration control', 0.167),
52+
# 'series_name': 'SecB his dimer apo',
53+
# 'temperature': 30,
54+
# 'temperature_unit': 'celsius',
55+
# 'pH': 8.,
56+
# 'c_term': 165
57+
# }
3258

33-
d1 = {
34-
'filenames': ['ecSecB_apo.csv', 'ecSecB_dimer.csv'],
35-
'd_percentage': 95,
36-
'control': ('Full deuteration control', 0.167),
37-
'series_name': 'SecB WT apo',
38-
'temperature': 30,
39-
'temperature_unit': 'celsius',
40-
'pH': 8.,
41-
'c_term': 165
42-
}
43-
44-
d2 = {
45-
'filenames': ['ecSecB_apo.csv', 'ecSecB_dimer.csv'],
46-
'd_percentage': 95,
47-
'control': ('Full deuteration control', 0.167),
48-
'series_name': 'SecB his dimer apo',
49-
'temperature': 30,
50-
'temperature_unit': 'celsius',
51-
'pH': 8.,
52-
'c_term': 165
53-
}
54-
55-
yaml_dicts = {'testname_123': d1, 'SecB his dimer apo': d2}
59+
#yaml_dicts = {'testname_123': d1, 'SecB his dimer apo': d2}
5660

5761

5862
def reload_dashboard():
59-
data_objs = {k: yaml_to_hdxm(v, data_dir=data_dir) for k, v in yaml_dicts.items()}
63+
data_objs = {k: yaml_to_hdxm(v, data_dir=data_dir) for k, v in yaml_dict.items()}
6064
for k, v in data_objs.items():
6165
v.metadata['name'] = k
6266
ctrl.data_objects = data_objs
@@ -96,21 +100,24 @@ def reload_dashboard():
96100

97101

98102
def init_dashboard():
99-
file_input = ctrl.control_panels['PeptideFileInputControl']
100-
file_input.input_files = files
101-
file_input.fd_state = 'Full deuteration control'
102-
file_input.fd_exposure = 0.167*60
103-
file_input.pH = 8
104-
file_input.temperature = 273.15 + 30
105-
file_input.d_percentage = 90.
106-
107-
file_input.exp_state = 'SecB WT apo'
108-
file_input.dataset_name = 'SecB_tetramer'
109-
file_input._action_add_dataset()
110-
111-
file_input.exp_state = 'SecB his dimer apo'
112-
file_input.dataset_name = 'SecB_dimer' # todo catch error duplicate name
113-
file_input._action_add_dataset()
103+
for k, v in yaml_dict.items():
104+
load_state(ctrl, v, data_dir=data_dir, name=k)
105+
106+
# file_input = ctrl.control_panels['PeptideFileInputControl']
107+
# file_input.input_files = files
108+
# file_input.fd_state = 'Full deuteration control'
109+
# file_input.fd_exposure = 0.167*60
110+
# file_input.pH = 8
111+
# file_input.temperature = 273.15 + 30
112+
# file_input.d_percentage = 90.
113+
#
114+
# file_input.exp_state = 'SecB WT apo'
115+
# file_input.dataset_name = 'SecB_tetramer'
116+
# file_input._action_add_dataset()
117+
#
118+
# file_input.exp_state = 'SecB his dimer apo'
119+
# file_input.dataset_name = 'SecB_dimer' # todo catch error duplicate name
120+
# file_input._action_add_dataset()
114121

115122
# initial_guess = ctrl.control_panels['InitialGuessControl']
116123
# initial_guess._action_fit()

docs/examples/01_basic_usage.ipynb

Lines changed: 39 additions & 32 deletions
Large diffs are not rendered by default.

docs/examples/04_exporting_output.ipynb

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/examples/04_plot_output.ipynb

Lines changed: 433 additions & 0 deletions
Large diffs are not rendered by default.

pyhdx/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from .models import PeptideMasterTable, PeptideMeasurements, HDXMeasurement, Coverage, HDXMeasurementSet
1+
from .models import PeptideMasterTable, HDXTimepoint, HDXMeasurement, Coverage, HDXMeasurementSet
22
from .fileIO import read_dynamx
3-
from .fitting_torch import TorchSingleFitResult, TorchBatchFitResult
3+
from .fitting_torch import TorchFitResult
44
from ._version import get_versions
55

66
try:
7-
from .output import Output, Report
7+
from .output import FitReport
88
except ModuleNotFoundError:
99
pass
1010

pyhdx/batch_processing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55

66
time_factors = {"s": 1, "m": 60., "min": 60., "h": 3600, "d": 86400}
7-
temperature_offsets = {'C': 273.15, 'celsius': 273.15, 'K': 0, 'kelvin': 0}
7+
temperature_offsets = {'c': 273.15, 'celsius': 273.15, 'k': 0, 'kelvin': 0}
8+
89

910
def yaml_to_hdxmset(yaml_dict, data_dir=None, **kwargs):
1011
"""reads files according to `yaml_dict` spec from `data_dir into HDXMEasurementSet"""

pyhdx/config.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@ n_workers = 10
55
[fitting]
66
dtype = float64
77
device = cpu
8+
9+
[plotting]
10+
# Sizes are in mm
11+
ncols = 2
12+
page_width = 160
13+
cbar_width = 2.5
14+
peptide_coverage_aspect = 3
15+
peptide_mse_aspect = 3
16+
residue_scatter_aspect = 3
17+
deltaG_aspect = 2.5
18+
linear_bars_aspect=30
19+
loss_aspect = 2.5
20+
rainbow_aspect = 4

pyhdx/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def get(self, *args, **kwargs):
7474
"""configparser get"""
7575
return self._config.get(*args, **kwargs)
7676

77+
def getint(self, *args, **kwargs):
78+
return self._config.getint(*args, **kwargs)
79+
80+
def getfloat(self, *args, **kwargs):
81+
return self._config.getfloat(*args, **kwargs)
82+
83+
def getboolean(self, *args, **kwargs):
84+
return self._config.getboolean(*args, **kwargs)
85+
7786
def set(self, *args, **kwargs):
7887
"""configparser set"""
7988
self._config.set(*args, **kwargs)

pyhdx/fileIO.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
PEPTIDE_DTYPES = {
1919
'start': int,
2020
'end': int,
21+
'_start': int,
22+
'_end': int
2123
}
2224

2325

@@ -196,7 +198,7 @@ def csv_to_hdxm(filepath_or_buffer, comment='#', **kwargs):
196198
if df.columns.nlevels == 2:
197199
hdxm_list = []
198200
for state in df.columns.unique(level=0):
199-
subdf = df[state].dropna(how='all')
201+
subdf = df[state].dropna(how='all').astype(PEPTIDE_DTYPES)
200202
m = metadata.get(state, {})
201203
hdxm = pyhdx.models.HDXMeasurement(subdf, **m)
202204
hdxm_list.append(hdxm)
@@ -343,10 +345,10 @@ def save_fitresult(output_dir, fit_result, log_lines=None):
343345
dataframe_to_file(output_dir / 'losses.csv', fit_result.losses)
344346
dataframe_to_file(output_dir / 'losses.txt', fit_result.losses, fmt='pprint')
345347

346-
if isinstance(fit_result.data_obj, pyhdx.HDXMeasurement):
347-
fit_result.data_obj.to_file(output_dir / 'HDXMeasurement.csv')
348-
if isinstance(fit_result.data_obj, pyhdx.HDXMeasurementSet):
349-
fit_result.data_obj.to_file(output_dir / 'HDXMeasurements.csv')
348+
if isinstance(fit_result.hdxm_set, pyhdx.HDXMeasurement):
349+
fit_result.hdxm_set.to_file(output_dir / 'HDXMeasurement.csv')
350+
if isinstance(fit_result.hdxm_set, pyhdx.HDXMeasurementSet):
351+
fit_result.hdxm_set.to_file(output_dir / 'HDXMeasurements.csv')
350352

351353
loss = f'Total_loss {fit_result.total_loss:.2f}, mse_loss {fit_result.mse_loss:.2f}, reg_loss {fit_result.reg_loss:.2f}' \
352354
f'({fit_result.regularization_percentage:.2f}%)'
@@ -379,12 +381,9 @@ def load_fitresult(fit_dir):
379381
if pth.is_dir():
380382
fit_result = csv_to_dataframe(fit_dir / 'fit_result.csv')
381383
losses = csv_to_dataframe(fit_dir / 'losses.csv')
382-
try:
383-
data_obj = csv_to_hdxm(fit_dir / 'HDXMeasurement.csv')
384-
result_klass = pyhdx.fitting_torch.TorchSingleFitResult
385-
except FileNotFoundError:
386-
data_obj = csv_to_hdxm(fit_dir / 'HDXMeasurements.csv')
387-
result_klass = pyhdx.fitting_torch.TorchBatchFitResult
384+
385+
data_obj = csv_to_hdxm(fit_dir / 'HDXMeasurements.csv')
386+
result_klass = pyhdx.fitting_torch.TorchFitResult
388387
elif pth.is_file():
389388
raise DeprecationWarning('`load_fitresult` only loads from fit result directories')
390389
fit_result = csv_to_dataframe(fit_dir)

0 commit comments

Comments
 (0)