Skip to content

Commit b26c187

Browse files
authored
Merge pull request #273 from pbashyal-nmdp/add_strict_flag
Add non-strict mode
2 parents d8192da + b6c9408 commit b26c187

File tree

10 files changed

+64
-10
lines changed

10 files changed

+64
-10
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LABEL MAINTAINER="Pradeep Bashyal"
44

55
WORKDIR /app
66

7-
ARG PY_ARD_VERSION=1.0.4
7+
ARG PY_ARD_VERSION=1.0.5
88

99
COPY requirements.txt /app
1010
RUN pip install --no-cache-dir --upgrade pip && \

api-spec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ openapi: 3.0.3
22
info:
33
title: ARD Reduction
44
description: Reduce to ARD Level
5-
version: "1.0.4"
5+
version: "1.0.5"
66
servers:
77
- url: 'http://localhost:8080'
88
tags:

pyard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .misc import get_imgt_db_versions as db_versions
2828

2929
__author__ = """NMDP Bioinformatics"""
30-
__version__ = "1.0.4"
30+
__version__ = "1.0.5"
3131

3232

3333
def init(

pyard/ard.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
"reduce_shortnull": True,
5555
"ping": False,
5656
"map_drb345_to_drbx": True,
57-
"verbose_log": True,
57+
"verbose_log": False,
5858
"ARS_as_lg": False,
59+
"strict": True,
5960
}
6061

6162

@@ -181,6 +182,15 @@ def _redux_allele(
181182
else:
182183
return redux_allele
183184

185+
# In non-strict mode, if the allele is not valid,
186+
# try it with expression characters suffixed
187+
if not self._config["strict"] and not self._is_valid_allele(allele):
188+
for expr_char in expression_chars:
189+
if self._is_valid_allele(allele + expr_char):
190+
if self._config["verbose_log"]:
191+
print(f"{allele} is not valid. Using {allele}{expr_char}")
192+
allele = allele + expr_char
193+
184194
# g_group maps alleles to their g_group
185195
# note: this includes mappings for shortened version of alleles
186196
# C*12:02:02:01 => C*12:02:01G
@@ -335,7 +345,8 @@ def redux(self, glstring: str, redux_type: VALID_REDUCTION_TYPES) -> str:
335345

336346
validate_reduction_type(redux_type)
337347

338-
self.validate(glstring)
348+
if self._config["strict"]:
349+
self.validate(glstring)
339350

340351
if "^" in glstring:
341352
return self._sorted_unique_gl(

scripts/pyard

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,29 @@ if __name__ == "__main__":
7676
parser.add_argument(
7777
"--lookup-mac", dest="lookup_mac", help="Lookup MAC for an Allele List"
7878
)
79+
parser.add_argument(
80+
"--non-strict",
81+
dest="non_strict",
82+
action="store_true",
83+
help="Use non-strict mode",
84+
)
85+
parser.add_argument(
86+
"--verbose", dest="verbose", action="store_true", help="Use verbose mode"
87+
)
7988

8089
args = parser.parse_args()
8190

8291
imgt_version = get_imgt_version(args.imgt_version)
8392
data_dir = get_data_dir(args.data_dir)
84-
ard = pyard.init(imgt_version=imgt_version, data_dir=data_dir)
93+
94+
new_config = {}
95+
if args.non_strict:
96+
new_config["strict"] = False
97+
98+
if args.verbose:
99+
new_config["verbose_log"] = True
100+
101+
ard = pyard.init(imgt_version=imgt_version, data_dir=data_dir, config=new_config)
85102

86103
if args.version:
87104
version = ard.get_db_version()
@@ -114,8 +131,8 @@ if __name__ == "__main__":
114131
sys.exit(0)
115132

116133
try:
117-
if args.validate:
118-
ard.validate(args.cwd)
134+
if args.validate and args.gl_string:
135+
ard.validate(args.gl_string)
119136
if args.cwd:
120137
if args.validate:
121138
ard.validate(args.cwd)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.4
2+
current_version = 1.0.5
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
setup(
3838
name="py-ard",
39-
version="1.0.4",
39+
version="1.0.5",
4040
description="ARD reduction for HLA with Python",
4141
long_description=readme,
4242
long_description_content_type="text/markdown",

tests/environment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ def before_all(context):
3636
"ARS_as_lg": True,
3737
}
3838
context.ard_ars = pyard.init("3440", data_dir="/tmp/py-ard", config=lg_ars_config)
39+
40+
# use non-strict mode
41+
non_strict_config = {"strict": False}
42+
context.ard_non_strict = pyard.init(
43+
"3440", data_dir="/tmp/py-ard", config=non_strict_config
44+
)

tests/features/allele.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ Feature: Alleles
5757
| DRB1*14:06:01 | lg | DRB1*14:06ARS |
5858
| C*02:02 | lg | C*02:02ARS |
5959
| C*02:10 | lg | C*02:02ARS |
60+
61+
Scenario Outline: Allele reduction in non-strict mode
62+
63+
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
64+
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
65+
66+
Given the allele as <Allele>
67+
When reducing on the <Level> level in non-strict mode
68+
Then the reduced allele is found to be <Redux Allele>
69+
70+
Examples:
71+
| Allele | Level | Redux Allele |
72+
| A*24:329 | lgx | A*24:329Q |
73+
| DQB1*03:276 | lgx | DQB1*03:01 |

tests/steps/redux_allele.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ def step_impl(context, level):
9292
@then("the expanded allele is found to be {expanded_alleles}")
9393
def step_impl(context, expanded_alleles):
9494
assert_that(context.expanded_alleles, is_(expanded_alleles))
95+
96+
97+
@when("reducing on the {level} level in non-strict mode")
98+
def step_impl(context, level):
99+
context.level = level
100+
context.redux_allele = context.ard_non_strict.redux(context.allele, level)

0 commit comments

Comments
 (0)