py-ard 2.4.2__tar.gz → 2.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {py_ard-2.4.2 → py_ard-2.4.4}/PKG-INFO +1 -1
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/__init__.py +3 -3
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/ard.py +14 -49
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/cli/reduce_csv.py +19 -3
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/cli/redux.py +29 -8
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/config.py +15 -1
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/constants.py +12 -1
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/allele_handler.py +49 -4
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/lg_reducer.py +3 -4
- {py_ard-2.4.2 → py_ard-2.4.4}/pyproject.toml +4 -5
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/environment.py +3 -0
- py_ard-2.4.4/tests/features/optional_expression_characters.feature +23 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/valid_allele.feature +0 -1
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/test_pyard.py +1 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/.gitignore +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/CONTRIBUTING.rst +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/HISTORY.rst +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/LICENSE +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/README.md +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/blender.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/cli/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/cli/import_db.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/cli/status.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/data_repository.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/db.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/dna_relshp.csv +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/drbx.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/exceptions.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/gl_string_processor.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/hats_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/mac_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/serology_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/shortnull_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/v2_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/handlers/xx_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/CWD2.csv +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/allele_list.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/cwd.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/g_group.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/mac_codes.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/p_group.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/serology.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/version.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/loader/wmda-data-model.md +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/mappings.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/misc.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/rc.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/base_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/default_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/exon_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/first_field_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/g_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/hats_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/p_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/reducer_factory.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/s_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/u2_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/reducers/w_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/serology.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/simple_table.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/pyard/smart_sort.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/api-test.hurl +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/1f_reduction.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/Gexpand.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/Pexpand.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/Wexpand.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/XX.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/allele.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/cwd.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/drbx.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/drbx_blender.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/glstring.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/mac.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/p_g_group.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/p_group.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/serology.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/serology_broad_splits.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/serology_typings_redux.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/shortnulls.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/u2_reduction.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/version2.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/features/who.feature +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/XX.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/broad_splits.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/cwd.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/drbx_blender.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/generate_drbx.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/mac.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/redux_allele.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/steps/validate_allele.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/expected-serology.json +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/expected.json +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_allele_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_gl_string_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_mac_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_serology_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_shortnull_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_v2_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/handlers/test_xx_handler.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_all_reducers.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_base_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_default_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_exon_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_first_field_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_g_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_lg_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_p_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_reducer_factory.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_s_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_u2_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/reducers/test_w_reducer.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/simple_table/__init__.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/simple_table/test_column.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/simple_table/test_simple_table.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/simple_table/test_simple_table_failures.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/test_cli.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/test_load_allele_list.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/test_load_serology_broad_split_mapping.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/test_load_serology_mappings.py +0 -0
- {py_ard-2.4.2 → py_ard-2.4.4}/tests/unit/test_smart_sort.py +0 -0
|
@@ -38,7 +38,7 @@ __all__ = [
|
|
|
38
38
|
]
|
|
39
39
|
|
|
40
40
|
__author__ = """NMDP Bioinformatics"""
|
|
41
|
-
__version__ = "2.4.
|
|
41
|
+
__version__ = "2.4.4"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
def init(
|
|
@@ -61,8 +61,8 @@ def init(
|
|
|
61
61
|
if imgt_version is not None
|
|
62
62
|
else rc.get("imgt_version", "Latest")
|
|
63
63
|
),
|
|
64
|
-
"data_dir": data_dir if data_dir
|
|
65
|
-
"load_mac": load_mac if load_mac
|
|
64
|
+
"data_dir": data_dir if data_dir else rc.get("data_dir"),
|
|
65
|
+
"load_mac": load_mac if load_mac else rc.get("load_mac", True),
|
|
66
66
|
"max_cache_size": (
|
|
67
67
|
cache_size
|
|
68
68
|
if cache_size is not None
|
|
@@ -139,49 +139,8 @@ class ARD:
|
|
|
139
139
|
self.db_connection.close()
|
|
140
140
|
|
|
141
141
|
@functools.lru_cache(maxsize=DEFAULT_CACHE_SIZE) # noqa: B019
|
|
142
|
-
def _redux_allele(
|
|
143
|
-
self
|
|
144
|
-
) -> str:
|
|
145
|
-
"""Core allele reduction with ping logic"""
|
|
146
|
-
if not self.config.strict_enabled:
|
|
147
|
-
allele = self._get_non_strict_allele(allele)
|
|
148
|
-
|
|
149
|
-
# Handle P/G suffixes
|
|
150
|
-
if allele.endswith(("P", "G")) and redux_type in ["lg", "lgx", "G", "P"]:
|
|
151
|
-
allele = allele[:-1]
|
|
152
|
-
|
|
153
|
-
# Handle ping mode
|
|
154
|
-
if self.config.ping and re_ping and redux_type in ("lg", "lgx", "U2"):
|
|
155
|
-
if allele in self.ars_mappings.p_not_g:
|
|
156
|
-
not_g_allele = self.ars_mappings.p_not_g[allele]
|
|
157
|
-
if redux_type == "lg":
|
|
158
|
-
return self.allele_reducer.add_lg_suffix(not_g_allele)
|
|
159
|
-
return not_g_allele
|
|
160
|
-
else:
|
|
161
|
-
redux_allele = self._redux_allele(allele, redux_type, False)
|
|
162
|
-
if redux_allele.endswith("g"):
|
|
163
|
-
no_suffix_allele = redux_allele[:-1]
|
|
164
|
-
elif redux_allele.endswith("ARS"):
|
|
165
|
-
no_suffix_allele = redux_allele[:-3]
|
|
166
|
-
else:
|
|
167
|
-
no_suffix_allele = redux_allele
|
|
168
|
-
|
|
169
|
-
if (
|
|
170
|
-
no_suffix_allele == allele
|
|
171
|
-
or "/" in no_suffix_allele
|
|
172
|
-
or no_suffix_allele in self.ars_mappings.p_not_g.values()
|
|
173
|
-
):
|
|
174
|
-
return redux_allele
|
|
175
|
-
|
|
176
|
-
twice_redux_allele = self._redux_allele(
|
|
177
|
-
no_suffix_allele, redux_type, False
|
|
178
|
-
)
|
|
179
|
-
if "/" in twice_redux_allele:
|
|
180
|
-
return twice_redux_allele
|
|
181
|
-
if self.is_valid_allele(twice_redux_allele):
|
|
182
|
-
return twice_redux_allele
|
|
183
|
-
|
|
184
|
-
return self.allele_reducer.reduce_allele(allele, redux_type, re_ping)
|
|
142
|
+
def _redux_allele(self, allele: str, redux_type: VALID_REDUCTION_TYPE) -> str:
|
|
143
|
+
return self.allele_reducer.reduce_allele_ping(allele, redux_type)
|
|
185
144
|
|
|
186
145
|
def _redux_non_glstring(
|
|
187
146
|
self, allele: str, glstring: str, redux_type: VALID_REDUCTION_TYPE
|
|
@@ -343,9 +302,12 @@ class ARD:
|
|
|
343
302
|
def validate(self, glstring: str) -> bool:
|
|
344
303
|
return self.gl_processor.validate_gl_string(glstring)
|
|
345
304
|
|
|
346
|
-
def
|
|
347
|
-
"""
|
|
305
|
+
def _get_allele_ignoring_expression_character(self, allele: str) -> str:
|
|
306
|
+
"""Return allele that is valid with any similar expression character or without"""
|
|
348
307
|
if not self._is_allele_in_db(allele):
|
|
308
|
+
if allele[-1] in expression_chars:
|
|
309
|
+
# Remove the current expr char and try others
|
|
310
|
+
allele = allele[:-1]
|
|
349
311
|
for expr_char in expression_chars:
|
|
350
312
|
if self._is_allele_in_db(allele + expr_char):
|
|
351
313
|
if self.config.verbose_log:
|
|
@@ -383,7 +345,7 @@ class ARD:
|
|
|
383
345
|
if self.config.strict_enabled:
|
|
384
346
|
return allele in self.ars_mappings.p_group.values()
|
|
385
347
|
allele = allele[:-1]
|
|
386
|
-
elif allele.endswith("g"):
|
|
348
|
+
elif allele.endswith("g"): # noqa: SIM102
|
|
387
349
|
if not self.config.strict_enabled:
|
|
388
350
|
allele = allele[:-1]
|
|
389
351
|
|
|
@@ -416,9 +378,6 @@ class ARD:
|
|
|
416
378
|
if fields in self.config.ignore_allele_with_suffixes:
|
|
417
379
|
return True
|
|
418
380
|
|
|
419
|
-
if not self.config.strict_enabled:
|
|
420
|
-
allele = self._get_non_strict_allele(allele)
|
|
421
|
-
|
|
422
381
|
if (
|
|
423
382
|
not self.is_mac(allele)
|
|
424
383
|
and not self.is_XX(allele)
|
|
@@ -426,6 +385,12 @@ class ARD:
|
|
|
426
385
|
and not self.is_v2(allele)
|
|
427
386
|
and not self.is_shortnull(allele)
|
|
428
387
|
):
|
|
388
|
+
if (
|
|
389
|
+
self.config.expression_characters_enabled
|
|
390
|
+
or not self.config.strict_enabled
|
|
391
|
+
):
|
|
392
|
+
allele = self._get_allele_ignoring_expression_character(allele)
|
|
393
|
+
|
|
429
394
|
return self.is_valid_allele(allele)
|
|
430
395
|
|
|
431
396
|
return True
|
|
@@ -385,7 +385,7 @@ def reduce_and_save(
|
|
|
385
385
|
|
|
386
386
|
# Save as XLSX if specified
|
|
387
387
|
if ard_config["output_file_format"] == "xlsx":
|
|
388
|
-
out_csv_filename = f"{
|
|
388
|
+
out_csv_filename = f"{out_csv_filename}.xlsx"
|
|
389
389
|
df.to_excel(out_csv_filename, index=False)
|
|
390
390
|
else:
|
|
391
391
|
# Save as compressed CSV if specified
|
|
@@ -479,6 +479,16 @@ def main():
|
|
|
479
479
|
dest="ipd_version",
|
|
480
480
|
help="IPD-IMGT/HLA db to use for redux",
|
|
481
481
|
)
|
|
482
|
+
parser.add_argument(
|
|
483
|
+
"--input-file",
|
|
484
|
+
dest="input_file",
|
|
485
|
+
help="Input CSV file. Overrides config file",
|
|
486
|
+
)
|
|
487
|
+
parser.add_argument(
|
|
488
|
+
"--output-file",
|
|
489
|
+
dest="output_file",
|
|
490
|
+
help="Output CSV file. Overrides config file",
|
|
491
|
+
)
|
|
482
492
|
parser.add_argument(
|
|
483
493
|
"-q",
|
|
484
494
|
"--quiet",
|
|
@@ -552,8 +562,14 @@ def main():
|
|
|
552
562
|
config=csv_redux_config,
|
|
553
563
|
)
|
|
554
564
|
|
|
555
|
-
|
|
556
|
-
|
|
565
|
+
if args.input_file:
|
|
566
|
+
in_csv_filename = args.input_file
|
|
567
|
+
else:
|
|
568
|
+
in_csv_filename = ard_config["in_csv_filename"]
|
|
569
|
+
if args.output_file:
|
|
570
|
+
out_csv_filename = args.output_file
|
|
571
|
+
else:
|
|
572
|
+
out_csv_filename = ard_config["out_csv_filename"]
|
|
557
573
|
|
|
558
574
|
reduce_and_save(ard, ard_config, in_csv_filename, out_csv_filename, verbose)
|
|
559
575
|
|
|
@@ -25,7 +25,7 @@ import sys
|
|
|
25
25
|
import pyard.misc
|
|
26
26
|
from pyard.constants import VALID_REDUCTION_MODES
|
|
27
27
|
from pyard.exceptions import InvalidAlleleError, InvalidMACError, InvalidTypingError
|
|
28
|
-
from pyard.misc import
|
|
28
|
+
from pyard.misc import get_imgt_version
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def find_similar_alleles(ard, prefix):
|
|
@@ -128,6 +128,13 @@ def main():
|
|
|
128
128
|
help="IPD-IMGT/HLA db to use for redux",
|
|
129
129
|
)
|
|
130
130
|
parser.add_argument("-g", "--gl", dest="gl_string", help="GL String to reduce")
|
|
131
|
+
parser.add_argument(
|
|
132
|
+
"gl_string_positional",
|
|
133
|
+
nargs="?",
|
|
134
|
+
default=None,
|
|
135
|
+
metavar="GL_STRING",
|
|
136
|
+
help="GL String to reduce (same as -g/--gl)",
|
|
137
|
+
)
|
|
131
138
|
parser.add_argument(
|
|
132
139
|
"-r",
|
|
133
140
|
"--redux-type",
|
|
@@ -142,6 +149,9 @@ def main():
|
|
|
142
149
|
action="store_true",
|
|
143
150
|
help="Validate the provided GL String",
|
|
144
151
|
)
|
|
152
|
+
parser.add_argument(
|
|
153
|
+
"--lgx", dest="lgx", action="store_true", help="Perform lgx/ARD redux"
|
|
154
|
+
)
|
|
145
155
|
parser.add_argument("--cwd", dest="cwd", help="Perform CWD redux")
|
|
146
156
|
parser.add_argument(
|
|
147
157
|
"--expand-mac", dest="expand_mac", help="Expand MAC to Allele List"
|
|
@@ -177,8 +187,11 @@ def main():
|
|
|
177
187
|
|
|
178
188
|
args = parser.parse_args()
|
|
179
189
|
|
|
190
|
+
# Treat a bare positional argument the same as -g/--gl
|
|
191
|
+
if args.gl_string is None:
|
|
192
|
+
args.gl_string = args.gl_string_positional
|
|
193
|
+
|
|
180
194
|
imgt_version = get_imgt_version(args.ipd_version)
|
|
181
|
-
data_dir = get_data_dir(args.data_dir)
|
|
182
195
|
|
|
183
196
|
new_config = {}
|
|
184
197
|
if args.non_strict:
|
|
@@ -187,7 +200,9 @@ def main():
|
|
|
187
200
|
if args.verbose:
|
|
188
201
|
new_config["verbose_log"] = True
|
|
189
202
|
|
|
190
|
-
ard = pyard.init(
|
|
203
|
+
ard = pyard.init(
|
|
204
|
+
imgt_version=imgt_version, data_dir=args.data_dir, config=new_config
|
|
205
|
+
)
|
|
191
206
|
|
|
192
207
|
# Handle --version option
|
|
193
208
|
if args.version:
|
|
@@ -229,8 +244,14 @@ def main():
|
|
|
229
244
|
if args.validate and args.gl_string:
|
|
230
245
|
ard.validate(args.gl_string)
|
|
231
246
|
|
|
232
|
-
if args.
|
|
233
|
-
print(
|
|
247
|
+
if not args.gl_string:
|
|
248
|
+
print("No GL String supplied. Use -g")
|
|
249
|
+
parser.print_help()
|
|
250
|
+
sys.exit(1)
|
|
251
|
+
|
|
252
|
+
redux_type = "lgx" if args.lgx else args.redux_type
|
|
253
|
+
if redux_type:
|
|
254
|
+
print(ard.redux(args.gl_string, redux_type))
|
|
234
255
|
else:
|
|
235
256
|
for redux_type in VALID_REDUCTION_MODES:
|
|
236
257
|
redux_type_info = f"Reduction Method: {redux_type}"
|
|
@@ -240,13 +261,13 @@ def main():
|
|
|
240
261
|
print()
|
|
241
262
|
except InvalidAlleleError as e:
|
|
242
263
|
print("Allele Error:", e.message, file=sys.stderr)
|
|
243
|
-
sys.exit(
|
|
264
|
+
sys.exit(2)
|
|
244
265
|
except InvalidTypingError as e:
|
|
245
266
|
print("Typing Error:", e.message, file=sys.stderr)
|
|
246
|
-
sys.exit(
|
|
267
|
+
sys.exit(3)
|
|
247
268
|
except InvalidMACError as e:
|
|
248
269
|
print("MAC Error:", e.message, file=sys.stderr)
|
|
249
|
-
sys.exit(
|
|
270
|
+
sys.exit(4)
|
|
250
271
|
else:
|
|
251
272
|
# Remove ard and close db connection
|
|
252
273
|
del ard
|
|
@@ -40,9 +40,10 @@ class ARDConfig:
|
|
|
40
40
|
ARS_as_lg: bool = False
|
|
41
41
|
strict: bool = True
|
|
42
42
|
ignore_allele_with_suffixes: tuple[str, ...] = ()
|
|
43
|
+
expression_character_is_optional: bool = True
|
|
43
44
|
|
|
44
45
|
@classmethod
|
|
45
|
-
def from_dict(cls, config_dict: dict) -> ARDConfig:
|
|
46
|
+
def from_dict(cls, config_dict: dict | None) -> ARDConfig:
|
|
46
47
|
"""Create ARDConfig from dictionary"""
|
|
47
48
|
if not config_dict:
|
|
48
49
|
return cls()
|
|
@@ -68,6 +69,7 @@ class ARDConfig:
|
|
|
68
69
|
"ARS_as_lg": self.ARS_as_lg,
|
|
69
70
|
"strict": self.strict,
|
|
70
71
|
"ignore_allele_with_suffixes": self.ignore_allele_with_suffixes,
|
|
72
|
+
"expression_character_is_optional": self.expression_character_is_optional,
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
@property
|
|
@@ -113,3 +115,15 @@ class ARDConfig:
|
|
|
113
115
|
@property
|
|
114
116
|
def strict_enabled(self) -> bool:
|
|
115
117
|
return self.strict
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def ignore_allele_with_suffixes_enabled(self) -> bool:
|
|
121
|
+
return bool(self.ignore_allele_with_suffixes)
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def ignore_allele_suffixes(self) -> tuple[str, ...]:
|
|
125
|
+
return self.ignore_allele_with_suffixes
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def expression_characters_enabled(self) -> bool:
|
|
129
|
+
return self.expression_character_is_optional
|
|
@@ -26,7 +26,18 @@ DEFAULT_CACHE_SIZE = 1_000
|
|
|
26
26
|
|
|
27
27
|
HLA_regex = re.compile("^HLA-")
|
|
28
28
|
|
|
29
|
-
VALID_REDUCTION_MODES = (
|
|
29
|
+
VALID_REDUCTION_MODES = (
|
|
30
|
+
"G",
|
|
31
|
+
"P",
|
|
32
|
+
"W",
|
|
33
|
+
"exon",
|
|
34
|
+
"U2",
|
|
35
|
+
"S",
|
|
36
|
+
"1F",
|
|
37
|
+
"hats",
|
|
38
|
+
"lg",
|
|
39
|
+
"lgx",
|
|
40
|
+
)
|
|
30
41
|
VALID_REDUCTION_TYPE = typing.Literal[VALID_REDUCTION_MODES]
|
|
31
42
|
|
|
32
43
|
expression_chars = ("N", "Q", "L", "S")
|
|
@@ -26,9 +26,48 @@ class AlleleHandler:
|
|
|
26
26
|
# Factory that creates appropriate reduction strategy based on redux_type
|
|
27
27
|
self.strategy_factory = StrategyFactory(ard_instance)
|
|
28
28
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
def reduce_allele_ping(self, allele: str, redux_type: VALID_REDUCTION_TYPE) -> str:
|
|
30
|
+
"""Core allele reduction with ping logic"""
|
|
31
|
+
if (
|
|
32
|
+
self.ard.config.expression_characters_enabled
|
|
33
|
+
or not self.ard.config.strict_enabled
|
|
34
|
+
):
|
|
35
|
+
allele = self.ard._get_allele_ignoring_expression_character(allele)
|
|
36
|
+
|
|
37
|
+
# Handle P/G suffixes
|
|
38
|
+
if allele.endswith(("P", "G")) and redux_type in ["lg", "lgx", "G", "P"]:
|
|
39
|
+
allele = allele[:-1]
|
|
40
|
+
|
|
41
|
+
# Check if ping applies
|
|
42
|
+
ping_applies = self.ard.config.ping and redux_type in ("lg", "lgx", "U2")
|
|
43
|
+
if not ping_applies:
|
|
44
|
+
return self.reduce_allele(allele, redux_type)
|
|
45
|
+
|
|
46
|
+
# Ping mode: alleles mapped as "P but not G" resolve directly
|
|
47
|
+
if allele in self.ard.ars_mappings.p_not_g:
|
|
48
|
+
not_g_allele = self.ard.ars_mappings.p_not_g[allele]
|
|
49
|
+
if redux_type == "lg":
|
|
50
|
+
return self.add_lg_suffix(not_g_allele)
|
|
51
|
+
return not_g_allele
|
|
52
|
+
|
|
53
|
+
# Otherwise reduce once, strip the group suffix, and try reducing again
|
|
54
|
+
redux_allele = self.reduce_allele(allele, redux_type)
|
|
55
|
+
no_suffix_allele = self._strip_group_suffix(redux_allele)
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
no_suffix_allele == allele
|
|
59
|
+
or "/" in no_suffix_allele
|
|
60
|
+
or no_suffix_allele in self.ard.ars_mappings.p_not_g.values()
|
|
61
|
+
):
|
|
62
|
+
return redux_allele
|
|
63
|
+
|
|
64
|
+
twice_redux_allele = self.reduce_allele(no_suffix_allele, redux_type)
|
|
65
|
+
if "/" in twice_redux_allele or self.ard.is_valid_allele(twice_redux_allele):
|
|
66
|
+
return twice_redux_allele
|
|
67
|
+
|
|
68
|
+
return redux_allele
|
|
69
|
+
|
|
70
|
+
def reduce_allele(self, allele: str, redux_type: VALID_REDUCTION_TYPE) -> str:
|
|
32
71
|
"""Core allele reduction logic using Strategy Pattern
|
|
33
72
|
|
|
34
73
|
Reduces an HLA allele to the specified resolution level by delegating
|
|
@@ -37,7 +76,6 @@ class AlleleHandler:
|
|
|
37
76
|
Args:
|
|
38
77
|
allele: HLA allele string to reduce (e.g., "A*01:01:01:01")
|
|
39
78
|
redux_type: Type of reduction to perform (G, P, lg, lgx, W, exon, U2, S)
|
|
40
|
-
re_ping: Whether to re-ping for P groups when G groups are unavailable
|
|
41
79
|
|
|
42
80
|
Returns:
|
|
43
81
|
Reduced allele string according to the specified redux_type
|
|
@@ -69,3 +107,10 @@ class AlleleHandler:
|
|
|
69
107
|
if self.ard.config.ars_as_lg_enabled:
|
|
70
108
|
return redux_allele + "ARS"
|
|
71
109
|
return redux_allele + "g"
|
|
110
|
+
|
|
111
|
+
def _strip_group_suffix(self, allele: str) -> str:
|
|
112
|
+
if allele.endswith("g"):
|
|
113
|
+
return allele[:-1]
|
|
114
|
+
if allele.endswith("ARS"):
|
|
115
|
+
return allele[:-3]
|
|
116
|
+
return allele
|
|
@@ -54,7 +54,7 @@ class LGXReducer(Reducer):
|
|
|
54
54
|
return ":".join(allele.split(":")[0:2])
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
class LGReducer(
|
|
57
|
+
class LGReducer(LGXReducer):
|
|
58
58
|
"""
|
|
59
59
|
Strategy for LG reduction of HLA alleles (LGX + 'g' suffix).
|
|
60
60
|
|
|
@@ -95,9 +95,8 @@ class LGReducer(Reducer):
|
|
|
95
95
|
>>> reducer.reduce("B*07:02:01")
|
|
96
96
|
"B*07:02g"
|
|
97
97
|
"""
|
|
98
|
-
# First perform
|
|
99
|
-
|
|
100
|
-
redux_allele = lgx_strategy.reduce(allele)
|
|
98
|
+
# First perform lgx reduction
|
|
99
|
+
redux_allele = super().reduce(allele)
|
|
101
100
|
|
|
102
101
|
# Add appropriate suffix
|
|
103
102
|
return self._add_lg_suffix(redux_allele)
|
|
@@ -61,18 +61,17 @@ test = [
|
|
|
61
61
|
"behave==1.3.3; python_version >= '3.10'",
|
|
62
62
|
"PyHamcrest==2.1.0; python_version >= '3.10'",
|
|
63
63
|
"pytest==9.0.3; python_version >= '3.10'",
|
|
64
|
+
"allure-behave==2.15.3; python_version >= '3.10'",
|
|
64
65
|
]
|
|
65
66
|
dev = [
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"coverage==7.13.4; python_version >= '3.10'",
|
|
69
|
-
"pre-commit==4.5.1; python_version >= '3.10'",
|
|
67
|
+
"coverage>=7.13.4; python_version >= '3.10'",
|
|
68
|
+
"pre-commit>=4.6.2; python_version >= '3.10'",
|
|
70
69
|
"bump-my-version; python_version >= '3.10'",
|
|
71
70
|
"ruff>=0.16.7; python_version >= '3.10'",
|
|
72
71
|
]
|
|
73
72
|
|
|
74
73
|
[tool.bumpversion]
|
|
75
|
-
current_version = "2.4.
|
|
74
|
+
current_version = "2.4.4"
|
|
76
75
|
commit = true
|
|
77
76
|
tag = true
|
|
78
77
|
|
|
@@ -19,10 +19,13 @@
|
|
|
19
19
|
# > http://www.fsf.org/licensing/licenses/lgpl.html
|
|
20
20
|
# > http://www.opensource.org/licenses/lgpl-license.php
|
|
21
21
|
#
|
|
22
|
+
import os
|
|
23
|
+
|
|
22
24
|
import pyard
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
def before_all(context):
|
|
28
|
+
os.environ["PYARD_RC"] = "no"
|
|
26
29
|
context.ard = pyard.init("3440", data_dir="/tmp/py-ard")
|
|
27
30
|
|
|
28
31
|
# an ard with ARS suffix for lg
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Feature: Expression characters are optional
|
|
2
|
+
|
|
3
|
+
An allele is valid if it's valid with any expression character or
|
|
4
|
+
without an expression character
|
|
5
|
+
|
|
6
|
+
Scenario Outline:
|
|
7
|
+
|
|
8
|
+
Given the allele as <Allele>
|
|
9
|
+
When reducing on the <Level> level
|
|
10
|
+
Then the reduced allele is found to be <Redux Allele>
|
|
11
|
+
|
|
12
|
+
Examples: expression characters not propagated for C*04:09
|
|
13
|
+
| Allele | Level | Redux Allele |
|
|
14
|
+
| C*04:09L | lgx | C*04:01 |
|
|
15
|
+
| C*04:09N | lgx | C*04:01 |
|
|
16
|
+
| C*04:09 | lgx | C*04:01 |
|
|
17
|
+
|
|
18
|
+
Examples: expression characters not propagated for A*24:329
|
|
19
|
+
| Allele | Level | Redux Allele |
|
|
20
|
+
| A*24:329N | lgx | A*24:329Q |
|
|
21
|
+
| A*24:329Q | lgx | A*24:329Q |
|
|
22
|
+
| A*24:329L | lgx | A*24:329Q |
|
|
23
|
+
| A*24:329 | lgx | A*24:329Q |
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|