Skip to content

Commit

Permalink
Add HLA normalization via py-ard
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaitodor committed Jan 25, 2024
1 parent 26b6776 commit 66d10f1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/api_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,28 @@ paths:
type: string
example: "NM_021960.4:c.740C>T"

/utilities/normalize-hla:
get:
summary: "Normalize HLA"
operationId: "app.utilities_endpoints.normalize_hla"
tags:
- "Operations Utilities (not part of balloted HL7 Operations)"
responses:
"200":
description: "Returns a normalized HLA ARD allele."
content:
application/json:
schema:
type: object
parameters:
- name: allele
in: query
required: true
description: "Allele."
schema:
type: string
example: "B14"

tags:
- name: Subject Genotype Operations
- name: Subject Phenotype Operations
Expand Down
25 changes: 25 additions & 0 deletions app/utilities_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os

from flask import abort, jsonify
from collections import OrderedDict
from app import common
from app import input_normalization
from utilities import SPDI_Normalization
import pyard

pyard_database_version = os.getenv('PYARD_DATABASE_VERSION', '3550')
ard = pyard.init(data_dir='./pyard', imgt_version=pyard_database_version)


def get_feature_coordinates(
Expand Down Expand Up @@ -208,3 +214,22 @@ def normalize_variant(variant):
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
abort(422, 'Failed LiftOver')


def normalize_hla(allele):
try:
return {
allele: {
"G": ard.redux(allele, "G"),
"P": ard.redux(allele, "P"),
"lg": ard.redux(allele, "lg"),
"lgx": ard.redux(allele, "lgx"),
"W": ard.redux(allele, "W"),
"exon": ard.redux(allele, "exon"),
"U2": ard.redux(allele, "U2"),
"S": ard.redux(allele, "S")
}
}
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
abort(422, 'Failed HLA normalization')
10 changes: 10 additions & 0 deletions fetch_refseq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ tar -xzf GRCh38_refseq.tar.gz
tar -xzf rna_refseq.tar.gz

echo "Finished extracting refseq files."

# TODO: REFACTOR THIS!
cd ..
mkdir -p ./pyard
cd ./pyard
curl -sLO https://github.com/FHIR/genomics-operations/releases/download/113c119/pyard.sqlite3.tar.gz

echo "Extracting pyard database..."
tar -xzf pyard.sqlite3.tar.gz
echo "Finished extracting pyard database."
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Flask==2.2.2
flask_cors==4.0.0
gunicorn==20.1.0
hgvs==1.5.4
pandas==1.3.5
pandas==1.5.3
py-ard==1.0.10
pyfastx==2.0.1
pyliftover==0.4
pymongo==4.2.0
Expand Down

0 comments on commit 66d10f1

Please sign in to comment.