Skip to content

Commit

Permalink
Add automated tests, add Binder link
Browse files Browse the repository at this point in the history
  • Loading branch information
prihoda committed Aug 19, 2021
1 parent 7dbea8b commit 98833a2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build & Test

on:
push:
schedule:
- cron: '0 3 * * 1'


jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 5

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
run: |
conda env update -f environment.yml
pip install . --no-deps
- name: Test with pytest
run: |
conda install pytest
pytest test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Convenience Python APIs for antibody numbering using [ANARCI](https://github.com/oxpig/ANARCI)

Try it out in your browser using Binder: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/prihoda/AbNumber/HEAD?filepath=examples%2FAbNumber_getting_started.ipynb)

## Installation

Install using Bioconda:
Expand Down
4 changes: 2 additions & 2 deletions abnumber/germlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_imgt_chain(gene_name):

def get_imgt_v_chains(chain_type=None):
global _HUMAN_IMGT_V_CHAINS
if _HUMAN_IMGT_V_CHAINS is None:
if _HUMAN_IMGT_V_CHAINS is None or chain_type not in _HUMAN_IMGT_V_CHAINS:
_HUMAN_IMGT_V_CHAINS = {}
for t, germlines in HUMAN_IMGT_IG_V.items():
positions = germlines['positions']
Expand All @@ -42,7 +42,7 @@ def get_imgt_v_chains(chain_type=None):

def get_imgt_j_chains(chain_type=None):
global _HUMAN_IMGT_J_CHAINS
if _HUMAN_IMGT_J_CHAINS is None:
if _HUMAN_IMGT_J_CHAINS is None or chain_type not in _HUMAN_IMGT_J_CHAINS:
_HUMAN_IMGT_J_CHAINS = {}
for t, germlines in HUMAN_IMGT_IG_J.items():
positions = germlines['positions']
Expand Down
11 changes: 11 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
channels:
- nodefaults
- bioconda
- conda-forge
dependencies:
# Dependencies for local setup only. Make sure to update meta.yml in bioconda channel.
- python >= 3.6
- pip
- pandas
- biopython
- anarci == 2020.04.23
9 changes: 9 additions & 0 deletions examples/AbNumber_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"# AbNumber Usage Examples"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"!conda install -y -c bioconda abnumber"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand Down
35 changes: 35 additions & 0 deletions test/test_bugs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from abnumber import Chain, ChainParseError, Position
from abnumber.germlines import HUMAN_IMGT_IG_V, HUMAN_IMGT_IG_J


def test_imgt_61A():
"""Related to ANARCI issue: https://github.com/oxpig/ANARCI/issues/14"""
assert Position.from_string('61A', 'H', 'imgt') > Position.from_string('61', 'H', 'imgt')
seq = 'EVQLVESGGGLVQPGGSLRLSCAASGIILDYYPIGWFRQAPGKEREGVAFITNSDDSTIYTNYADSVKGRFTISRDKNSLYLQMNSLRAEDTAVYYCSSKASFLIGKDDQGIDAGEYDYWGQGTMVTVSS'
with pytest.raises(NotImplementedError):
chain = Chain(seq, 'imgt')


def test_light_chain_IMGT_position_21():
# Check bug from ANARCI 2021.02.04
# When numbering full Kappa chains, position IMGT 21 contains a gap
# When numbering V gene only, position IMGT 21 contains an amino acid as expected
# Test against this by making sure that same numbering is assigned when numbering V gene and VJ genes concatenated
# https://github.com/oxpig/ANARCI/issues/17
for germline in HUMAN_IMGT_IG_V['K']['aligned_sequences']:
v_seq = HUMAN_IMGT_IG_V['K']['aligned_sequences'][germline].replace('-', '')
first_j_gene = list(HUMAN_IMGT_IG_J['K']['aligned_sequences'].keys())[0]
j_seq = HUMAN_IMGT_IG_J['K']['aligned_sequences'][first_j_gene].replace('-', '')
vj_seq = v_seq + j_seq
try:
v_chain = Chain(v_seq, 'imgt')
vj_chain = Chain(vj_seq, 'imgt')
except Exception as e:
print(e)
continue
v_positions = [str(p) for p in v_chain.positions]
vj_positions = [str(p) for p in vj_chain.positions]

len_limit = len(v_seq) - 20
assert ','.join(v_positions[:len_limit]) == ','.join(vj_positions[:len_limit])
8 changes: 0 additions & 8 deletions test/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ def test_multiple_domains():
chain = Chain(vh + vl, 'imgt')


def test_imgt_61A():
"""Related to ANARCI issue: https://github.com/oxpig/ANARCI/issues/14"""
assert Position.from_string('61A', 'H', 'imgt') > Position.from_string('61', 'H', 'imgt')
seq = 'EVQLVESGGGLVQPGGSLRLSCAASGIILDYYPIGWFRQAPGKEREGVAFITNSDDSTIYTNYADSVKGRFTISRDKNSLYLQMNSLRAEDTAVYYCSSKASFLIGKDDQGIDAGEYDYWGQGTMVTVSS'
with pytest.raises(NotImplementedError):
chain = Chain(seq, 'imgt')


def test_germline_assignment():
light_seq = 'ELVMTQSPSSLSASVGDRVNIACRASQGISSALAWYQQKPGKAPRLLIYDASNLESGVPSRFSGSGSGTDFTLTISSLQPEDFAIYYCQQFNSYPLTFGGGTKVEIK'
light_chain = Chain(light_seq, scheme='imgt', assign_germline=True)
Expand Down

0 comments on commit 98833a2

Please sign in to comment.