py-ard 2.4.2__tar.gz → 2.4.3__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.
Files changed (125) hide show
  1. {py_ard-2.4.2 → py_ard-2.4.3}/PKG-INFO +1 -1
  2. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/__init__.py +3 -3
  3. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/ard.py +13 -48
  4. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/cli/redux.py +23 -6
  5. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/config.py +15 -1
  6. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/constants.py +12 -1
  7. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/allele_handler.py +49 -4
  8. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/lg_reducer.py +3 -4
  9. {py_ard-2.4.2 → py_ard-2.4.3}/pyproject.toml +4 -5
  10. {py_ard-2.4.2 → py_ard-2.4.3}/tests/environment.py +3 -0
  11. py_ard-2.4.3/tests/features/optional_expression_characters.feature +23 -0
  12. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/valid_allele.feature +0 -1
  13. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/test_pyard.py +1 -0
  14. {py_ard-2.4.2 → py_ard-2.4.3}/.gitignore +0 -0
  15. {py_ard-2.4.2 → py_ard-2.4.3}/CONTRIBUTING.rst +0 -0
  16. {py_ard-2.4.2 → py_ard-2.4.3}/HISTORY.rst +0 -0
  17. {py_ard-2.4.2 → py_ard-2.4.3}/LICENSE +0 -0
  18. {py_ard-2.4.2 → py_ard-2.4.3}/README.md +0 -0
  19. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/blender.py +0 -0
  20. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/cli/__init__.py +0 -0
  21. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/cli/import_db.py +0 -0
  22. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/cli/reduce_csv.py +0 -0
  23. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/cli/status.py +0 -0
  24. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/data_repository.py +0 -0
  25. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/db.py +0 -0
  26. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/dna_relshp.csv +0 -0
  27. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/drbx.py +0 -0
  28. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/exceptions.py +0 -0
  29. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/__init__.py +0 -0
  30. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/gl_string_processor.py +0 -0
  31. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/hats_handler.py +0 -0
  32. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/mac_handler.py +0 -0
  33. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/serology_handler.py +0 -0
  34. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/shortnull_handler.py +0 -0
  35. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/v2_handler.py +0 -0
  36. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/handlers/xx_handler.py +0 -0
  37. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/CWD2.csv +0 -0
  38. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/__init__.py +0 -0
  39. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/allele_list.py +0 -0
  40. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/cwd.py +0 -0
  41. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/g_group.py +0 -0
  42. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/mac_codes.py +0 -0
  43. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/p_group.py +0 -0
  44. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/serology.py +0 -0
  45. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/version.py +0 -0
  46. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/loader/wmda-data-model.md +0 -0
  47. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/mappings.py +0 -0
  48. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/misc.py +0 -0
  49. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/rc.py +0 -0
  50. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/__init__.py +0 -0
  51. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/base_reducer.py +0 -0
  52. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/default_reducer.py +0 -0
  53. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/exon_reducer.py +0 -0
  54. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/first_field_reducer.py +0 -0
  55. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/g_reducer.py +0 -0
  56. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/hats_reducer.py +0 -0
  57. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/p_reducer.py +0 -0
  58. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/reducer_factory.py +0 -0
  59. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/s_reducer.py +0 -0
  60. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/u2_reducer.py +0 -0
  61. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/reducers/w_reducer.py +0 -0
  62. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/serology.py +0 -0
  63. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/simple_table.py +0 -0
  64. {py_ard-2.4.2 → py_ard-2.4.3}/pyard/smart_sort.py +0 -0
  65. {py_ard-2.4.2 → py_ard-2.4.3}/tests/api-test.hurl +0 -0
  66. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/1f_reduction.feature +0 -0
  67. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/Gexpand.feature +0 -0
  68. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/Pexpand.feature +0 -0
  69. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/Wexpand.feature +0 -0
  70. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/XX.feature +0 -0
  71. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/allele.feature +0 -0
  72. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/cwd.feature +0 -0
  73. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/drbx.feature +0 -0
  74. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/drbx_blender.feature +0 -0
  75. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/glstring.feature +0 -0
  76. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/mac.feature +0 -0
  77. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/p_g_group.feature +0 -0
  78. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/p_group.feature +0 -0
  79. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/serology.feature +0 -0
  80. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/serology_broad_splits.feature +0 -0
  81. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/serology_typings_redux.feature +0 -0
  82. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/shortnulls.feature +0 -0
  83. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/u2_reduction.feature +0 -0
  84. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/version2.feature +0 -0
  85. {py_ard-2.4.2 → py_ard-2.4.3}/tests/features/who.feature +0 -0
  86. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/XX.py +0 -0
  87. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/broad_splits.py +0 -0
  88. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/cwd.py +0 -0
  89. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/drbx_blender.py +0 -0
  90. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/generate_drbx.py +0 -0
  91. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/mac.py +0 -0
  92. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/redux_allele.py +0 -0
  93. {py_ard-2.4.2 → py_ard-2.4.3}/tests/steps/validate_allele.py +0 -0
  94. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/expected-serology.json +0 -0
  95. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/expected.json +0 -0
  96. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/__init__.py +0 -0
  97. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_allele_handler.py +0 -0
  98. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_gl_string_handler.py +0 -0
  99. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_mac_handler.py +0 -0
  100. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_serology_handler.py +0 -0
  101. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_shortnull_handler.py +0 -0
  102. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_v2_handler.py +0 -0
  103. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/handlers/test_xx_handler.py +0 -0
  104. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/__init__.py +0 -0
  105. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_all_reducers.py +0 -0
  106. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_base_reducer.py +0 -0
  107. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_default_reducer.py +0 -0
  108. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_exon_reducer.py +0 -0
  109. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_first_field_reducer.py +0 -0
  110. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_g_reducer.py +0 -0
  111. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_lg_reducer.py +0 -0
  112. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_p_reducer.py +0 -0
  113. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_reducer_factory.py +0 -0
  114. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_s_reducer.py +0 -0
  115. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_u2_reducer.py +0 -0
  116. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/reducers/test_w_reducer.py +0 -0
  117. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/simple_table/__init__.py +0 -0
  118. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/simple_table/test_column.py +0 -0
  119. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/simple_table/test_simple_table.py +0 -0
  120. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/simple_table/test_simple_table_failures.py +0 -0
  121. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/test_cli.py +0 -0
  122. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/test_load_allele_list.py +0 -0
  123. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/test_load_serology_broad_split_mapping.py +0 -0
  124. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/test_load_serology_mappings.py +0 -0
  125. {py_ard-2.4.2 → py_ard-2.4.3}/tests/unit/test_smart_sort.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: py-ard
