示例#1
0
    def test_load_save_fitresult(self, tmp_path):
        #todo missing read batch result test

        fpath = Path(tmp_path) / 'fit_result_single.csv'
        self.fit_result.to_file(fpath)
        df = csv_to_dataframe(fpath)
        assert df.attrs['metadata'] == self.fit_result.metadata
        fit_result_dir = Path(tmp_path) / 'fit_result'

        save_fitresult(fit_result_dir, self.fit_result, log_lines=['test123'])

        log_lines = Path(fit_result_dir / 'log.txt').read_text().split('\n')
        assert log_lines[-1] == 'test123'

        fit_result_loaded = load_fitresult(fit_result_dir)
        assert isinstance(fit_result_loaded.losses, pd.DataFrame)
        assert isinstance(fit_result_loaded.hdxm_set, HDXMeasurementSet)

        timepoints = np.linspace(0, 30*60, num=100)
        d_calc = fit_result_loaded(timepoints)
        assert d_calc.shape == (1, self.hdxm.Np, len(timepoints))

        losses = csv_to_dataframe(fit_result_dir / 'losses.csv')
        fr_load_with_hdxm_and_losses = load_fitresult(fit_result_dir)
        assert len(fr_load_with_hdxm_and_losses.losses) == 100

        assert fr_load_with_hdxm_and_losses.metadata['total_loss'] == losses.iloc[-1].sum()
示例#2
0
"""Generate a pdf output with all peptide fits. Requires pdflatex"""
from pyhdx.output import FitReport
from pyhdx.fileIO import load_fitresult
from pathlib import Path
from concurrent import futures
import proplot as pplt

current_dir = Path().cwd()
fit_result = load_fitresult(current_dir / 'output' /
                            'SecB_tetramer_dimer_batch')

tmp_dir = Path(__file__).parent / 'temp'
tmp_dir.mkdir(exist_ok=True)

if __name__ == '__main__':

    report = FitReport(fit_result, temp_dir=tmp_dir)
    report.add_standard_figure('peptide_coverage_figure')
    report.add_standard_figure('residue_time_scatter_figure')
    report.add_standard_figure('residue_scatter_figure')
    report.add_standard_figure('dG_scatter_figure', ncols=1, aspect=3)
    report.add_standard_figure('ddG_scatter_figure', ncols=1, reference=0)
    report.add_standard_figure('linear_bars',
                               cmap='viridis',
                               norm=pplt.Norm('linear', 15e3,
                                              35e3))  #todo name from kwargs
    report.add_standard_figure('rainbowclouds')

    report.add_peptide_uptake_curves()

    executor = futures.ProcessPoolExecutor(max_workers=10)
示例#3
0
"""Load a fit result from a a directory directly ino the web interface"""
from pyhdx.fileIO import load_fitresult
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
from pyhdx.web.apps import main_app
from pyhdx.web.base import STATIC_DIR
import sys
import panel as pn

current_dir = Path(__file__).parent
fit_result = load_fitresult(current_dir.parent / 'tests' / 'test_data' /
                            'output' / 'ecsecb_tetramer_dimer')

ctrl, tmpl = main_app()

src = ctrl.sources['main']
for hdxm in fit_result.hdxm_set:
    src.add(hdxm, hdxm.name)
src.add(fit_result, 'fitresult_1')

pn.serve(tmpl, show=True, static_dirs={'pyhdx': STATIC_DIR})
示例#4
0
"""
Automagically plot all available figures from a fit result
"""

from pyhdx.fileIO import load_fitresult
from pyhdx.plot import FitResultPlot
from pathlib import Path

#%%

# __file__ = Path().cwd() / 'templates'/ 'script.py'  # Uncomment for PyCharm scientific mode

cwd = Path(__file__).parent
output_dir = cwd / 'output' / 'figures'
output_dir.mkdir(exist_ok=True)
fit_result = load_fitresult(cwd / 'output' / 'SecB_tetramer_dimer_batch')

fr_plot = FitResultPlot(fit_result, output_path=output_dir)

kwargs = {
    'residue_scatter': {
        'cmap': 'BuGn'
    },  # change default colormap
    'ddG_scatter': {
        'reference': 1
    }  # Set reference for ΔΔG to the second (index 1 state) (+ APO state (tetramer))
}

fr_plot.plot_all(**kwargs)