Skip to content

Commit

Permalink
test: correct tests and add them to CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
valentynbez committed Jun 11, 2024
1 parent a1fef38 commit 1461d8a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 18 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
CIBW_ARCHS: aarch64
CIBW_BUILD: ${{ matrix.python-tag }}
CIBW_BEFORE_BUILD: pip install cython
CIBW_TEST_COMMAND: python -m unittest mDeepFRI.tests -vv
CIBW_BUILD_VERBOSITY: 2
CIBW_TEST_REQUIRES: importlib-resources
with:
Expand All @@ -52,6 +53,7 @@ jobs:
CIBW_ARCHS: x86_64
CIBW_BUILD: ${{ matrix.python-tag }}
CIBW_BEFORE_BUILD: pip install cython
CIBW_TEST_COMMAND: python -m unittest mDeepFRI.tests -vv
CIBW_BUILD_VERBOSITY: 2
CIBW_TEST_REQUIRES: importlib-resources
with:
Expand Down Expand Up @@ -129,6 +131,8 @@ jobs:
with:
name: wheels
path: dist/*
- name: Run tests without coverage
run: python -m unittest

test-sdist:
runs-on: ubuntu-latest
Expand All @@ -149,8 +153,8 @@ jobs:
run: python -m pip install -U pip setuptools wheel
- name: Install built wheel
run: python -m pip install --no-binary mDeepFRI --find-links=dist mDeepFRI
# - name: Run tests without coverage
# run: python -m unittest mDeepFRI.tests -vv
- name: Run tests without coverage
run: python -m unittest mDeepFRI.tests -vv

upload:
environment: PyPI
Expand Down
2 changes: 1 addition & 1 deletion mDeepFRI/bio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def get_residues_coordinates(structure: np.ndarray, chain: str = "A"):
protein_chain = structure[structure.chain_id == chain]
# extract CA atoms coordinates
ca_atoms = protein_chain[(protein_chain.atom_name == "CA")
& (protein_chain.hetero is False)]
& (protein_chain.hetero is not False)]

residues = str(
ProteinSequence(
Expand Down
13 changes: 13 additions & 0 deletions mDeepFRI/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from . import (test_alignment, test_bio_utils, test_install, test_mmseqs,
test_pdb, test_predict, test_utils)


def load_tests(loader, suite, pattern):
suite.addTests(loader.loadTestsFromModule(test_alignment))
suite.addTests(loader.loadTestsFromModule(test_bio_utils))
suite.addTests(loader.loadTestsFromModule(test_install))
suite.addTests(loader.loadTestsFromModule(test_mmseqs))
suite.addTests(loader.loadTestsFromModule(test_pdb))
suite.addTests(loader.loadTestsFromModule(test_predict))
suite.addTests(loader.loadTestsFromModule(test_utils))
return suite
19 changes: 16 additions & 3 deletions mDeepFRI/tests/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pyopal

from mDeepFRI.alignment import align_pairwise, best_hit_database
from mDeepFRI.alignment import align_pairwise, best_hit_database, insert_gaps


class TestAlignment(unittest.TestCase):
Expand All @@ -26,7 +26,20 @@ def test_best_hit_database(self):
self.assertEqual(best_hit, "seq3")

def test_align_pairwise(self):
alignment = align_pairwise(self.queries["query_seq"],
self.targets["seq3"])
alignment, iden, coverage = align_pairwise(self.queries["query_seq"],
self.targets["seq3"])
self.assertEqual(alignment,
"MMMMMMMMMXMMMMMMMMMMMMMMMMMMMMMMXMMMMMMMMMMX")
self.assertAlmostEqual(iden, 0.93, places=2)
self.assertAlmostEqual(coverage, 1.0, places=2)


class TestInsertGaps(unittest.TestCase):
def test_deletion(self):
self.assertEqual(insert_gaps('AACT', 'AAT', 'MMDM'), ('AACT', 'AA-T'))

def test_insertion(self):
self.assertEqual(insert_gaps('AAT', 'AATC', 'MMMI'), ('AAT-', 'AATC'))

def test_unaligned(self):
self.assertEqual(insert_gaps('AAT', 'FGTC', 'XXMI'), ('AAT-', 'FGTC'))
13 changes: 1 addition & 12 deletions mDeepFRI/tests/test_bio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@
import numpy as np
from biotite.structure.io.pdb import PDBFile

from mDeepFRI.bio_utils import get_residues_coordinates, insert_gaps
from mDeepFRI.bio_utils import get_residues_coordinates
from mDeepFRI.contact_map_utils import pairwise_sqeuclidean


class TestInsertGaps(unittest.TestCase):
def test_deletion(self):
self.assertEqual(insert_gaps('AACT', 'AAT', 'MMDM'), ('AACT', 'AA-T'))

def test_insertion(self):
self.assertEqual(insert_gaps('AAT', 'AATC', 'MMMI'), ('AAT-', 'AATC'))

def test_unaligned(self):
self.assertEqual(insert_gaps('AAT', 'FGTC', 'XXMI'), ('AAT-', 'FGTC'))


class TestPairwiseSqeuclidean(unittest.TestCase):
def test_pairwise_sqeuclidean(self):
np.random.seed(42)
Expand Down
46 changes: 46 additions & 0 deletions mDeepFRI/tests/test_conctact_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import unittest

import numpy as np

from mDeepFRI.contact_map import CAlphaCoordinates


class TestCAlphaCoords(unittest.TestCase):
def test_init_valid_coords(self):
coords = np.array([[1, 2, 3], [4, 5, 6]])
alpha_coords = CAlphaCoordinates(coords)
assert np.array_equal(alpha_coords.coords, coords)

def test_init_invalid_dims(self):
coords = np.array([[1, 2], [3, 4]])
with self.assertRaisesRegex(ValueError, "Coordinates are not 3D."):
CAlphaCoordinates(coords)

def test_init_negative_coords(self):
coords = np.array([[-1, 2, 3], [4, 5, 6]])
with self.assertRaisesRegex(ValueError,
"Coordinates contain negative values."):
CAlphaCoordinates(coords)

def test_calculate_distance_map(self):
coords = np.array([[0, 0, 0], [1, 1, 1]])
alpha_coords = CAlphaCoordinates(coords)
distance_map = alpha_coords.calculate_distance_map(
distance="sqeuclidean")
expected_distances = np.array([[0, 3], [3, 0]], dtype=np.float32)
assert np.allclose(np.sqrt(distance_map.distance_map),
expected_distances)

def test_calculate_distance_map_invalid_function(self):
coords = np.array([[0, 0, 0], [1, 1, 1]])
alpha_coords = CAlphaCoordinates(coords)
with self.assertRaisesRegex(NotImplementedError,
"Distance metric not implemented."):
alpha_coords.calculate_distance_map(distance="euclidean")

def test_calculate_contact_map(self):
coords = np.array([[0, 0, 0], [5, 0, 0], [10, 0, 0]])
alpha_coords = CAlphaCoordinates(coords)
contact_map = alpha_coords.calculate_contact_map(threshold=6.0)
expected_contact_map = np.array([[1, 1, 0], [1, 1, 1], [0, 1, 1]])
assert np.array_equal(contact_map.cmap, expected_contact_map)
8 changes: 8 additions & 0 deletions mDeepFRI/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ def run_command(command):
shell=True,
universal_newlines=True)

stdout = []
while True:
line = process.stdout.readline()

if not line:
break
stdout.append(line)
print(line, end='')

process.wait()
if process.returncode != 0:
raise RuntimeError(
f"Command {command} failed with exit code {process.returncode}")

# close file
process.stdout.close()

return "".join(stdout)


def download_file(url, path):
"""
Expand Down

0 comments on commit 1461d8a

Please sign in to comment.