Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tests and add CI testing #2

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:


jobs:
test:
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

runs-on: ubuntu-20.04

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .
pip install pytest

- name: Run tests
run: pytest
199 changes: 141 additions & 58 deletions tests/test_hdxrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,146 @@
from itertools import combinations
from operator import add

import pytest

pth = Path(__file__).parent

class TestHDXrate(object):
"""Tests for `hdxrate` package."""

@classmethod
def setup_class(cls):
cls.seq1 = list('AAAWADEAA')

k_reference = {'D': 3.87, 'E': 4.33, 'H': 7.0} # DH
dict = get_side_chain_dictionary(278, 8, k_reference)
one_letter = [k for k in dict.keys() if len(k) == 1]
cls.seq2 = reduce(add, [a + b for a, b in combinations(one_letter, 2)])

cls.seq2 = np.genfromtxt(pth / 'sequence.txt', dtype='U')

def test_seq1(self):
# HD rates
pH_read = 6.6
temp = 279
rates = k_int_from_sequence(self.seq1, temp, pH_read, reference='poly', wildcard='X') * 60
# Reference rates obtained from Englander group xls sheet
ref_rates = np.array([np.inf, 1.29939811E+03, 3.11703908E+01, 1.21266892E+01, 2.41959255E+01, 3.95805093E+01,
1.63948783E+01, 2.25232682E+01, 4.94028674E-01])
assert np.allclose(rates, ref_rates)

# DH rates
pH_read = 7.0
temp = 278
rates = k_int_from_sequence(self.seq1, temp, pH_read, exchange_type='DH', reference='poly') * 60
# Reference rates obtained from Englander group xls sheet
ref_rates = np.array([np.inf, 5.831286065E+03, 1.398828104E+02, 5.442072826E+01, 1.085836280E+02,
1.764790873E+02, 7.219785837E+01, 9.955072660E+01, 2.216999376E+00])
assert np.allclose(rates, ref_rates)

#HH rates
pH_read = 7.0
temp = 278
rates = k_int_from_sequence(self.seq1, temp, pH_read, exchange_type='HH', reference='poly', wildcard='X') * 60
# Reference rates obtained from Englander group xls sheet
ref_rates = np.array([np.inf, 7.01071144E+03, 1.68175255E+02, 6.54277663E+01, 1.30545556E+02, 2.12183978E+02,
8.68187188E+01, 1.19715146E+02, 2.66540425E+00])
assert np.allclose(rates, ref_rates)

def test_seq2(self):
reference_rates = np.genfromtxt(pth / 'exchange_rates_xls.txt', skip_header=2,
delimiter='\t', filling_values=0.)

reference_rates[0][:] = np.inf

#HD exchange
rates = k_int_from_sequence(self.seq2, 279, 7 - 0.4, exchange_type='HD') * 60
assert np.allclose(rates, reference_rates[:, 0], rtol=0.1, equal_nan=True)

#
rates = k_int_from_sequence(self.seq2, 279, 7, exchange_type='DH') * 60
assert np.allclose(rates, reference_rates[:, 1], rtol=0.1, equal_nan=True)

rates = k_int_from_sequence(self.seq2, 279, 7, exchange_type='HH') * 60
assert np.allclose(rates, reference_rates[:, 2], rtol=0.1, equal_nan=True)

@pytest.fixture()
def seq1():
return list("AAAWADEAA")


@pytest.fixture()
def seq2():
"""sequence two a sequence of the pairwise combination of all side chains"""
k_reference = {"D": 3.87, "E": 4.33, "H": 7.0} # DH
chains_dict = get_side_chain_dictionary(278, 8, k_reference)
one_letter = [k for k in chains_dict.keys() if len(k) == 1]
seq2 = reduce(add, [a + b for a, b in combinations(one_letter, 2)])

return list(seq2)


def test_seq1_HD(seq1):
# HD rates
pH_read = 6.6
temp = 279
rates = (
k_int_from_sequence(seq1, temp, pH_read, reference="poly", wildcard="X") * 60
)
# Reference rates obtained from Englander group xls sheet
ref_rates = np.array(
[
np.inf,
1.29939811e03,
3.11703908e01,
1.21266892e01,
2.41959255e01,
3.95805093e01,
1.63948783e01,
2.25232682e01,
4.94028674e-01,
]
)
assert np.allclose(rates, ref_rates)


def test_seq1_DH(seq1):
# DH rates
pH_read = 7.0
temp = 278
rates = (
k_int_from_sequence(seq1, temp, pH_read, exchange_type="DH", reference="poly")
* 60
)
# check repeated calls give the same result
rep_rates = (
k_int_from_sequence(seq1, temp, pH_read, exchange_type="DH", reference="poly")
* 60
)
# Reference rates obtained from Englander group xls sheet
ref_rates = np.array(
[
np.inf,
5.831286065e03,
1.398828104e02,
5.442072826e01,
1.085836280e02,
1.764790873e02,
7.219785837e01,
9.955072660e01,
2.216999376e00,
]
)
assert np.allclose(rates, ref_rates)
assert np.allclose(rates, rep_rates)


def test_seq1_HH(seq1):
# HH rates
pH_read = 7.0
temp = 278
rates = (
k_int_from_sequence(
seq1,
temp,
pH_read,
exchange_type="HH",
reference="poly",
wildcard="X",
)
* 60
)

rep_rates = (
k_int_from_sequence(
seq1,
temp,
pH_read,
exchange_type="HH",
reference="poly",
wildcard="X",
)
* 60
)

# Reference rates obtained from Englander group xls sheet
ref_rates = np.array(
[
np.inf,
7.01071144e03,
1.68175255e02,
6.54277663e01,
1.30545556e02,
2.12183978e02,
8.68187188e01,
1.19715146e02,
2.66540425e00,
]
)
assert np.allclose(rates, ref_rates)
assert np.allclose(rates, rep_rates)


def test_seq2(seq2):
reference_rates = np.genfromtxt(
pth / "exchange_rates_xls.txt",
skip_header=2,
delimiter="\t",
filling_values=0.0,
)

reference_rates[0][:] = np.inf

# HD exchange
rates = k_int_from_sequence(seq2, 279, 7 - 0.4, exchange_type="HD") * 60
assert np.allclose(rates, reference_rates[:, 0], rtol=0.1, equal_nan=True)

# DH exchange
rates = k_int_from_sequence(seq2, 279, 7, exchange_type="DH") * 60
assert np.allclose(rates, reference_rates[:, 1], rtol=0.1, equal_nan=True)

# HH exchange
rates = k_int_from_sequence(seq2, 279, 7, exchange_type="HH") * 60
assert np.allclose(rates, reference_rates[:, 2], rtol=0.1, equal_nan=True)