Skip to content

Commit 66d10f1

Browse files
committed
Add HLA normalization via py-ard
1 parent 26b6776 commit 66d10f1

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

app/api_spec.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,28 @@ paths:
12251225
type: string
12261226
example: "NM_021960.4:c.740C>T"
12271227

1228+
/utilities/normalize-hla:
1229+
get:
1230+
summary: "Normalize HLA"
1231+
operationId: "app.utilities_endpoints.normalize_hla"
1232+
tags:
1233+
- "Operations Utilities (not part of balloted HL7 Operations)"
1234+
responses:
1235+
"200":
1236+
description: "Returns a normalized HLA ARD allele."
1237+
content:
1238+
application/json:
1239+
schema:
1240+
type: object
1241+
parameters:
1242+
- name: allele
1243+
in: query
1244+
required: true
1245+
description: "Allele."
1246+
schema:
1247+
type: string
1248+
example: "B14"
1249+
12281250
tags:
12291251
- name: Subject Genotype Operations
12301252
- name: Subject Phenotype Operations

app/utilities_endpoints.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import os
2+
13
from flask import abort, jsonify
24
from collections import OrderedDict
35
from app import common
46
from app import input_normalization
57
from utilities import SPDI_Normalization
8+
import pyard
9+
10+
pyard_database_version = os.getenv('PYARD_DATABASE_VERSION', '3550')
11+
ard = pyard.init(data_dir='./pyard', imgt_version=pyard_database_version)
612

713

814
def get_feature_coordinates(
@@ -208,3 +214,22 @@ def normalize_variant(variant):
208214
except Exception as err:
209215
print(f"Unexpected {err=}, {type(err)=}")
210216
abort(422, 'Failed LiftOver')
217+
218+
219+
def normalize_hla(allele):
220+
try:
221+
return {
222+
allele: {
223+
"G": ard.redux(allele, "G"),
224+
"P": ard.redux(allele, "P"),
225+
"lg": ard.redux(allele, "lg"),
226+
"lgx": ard.redux(allele, "lgx"),
227+
"W": ard.redux(allele, "W"),
228+
"exon": ard.redux(allele, "exon"),
229+
"U2": ard.redux(allele, "U2"),
230+
"S": ard.redux(allele, "S")
231+
}
232+
}
233+
except Exception as err:
234+
print(f"Unexpected {err=}, {type(err)=}")
235+
abort(422, 'Failed HLA normalization')

fetch_refseq.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ tar -xzf GRCh38_refseq.tar.gz
2121
tar -xzf rna_refseq.tar.gz
2222

2323
echo "Finished extracting refseq files."
24+
25+
# TODO: REFACTOR THIS!
26+
cd ..
27+
mkdir -p ./pyard
28+
cd ./pyard
29+
curl -sLO https://github.com/FHIR/genomics-operations/releases/download/113c119/pyard.sqlite3.tar.gz
30+
31+
echo "Extracting pyard database..."
32+
tar -xzf pyard.sqlite3.tar.gz
33+
echo "Finished extracting pyard database."

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Flask==2.2.2
66
flask_cors==4.0.0
77
gunicorn==20.1.0
88
hgvs==1.5.4
9-
pandas==1.3.5
9+
pandas==1.5.3
10+
py-ard==1.0.10
1011
pyfastx==2.0.1
1112
pyliftover==0.4
1213
pymongo==4.2.0

0 commit comments

Comments
 (0)