Skip to content

Commit bc3789d

Browse files
Decode MAC and CWD 2.0 Reductions (#224)
* Supports Decoding to MAC code from allele list * exclude tests for distribution * CWD Reduction - add `cwd_redux` method to produce CWD only allele list - create `cwd2` table on load - `cwd-redux` endpoint to allow CWD reduction * Bump version to 1.0.0rc5 * Set the sample files name the same as remote. * Documentation on CWD changes * Make P,G group alleles explicit lookups. * - renamed method to `lookup_mac` to align with terminology - Updated README with links to MacUI - Fixed api verbage * Allow P group in `redux` REST endpoint
1 parent b6fcf2d commit bc3789d

File tree

19 files changed

+802
-42
lines changed

19 files changed

+802
-42
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.0rc4
7+
ARG PY_ARD_VERSION=1.0.0rc5
88

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

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include LICENSE
66
include README.rst
77
include pyard/*.csv
88

9-
recursive-include tests *
9+
recursive-exclude tests *
1010
recursive-exclude * __pycache__
1111
recursive-exclude * *.py[co]
1212

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Human leukocyte antigen (HLA) genes encode cell surface proteins that are import
2121
* [Using `py-ard` from R](#using-py-ard-from-r-code)
2222
* [Perform Reduxtion](#reduce-typings)
2323
* [DRBX blending](#perform-drb1-blending-with-drb3-drb4-and-drb5)
24+
* [Expand/Lookup MAC](#mac-codes)
2425
3. [Command Line Tools](#command-line-tools)
2526
* [`pyard-import` Import Reference Data](#pyard-import-import-the-latest-ipd-imgthla-database)
2627
* [`pyard-status` Show Statuses of Databases](#pyard-status-show-database-status)
@@ -183,12 +184,41 @@ pyard.dr_blender(drb1='HLA-DRB1*03:01+DRB1*04:01', drb3='DRB3*01:01', drb4='DRB4
183184
# >>> 'DRB3*01:01+DRB4*01:03'
184185
```
185186

186-
### Expand MAC codes
187+
## MAC Codes
188+
189+
`py-ard` supports not only reducing to various types but helps in expanding and
190+
looking up MAC representation. See [MAC Service UI](https://hml.nmdp.org/MacUI/) for detail.
191+
192+
### Expand MAC
187193

188194
You can also use `py-ard` to expand MAC codes. Use `expand_mac` method on `ard`.
189195
```python
190196
ard.expand_mac('HLA-A*01:BC')
191-
# ['HLA-A*01:02', 'HLA-A*01:03']
197+
# 'HLA-A*01:02/HLA-A*01:03'
198+
```
199+
200+
### Lookup MAC
201+
202+
Find the corresponding MAC code for an allele list GL String.
203+
204+
```python
205+
ard.lookup_mac('A*01:02/A*01:01/A*01:03')
206+
# A*01:MN
207+
```
208+
209+
### CWD Reduction
210+
211+
Reduce a MAC code or an allele list GL String to CWD reduced list.
212+
```python
213+
ard.cwd_redux("B*15:01:01/B*15:01:03/B*15:04/B*15:07/B*15:26N/B*15:27")
214+
# => B*15:01/B*15:07
215+
```
216+
217+
The above 2 methods can be chained to get back a MAC code that has a CWD reduced version.
218+
219+
```python
220+
ard.lookup_mac(ard.cwd_redux("B*15:01:01/B*15:01:03/B*15:04/B*15:07/B*15:26N/B*15:27"))
221+
# 'B*15:AH'
192222
```
193223

194224
### Using `py-ard` from R code

api-spec.yaml

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ openapi: 3.0.3
22
info:
33
title: ARD Reduction
44
description: Reduce to ARD Level
5-
version: "1.0.0rc4"
5+
version: "1.0.0rc5"
66
servers:
77
- url: 'http://localhost:8080'
88
tags:
99
- name: Database
1010
description: IPD-IMGT/HLA DB Information
1111
- name: ARD Reduction
1212
description: Reduce GL String to ARD
13-
- name: MAC Expansion
14-
description: Expand MAC to alleles
13+
- name: MAC
14+
description: Expand/Collapse MAC to/from alleles
1515
- name: DRBX Blender
1616
description: Blend DRBX based on DRB1 and DRB3/4/5
1717
- name: Validation
@@ -55,6 +55,7 @@ paths:
5555
type: string
5656
enum:
5757
- G
58+
- P
5859
- lg
5960
- lgx
6061
- W
@@ -84,10 +85,59 @@ paths:
8485
description: Describes what went wrong
8586
type: string
8687
example: "Invalid HLA locus"
88+
/cwd-redux:
89+
post:
90+
tags:
91+
- CWD Reduction
92+
operationId: api.cwd_redux_controller
93+
summary: Reduce to CWD/MAC
94+
description: |
95+
Given a GL String of Allele List or a MAC find only the CWD alleles and a corresponding
96+
MAC if available.
97+
requestBody:
98+
content:
99+
application/json:
100+
schema:
101+
properties:
102+
gl_string:
103+
description: GL String of Allele List or a MAC code
104+
type: string
105+
example: "A*26:CBJTR"
106+
responses:
107+
200:
108+
description: CWD Result
109+
content:
110+
application/json:
111+
schema:
112+
type: object
113+
properties:
114+
gl_string:
115+
description: GL String of Allele List or a MAC code
116+
type: string
117+
example: "A*26:CBJTR"
118+
cwd:
119+
description: CWD reduced version of GL String
120+
type: string
121+
example: "A*26:01/A*25:01"
122+
cwd_mac:
123+
description: MAC of reduced CWD if available
124+
type: string
125+
example: "A*26:BYHR"
126+
400:
127+
description: Invalid GL String Form
128+
content:
129+
application/json:
130+
schema:
131+
type: object
132+
properties:
133+
message:
134+
description: Describes what went wrong
135+
type: string
136+
example: "Invalid HLA locus"
87137
/mac/{allele_code}:
88138
get:
89139
tags:
90-
- MAC Expansion
140+
- MAC
91141
operationId: api.mac_expand_controller
92142
summary: Expand MAC (Allele Code)
93143
description: |
@@ -116,7 +166,57 @@ paths:
116166
description: GL String version of expanded MAC
117167
type: string
118168
example: "HLA-A*01:01/HLA-A*01:02"
119-
expansion:
169+
alleles:
170+
description: Alleles corresponding to MAC
171+
type: array
172+
example:
173+
- "HLA-A*01:01"
174+
- "HLA-A*01:02"
175+
400:
176+
description: Invalid MAC Code
177+
content:
178+
application/json:
179+
schema:
180+
type: object
181+
properties:
182+
message:
183+
description: MAC Code is not valid
184+
type: string
185+
example: "Invalid MAC Code"
186+
/mac:
187+
post:
188+
tags:
189+
- MAC
190+
operationId: api.mac_lookup_controller
191+
summary: Lookup MAC from Alleles
192+
description: |
193+
Given a allele list as a GL String, find corresponding MAC
194+
requestBody:
195+
content:
196+
application/json:
197+
schema:
198+
properties:
199+
gl_string:
200+
description: GL String version of allele list
201+
type: string
202+
example: "HLA-A*01:01/HLA-A*01:02"
203+
responses:
204+
200:
205+
description: MAC corresponding to Alleles
206+
content:
207+
application/json:
208+
schema:
209+
type: object
210+
properties:
211+
mac:
212+
description: MAC
213+
type: string
214+
example: "HLA-A*01:AB"
215+
gl_string:
216+
description: Supplied GL String
217+
type: string
218+
example: "HLA-A*01:01/HLA-A*01:02"
219+
alleles:
120220
description: Alleles corresponding to MAC
121221
type: array
122222
example:

api.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,32 @@ def redux_controller():
5353
def mac_expand_controller(allele_code: str):
5454
try:
5555
if ard.is_mac(allele_code):
56-
alleles = ard.expand_mac(allele_code)
56+
allele_list = ard.expand_mac(allele_code)
5757
return {
5858
"mac": allele_code,
59-
"alleles": alleles,
60-
"gl_string": "/".join(alleles),
59+
"alleles": allele_list.split("/"),
60+
"gl_string": allele_list,
6161
}, 200
6262
else:
6363
return {"message": f"{allele_code} is not a valid MAC"}, 404
6464
except PyArdError as e:
6565
return {"message": e.message}, 400
6666

6767

68+
def mac_lookup_controller():
69+
if request.json:
70+
try:
71+
allele_list = request.json["gl_string"]
72+
mac_code = ard.lookup_mac(allele_list)
73+
return {
74+
"mac": mac_code,
75+
"alleles": allele_list.split("/"),
76+
"gl_string": allele_list,
77+
}, 200
78+
except PyArdError as e:
79+
return {"message": e.message}, 400
80+
81+
6882
def drbx_blender_controller():
6983
if request.json:
7084
try:
@@ -93,3 +107,31 @@ def splits_controller(allele: str):
93107
return {"broad": mapping[0], "splits": mapping[1]}, 200
94108

95109
return {"message": f"No Broad/Splits matched {allele}"}, 404
110+
111+
112+
def cwd_redux_controller():
113+
if request.json:
114+
# Check the request has required inputs
115+
try:
116+
gl_string = request.json["gl_string"]
117+
except KeyError:
118+
return {"message": "gl_string and reduction_method not provided"}, 404
119+
# Perform redux
120+
try:
121+
cwd = ard.cwd_redux(ard.redux(gl_string, "lgx"))
122+
except PyArdError as e:
123+
return {"message": e.message}, 400
124+
125+
# If the cwd reduction is a single locus or empty
126+
if "/" in cwd:
127+
try:
128+
cwd_mac = ard.lookup_mac(cwd)
129+
except pyard.exceptions.InvalidMACError as e:
130+
cwd_mac = ""
131+
else:
132+
cwd_mac = ""
133+
134+
return {"gl_string": gl_string, "cwd": cwd, "cwd_mac": cwd_mac}, 200
135+
136+
# if no data is sent
137+
return {"message": "No input data provided"}, 404

0 commit comments

Comments
 (0)