Skip to content
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LABEL MAINTAINER="Pradeep Bashyal"

WORKDIR /app

ARG PY_ARD_VERSION=1.0.4
ARG PY_ARD_VERSION=1.0.5

COPY requirements.txt /app
RUN pip install --no-cache-dir --upgrade pip && \
Expand Down
2 changes: 1 addition & 1 deletion api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: ARD Reduction
description: Reduce to ARD Level
version: "1.0.4"
version: "1.0.5"
servers:
- url: 'http://localhost:8080'
tags:
Expand Down
2 changes: 1 addition & 1 deletion pyard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .misc import get_imgt_db_versions as db_versions

__author__ = """NMDP Bioinformatics"""
__version__ = "1.0.4"
__version__ = "1.0.5"


def init(
Expand Down
15 changes: 13 additions & 2 deletions pyard/ard.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
"reduce_shortnull": True,
"ping": False,
"map_drb345_to_drbx": True,
"verbose_log": True,
"verbose_log": False,
"ARS_as_lg": False,
"strict": True,
}


Expand Down Expand Up @@ -181,6 +182,15 @@ def _redux_allele(
else:
return redux_allele

# In non-strict mode, if the allele is not valid,
# try it with expression characters suffixed
if not self._config["strict"] and not self._is_valid_allele(allele):
for expr_char in expression_chars:
if self._is_valid_allele(allele + expr_char):
if self._config["verbose_log"]:
print(f"{allele} is not valid. Using {allele}{expr_char}")
allele = allele + expr_char

# g_group maps alleles to their g_group
# note: this includes mappings for shortened version of alleles
# C*12:02:02:01 => C*12:02:01G
Expand Down Expand Up @@ -335,7 +345,8 @@ def redux(self, glstring: str, redux_type: VALID_REDUCTION_TYPES) -> str:

validate_reduction_type(redux_type)

self.validate(glstring)
if self._config["strict"]:
self.validate(glstring)

if "^" in glstring:
return self._sorted_unique_gl(
Expand Down
23 changes: 20 additions & 3 deletions scripts/pyard
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,29 @@ if __name__ == "__main__":
parser.add_argument(
"--lookup-mac", dest="lookup_mac", help="Lookup MAC for an Allele List"
)
parser.add_argument(
"--non-strict",
dest="non_strict",
action="store_true",
help="Use non-strict mode",
)
parser.add_argument(
"--verbose", dest="verbose", action="store_true", help="Use verbose mode"
)

args = parser.parse_args()

imgt_version = get_imgt_version(args.imgt_version)
data_dir = get_data_dir(args.data_dir)
ard = pyard.init(imgt_version=imgt_version, data_dir=data_dir)

new_config = {}
if args.non_strict:
new_config["strict"] = False

if args.verbose:
new_config["verbose_log"] = True

ard = pyard.init(imgt_version=imgt_version, data_dir=data_dir, config=new_config)

if args.version:
version = ard.get_db_version()
Expand Down Expand Up @@ -114,8 +131,8 @@ if __name__ == "__main__":
sys.exit(0)

try:
if args.validate:
ard.validate(args.cwd)
if args.validate and args.gl_string:
ard.validate(args.gl_string)
if args.cwd:
if args.validate:
ard.validate(args.cwd)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.4
current_version = 1.0.5
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

setup(
name="py-ard",
version="1.0.4",
version="1.0.5",
description="ARD reduction for HLA with Python",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down
6 changes: 6 additions & 0 deletions tests/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ def before_all(context):
"ARS_as_lg": True,
}
context.ard_ars = pyard.init("3440", data_dir="/tmp/py-ard", config=lg_ars_config)

# use non-strict mode
non_strict_config = {"strict": False}
context.ard_non_strict = pyard.init(
"3440", data_dir="/tmp/py-ard", config=non_strict_config
)
14 changes: 14 additions & 0 deletions tests/features/allele.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ Feature: Alleles
| DRB1*14:06:01 | lg | DRB1*14:06ARS |
| C*02:02 | lg | C*02:02ARS |
| C*02:10 | lg | C*02:02ARS |

Scenario Outline: Allele reduction in non-strict mode

The canon of HLA Nomenclature includes Deleted Alleles like A*24:329 that were renamed to add an expression character. https://hla.alleles.org/alleles/deleted.html
Such alleles can be included by using non-strict mode where py-ard will try alleles with expression characters when the original allele is not valid

Given the allele as <Allele>
When reducing on the <Level> level in non-strict mode
Then the reduced allele is found to be <Redux Allele>

Examples:
| Allele | Level | Redux Allele |
| A*24:329 | lgx | A*24:329Q |
| DQB1*03:276 | lgx | DQB1*03:01 |
6 changes: 6 additions & 0 deletions tests/steps/redux_allele.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ def step_impl(context, level):
@then("the expanded allele is found to be {expanded_alleles}")
def step_impl(context, expanded_alleles):
assert_that(context.expanded_alleles, is_(expanded_alleles))


@when("reducing on the {level} level in non-strict mode")
def step_impl(context, level):
context.level = level
context.redux_allele = context.ard_non_strict.redux(context.allele, level)