Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
90 changes: 90 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Test Suite

on:
push:
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Fast tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install test dependencies
run: python -m pip install pytest

- name: Install package
run: python -m pip install .

- name: Copy tests to temp directory
run: python -c "import pathlib, shutil; src = pathlib.Path(r'${{ github.workspace }}') / 'tests'; dst = pathlib.Path(r'${{ runner.temp }}') / 'tests'; shutil.rmtree(dst, ignore_errors=True); shutil.copytree(src, dst)"

- name: Run fast test suite
working-directory: ${{ runner.temp }}
run: python -m pytest tests -m "not benchmark and not integration" -q

test-heavy:
name: Heavy tests on ${{ matrix.os }}
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install test dependencies
run: python -m pip install pytest

- name: Install package
run: python -m pip install .

- name: Copy tests to temp directory
run: python -c "import pathlib, shutil; src = pathlib.Path(r'${{ github.workspace }}') / 'tests'; dst = pathlib.Path(r'${{ runner.temp }}') / 'tests'; shutil.rmtree(dst, ignore_errors=True); shutil.copytree(src, dst)"

- name: Run benchmark and integration suites
env:
RUN_BENCHMARKS: "1"
RUN_INTEGRATION: "1"
working-directory: ${{ runner.temp }}
run: python -m pytest tests -m "benchmark or integration" -q
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"python.testing.pytestArgs": [
"mir"
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"python.formatting.provider": "none"
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda"
}
31 changes: 22 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
cmake_minimum_required(VERSION 3.18)
project(mir_cdrscore LANGUAGES CXX)
project(mir_native LANGUAGES CXX)

find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)

pybind11_add_module(cdrscore MODULE mir/distances/cdrscore.cpp)
target_compile_features(cdrscore PRIVATE cxx_std_17)
# --- seqdist_c (mir.distances) — distances + CDR3 scoring ---
pybind11_add_module(seqdist_c MODULE mir/distances/seqdist.cpp)
target_compile_features(seqdist_c PRIVATE cxx_std_17)
if (MSVC)
target_compile_options(cdrscore PRIVATE /O2 /DNOMINMAX)
target_compile_options(seqdist_c PRIVATE /O2 /DNOMINMAX)
else()
target_compile_options(cdrscore PRIVATE -O3)
target_compile_options(seqdist_c PRIVATE -O3)
endif()

set_target_properties(cdrscore PROPERTIES
set_target_properties(seqdist_c PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mir/distances"
)
install(TARGETS cdrscore LIBRARY DESTINATION mir/distances)
install(TARGETS seqdist_c LIBRARY DESTINATION mir/distances)

# --- mirseq (mir.basic) ---
pybind11_add_module(mirseq MODULE mir/basic/mirseq.cpp)
target_compile_features(mirseq PRIVATE cxx_std_17)
if (MSVC)
target_compile_options(mirseq PRIVATE /O2 /DNOMINMAX)
else()
target_compile_options(mirseq PRIVATE -O3)
endif()
set_target_properties(mirseq PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mir/basic"
)
install(TARGETS mirseq LIBRARY DESTINATION mir/basic)
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Requirements:
- Python 3.11+
- a C/C++ build toolchain for compiled extensions

Install from PyPI:

```bash
pip install mirpy-lib
```

Install from the repository root:

```bash
Expand Down Expand Up @@ -90,6 +96,29 @@ repertoire = Repertoire.load(
)
```

### Mask and match sequences

```python
from mir.basic.alphabets import (
aa_to_reduced,
mask,
matches,
matches_aa_reduced,
NT_MASK,
AA_MASK,
)

nt_masked = mask("ATCGAT", (2, 5), NT_MASK)
assert nt_masked == b"ATNNNT"

aa = "CASTIV"
reduced = aa_to_reduced(aa)

# Matching ignores mask symbols: N for nucleotides, X for amino-acid alphabets.
assert matches(mask(aa, 0, AA_MASK), aa, AA_MASK)
assert matches_aa_reduced(aa, mask(reduced, 3, AA_MASK))
```

## Resources

- Example notebooks are available in [notebooks/](https://github.com/antigenomics/mirpy/tree/main/notebooks).
Expand Down
24 changes: 16 additions & 8 deletions docs/mir.basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ mir.basic.fast_clust module
:undoc-members:
:show-inheritance:

mir.basic.kmers module
----------------------

.. automodule:: mir.basic.kmers
:members:
:undoc-members:
:show-inheritance:

mir.basic.pgen module
---------------------

Expand All @@ -52,6 +44,22 @@ mir.basic.sampling module
:undoc-members:
:show-inheritance:

mir.basic.alphabets module
--------------------------

.. automodule:: mir.basic.alphabets
:members:
:undoc-members:
:show-inheritance:

mir.basic.mirseq module
-----------------------

.. automodule:: mir.basic.mirseq
:members:
:undoc-members:
:show-inheritance:

mir.basic.segment_usage module
------------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/mir.biomarkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ mir.biomarkers.fisher_biomarkers_detector module
:undoc-members:
:show-inheritance:

mir.biomarkers.kmer_stats module
--------------------------------

.. automodule:: mir.biomarkers.kmer_stats
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
16 changes: 16 additions & 0 deletions docs/mir.distances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ mir.distances.search module
:undoc-members:
:show-inheritance:

mir.distances.seqdist module
----------------------------

.. automodule:: mir.distances.seqdist
:members:
:undoc-members:
:show-inheritance:

mir.distances.seqdist\_c module
-------------------------------

.. automodule:: mir.distances.seqdist_c
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
Loading
Loading