From 8ee85619de2fbe71c85e5e3b028559500a7acbd4 Mon Sep 17 00:00:00 2001 From: pbashyal-nmdp Date: Fri, 3 Jun 2022 11:57:12 -0500 Subject: [PATCH] /mac Endpoint to expand MAC to alleles --- api-spec.yaml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ api.py | 15 +++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/api-spec.yaml b/api-spec.yaml index c7c769f..7da828d 100644 --- a/api-spec.yaml +++ b/api-spec.yaml @@ -8,6 +8,8 @@ servers: tags: - name: ARD Reduction description: Reduce GL String to ARD + - name: MAC Expansion + description: Expand MAC to alleles paths: /redux: post: @@ -60,6 +62,55 @@ paths: description: Describes what went wrong type: string example: "Invalid HLA locus" + /mac/{allele_code}: + get: + tags: + - MAC Expansion + operationId: api.mac_expand_controller + summary: Expand MAC (Allele Code) + description: | + Given a MAC Code, expand its allele components + parameters: + - name: allele_code + in: path + description: A valid MAC (Allele Code) + required: true + schema: + type: string + example: "HLA-A*01:AB" + responses: + 200: + description: Alleles corresponding to MAC + content: + application/json: + schema: + type: object + properties: + mac: + description: MAC + type: string + example: "HLA-A*01:AB" + gl_string: + description: GL String version of expanded MAC + type: string + example: "HLA-A*01:01/HLA-A*01:02" + expansion: + description: Alleles corresponding to MAC + type: array + example: + - "HLA-A*01:01" + - "HLA-A*01:02" + 400: + description: Invalid MAC Code + content: + application/json: + schema: + type: object + properties: + message: + description: MAC Code is not valid + type: string + example: "Invalid MAC Code" /validate: post: tags: diff --git a/api.py b/api.py index eff3025..b1cec4d 100644 --- a/api.py +++ b/api.py @@ -45,3 +45,18 @@ def redux_controller(): # if no data is sent return {"message": "No input data provided"}, 404 + + +def mac_expand_controller(allele_code: str): + try: + if ard.is_mac(allele_code): + alleles = ard.expand_mac(allele_code) + return { + "mac": allele_code, + "alleles": alleles, + "gl_string": "/".join(alleles), + }, 200 + else: + return {"message": f"{allele_code} is not a valid MAC"}, 404 + except PyArdError as e: + return {"message": e.message}, 400