diff --git a/Dockerfile b/Dockerfile index 240bf4c..ac47d19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ diff --git a/api-spec.yaml b/api-spec.yaml index f565921..0218e7d 100644 --- a/api-spec.yaml +++ b/api-spec.yaml @@ -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: diff --git a/pyard/__init__.py b/pyard/__init__.py index 09ea54a..ab12b6c 100644 --- a/pyard/__init__.py +++ b/pyard/__init__.py @@ -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( diff --git a/pyard/ard.py b/pyard/ard.py index 49b16dd..fb8d618 100644 --- a/pyard/ard.py +++ b/pyard/ard.py @@ -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, } @@ -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 @@ -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( diff --git a/scripts/pyard b/scripts/pyard index c294c62..035c9ee 100755 --- a/scripts/pyard +++ b/scripts/pyard @@ -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() @@ -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) diff --git a/setup.cfg b/setup.cfg index 4d4adb7..6978158 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.0.4 +current_version = 1.0.5 commit = True tag = True diff --git a/setup.py b/setup.py index 39edb12..0ecce82 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tests/environment.py b/tests/environment.py index 9a6bd4c..d6d5423 100644 --- a/tests/environment.py +++ b/tests/environment.py @@ -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 + ) diff --git a/tests/features/allele.feature b/tests/features/allele.feature index 5f497be..3629b4c 100644 --- a/tests/features/allele.feature +++ b/tests/features/allele.feature @@ -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 + When reducing on the level in non-strict mode + Then the reduced allele is found to be + + Examples: + | Allele | Level | Redux Allele | + | A*24:329 | lgx | A*24:329Q | + | DQB1*03:276 | lgx | DQB1*03:01 | diff --git a/tests/steps/redux_allele.py b/tests/steps/redux_allele.py index f9a7c77..8c4b857 100644 --- a/tests/steps/redux_allele.py +++ b/tests/steps/redux_allele.py @@ -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)