Skip to content

Commit 67b77cc

Browse files
authored
Merge pull request #334 from pbashyal-nmdp/redux_to_one
Only single `lgx` reductions
2 parents 3caf90f + f91fef4 commit 67b77cc

File tree

10 files changed

+34
-27
lines changed

10 files changed

+34
-27
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.5.1
7+
ARG PY_ARD_VERSION=1.5.2
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.5.1"
5+
version: "1.5.2"
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
@@ -26,7 +26,7 @@
2626
from .misc import get_imgt_db_versions as db_versions
2727

2828
__author__ = """NMDP Bioinformatics"""
29-
__version__ = "1.5.1"
29+
__version__ = "1.5.2"
3030

3131

3232
def init(

pyard/ard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ def _redux_allele(
189189
hla, allele_name = allele.split("-")
190190
redux_allele = self._redux_allele(allele_name, redux_type)
191191
if redux_allele:
192+
if "/" in redux_allele:
193+
return "/".join(["HLA-" + ra for ra in redux_allele.split("/")])
192194
return "HLA-" + redux_allele
193195
else:
194196
return redux_allele
@@ -246,9 +248,7 @@ def _redux_allele(
246248
elif redux_type == "P" and allele in self.ars_mappings.p_group:
247249
return self.ars_mappings.p_group[allele]
248250
elif redux_type in ["lgx", "lg"]:
249-
if allele in self.ars_mappings.dup_lgx:
250-
redux_allele = self.ars_mappings.dup_lgx[allele]
251-
elif allele in self.ars_mappings.lgx_group:
251+
if allele in self.ars_mappings.lgx_group:
252252
redux_allele = self.ars_mappings.lgx_group[allele]
253253
else:
254254
# for 'lgx' or 'lg' mode when allele is not in G group,

pyard/data_repository.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
get_1field_allele,
5151
)
5252
from .serology import broad_splits_dna_mapping, SerologyMapping
53+
from .smart_sort import smart_sort_comparator
5354

5455

5556
def expression_reduce(df):
@@ -154,6 +155,24 @@ def generate_ard_mapping(db_connection: sqlite3.Connection, imgt_version) -> ARS
154155
)
155156
lgx_group = df_lgx.set_index("A")["lgx"].to_dict()
156157

158+
# Find the alleles that have more than 1 mapping
159+
dup_lgx = (
160+
df_g_group[df_g_group["2d"].isin(multiple_lgx_list)][["lgx", "2d"]]
161+
.drop_duplicates()
162+
.groupby("2d", as_index=True)
163+
.agg(list)
164+
.to_dict()["lgx"]
165+
)
166+
# Do not keep duplicate alleles for lgx. Issue #333
167+
# DPA1*02:02/DPA1*02:07 ==> DPA1*02:02
168+
#
169+
lowest_numbered_dup_lgx = {
170+
k: sorted(v, key=functools.cmp_to_key(smart_sort_comparator))[0]
171+
for k, v in dup_lgx.items()
172+
}
173+
# Update the lgx_group with the allele with the lowest number
174+
lgx_group.update(lowest_numbered_dup_lgx)
175+
157176
# Extract exon mapping
158177
df_exon = pd.concat(
159178
[
@@ -164,7 +183,6 @@ def generate_ard_mapping(db_connection: sqlite3.Connection, imgt_version) -> ARS
164183

165184
ars_mapping = ARSMapping(
166185
dup_g=dup_g,
167-
dup_lgx=dup_lgx,
168186
g_group=g_group,
169187
p_group=p_group,
170188
lgx_group=lgx_group,

pyard/db.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,6 @@ def set_user_version(connection: sqlite3.Connection, version: int):
461461

462462
def load_ars_mappings(db_connection):
463463
dup_g = load_dict(db_connection, table_name="dup_g", columns=("allele", "g_group"))
464-
dup_lgx = load_dict(
465-
db_connection, table_name="dup_lgx", columns=("allele", "lgx_group")
466-
)
467464
g_group = load_dict(db_connection, table_name="g_group", columns=("allele", "g"))
468465
p_group = load_dict(db_connection, table_name="p_group", columns=("allele", "p"))
469466
lgx_group = load_dict(
@@ -475,7 +472,6 @@ def load_ars_mappings(db_connection):
475472
p_not_g = load_dict(db_connection, table_name="p_not_g", columns=("allele", "lgx"))
476473
return ARSMapping(
477474
dup_g=dup_g,
478-
dup_lgx=dup_lgx,
479475
g_group=g_group,
480476
p_group=p_group,
481477
lgx_group=lgx_group,
@@ -497,12 +493,6 @@ def save_ars_mappings(db_connection: sqlite3.Connection, ars_mapping: ARSMapping
497493
dictionary=ars_mapping.dup_g,
498494
columns=("allele", "g_group"),
499495
)
500-
save_dict(
501-
db_connection,
502-
table_name="dup_lgx",
503-
dictionary=ars_mapping.dup_lgx,
504-
columns=("allele", "lgx_group"),
505-
)
506496
save_dict(
507497
db_connection,
508498
table_name="g_group",

pyard/mappings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
ars_mapping_tables = [
2525
"dup_g",
26-
"dup_lgx",
2726
"g_group",
2827
"p_group",
2928
"lgx_group",

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.5.1
2+
current_version = 1.5.2
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.5.1",
39+
version="1.5.2",
4040
description="ARD reduction for HLA with Python",
4141
long_description=readme,
4242
long_description_content_type="text/markdown",

tests/features/p_g_group.feature

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ Feature: P and G Groups
9090
| C*02:10 | lg | C*02:02g |
9191
| C*02:10 | lgx | C*02:02 |
9292

93-
Examples: lgx with duplicates
94-
| Allele | Level | Redux Allele |
95-
| DPA1*02:12 | lgx | DPA1*02:02/DPA1*02:07 |
96-
| DPA1*02:12 | lg | DPA1*02:02g/DPA1*02:07g |
97-
| DQA1*03:03 | lgx | DQA1*03:01 |
98-
| DQA1*03:03 | lg | DQA1*03:01g |
99-
| DQA1*03:03:09 | lg | DQA1*03:03g |
93+
Examples: lgx redux with duplicate G groups
94+
| Allele | Level | Redux Allele |
95+
| DPA1*02:12 | lgx | DPA1*02:02 |
96+
| DPA1*02:12 | lg | DPA1*02:02g |
97+
| DQA1*03:03 | lgx | DQA1*03:01 |
98+
| DQA1*03:03 | lg | DQA1*03:01g |
99+
| DQA1*03:03:09 | lg | DQA1*03:03g |

0 commit comments

Comments
 (0)