3
- Version: 2.4.2
3
+ Version: 2.4.3
4
4
  Summary: ARD reduction for HLA with Python
5
5
  Project-URL: Homepage, https://github.com/nmdp-bioinformatics/py-ard
6
6
  Project-URL: Repository, https://github.com/nmdp-bioinformatics/py-ard
@@ -38,7 +38,7 @@ __all__ = [
38
38
  ]
39
39
 
40
40
  __author__ = """NMDP Bioinformatics"""
41
- __version__ = "2.4.2"
41
+ __version__ = "2.4.3"
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 is not None else rc.get("data_dir"),
65
- "load_mac": load_mac if load_mac is not None else rc.get("load_mac", True),
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, allele: str, redux_type: VALID_REDUCTION_TYPE, re_ping=True
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 _get_non_strict_allele(self, allele: str) -> str:
347
- """Handle non-strict allele validation"""
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:
@@ -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
@@ -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 get_data_dir, get_imgt_version
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",
@@ -177,8 +184,11 @@ def main():
177
184
 
178
185
  args = parser.parse_args()
179
186
 
187
+ # Treat a bare positional argument the same as -g/--gl
188
+ if args.gl_string is None:
189
+ args.gl_string = args.gl_string_positional
190
+
180
191
  imgt_version = get_imgt_version(args.ipd_version)
181
- data_dir = get_data_dir(args.data_dir)
182
192
 
183
193
  new_config = {}
184
194
  if args.non_strict:
@@ -187,7 +197,9 @@ def main():
187
197
  if args.verbose:
188
198
  new_config["verbose_log"] = True
189
199
 
190
- ard = pyard.init(imgt_version=imgt_version, data_dir=data_dir, config=new_config)
200
+ ard = pyard.init(
201
+ imgt_version=imgt_version, data_dir=args.data_dir, config=new_config
202
+ )
191
203
 
192
204
  # Handle --version option
193
205
  if args.version:
@@ -229,6 +241,11 @@ def main():
229
241
  if args.validate and args.gl_string:
230
242
  ard.validate(args.gl_string)
231
243
 
244
+ if not args.gl_string:
245
+ print("No GL String supplied. Use -g")
246
+ parser.print_help()
247
+ sys.exit(1)
248
+
232
249
  if args.redux_type:
233
250
  print(ard.redux(args.gl_string, args.redux_type))
234
251
  else:
@@ -240,13 +257,13 @@ def main():
240
257
  print()
241
258
  except InvalidAlleleError as e:
242
259
  print("Allele Error:", e.message, file=sys.stderr)
243
- sys.exit(1)
260
+ sys.exit(2)
244
261
  except InvalidTypingError as e:
245
262
  print("Typing Error:", e.message, file=sys.stderr)
246
- sys.exit(2)
263
+ sys.exit(3)
247
264
  except InvalidMACError as e:
248
265
  print("MAC Error:", e.message, file=sys.stderr)
249
- sys.exit(3)
266
+ sys.exit(4)
250
267
  else:
251
268
  # Remove ard and close db connection
252
269
  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 = ("G", "P", "lg", "lgx", "W", "exon", "U2", "S", "1F", "hats")
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 reduce_allele(
30
- self, allele: str, redux_type: VALID_REDUCTION_TYPE, re_ping=True
31
- ) -> str:
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(Reducer):
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 LGX reduction
99
- lgx_strategy = LGXReducer(self.ard)
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
- "allure-behave==2.15.3; python_version >= '3.10'",
67
- "flake8==7.3.0; python_version >= '3.10'",
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.2"
74
+ current_version = "2.4.3"
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 |
@@ -84,7 +84,6 @@ Feature: Validate Allele
84
84
 
85
85
  Examples:
86
86
  | Allele | Validity |
87
- | A*24:329 | InValid |
88
87
  | DRBX*NNNN | Invalid |
89
88
  | A*30:02g | Invalid |
90
89
  | HLA-A*01:04Ng | Invalid |
@@ -32,6 +32,7 @@ from pyard.misc import validate_reduction_type
32
32
 
33
33
  @pytest.fixture(scope="module")
34
34
  def ard():
35
+ os.environ["PYARD_RC"] = "no"
35
36
  db_version = "3440"
36
37
  return pyard.init(db_version, data_dir="/tmp/py-ard")
37
38
 
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