Skip to content

Commit 1aaf933

Browse files
committed
WIP
Signed-off-by: Mihai Todor <todormihai@gmail.com>
1 parent faa468d commit 1aaf933

File tree

7 files changed

+25
-65
lines changed

7 files changed

+25
-65
lines changed

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"type": "debugpy",
2424
"request": "launch",
2525
"program": "${file}",
26+
"cwd": "${fileDirname}",
2627
"console": "integratedTerminal",
2728
"justMyCode": false
2829
}

app/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import os
2+
13
import connexion
24
import flask
5+
import hgvs
36
from flask_cors import CORS
4-
import os
57

6-
import hgvs
78
# Disable the hgvs LRU cache to avoid blowing up memory
89
# TODO: Revisit this, since this caching might not use a ton of memory.
910
hgvs.global_config.lru_cache.maxsize = 0

app/endpoints.py

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from collections import OrderedDict
2+
23
from flask import abort, jsonify
3-
from app import common
4-
from app import utilities_endpoints
4+
5+
from app import common, utilities_endpoints
56

67

78
def find_subject_variants(
@@ -180,11 +181,7 @@ def find_subject_specific_variants(
180181
subject = subject.strip()
181182
common.validate_subject(subject)
182183

183-
try:
184-
variants = list(map(common.get_variant, variants))
185-
except Exception as err:
186-
print(f"Unexpected {err=}, {type(err)=}")
187-
abort(422, 'Failed LiftOver')
184+
variants = list(map(common.get_variant, variants))
188185

189186
# Query
190187
query = {}
@@ -836,22 +833,13 @@ def find_subject_tx_implications(
836833
ranges = list(map(common.get_range, ranges))
837834
common.get_lift_over_range(ranges)
838835

839-
try:
840-
variants = common.get_variants(ranges, query)
841-
except Exception as err:
842-
print(f"Unexpected {err=}, {type(err)=}")
843-
abort(422, 'Failed LiftOver')
844-
836+
variants = common.get_variants(ranges, query)
845837
if not variants:
846838
return jsonify({"resourceType": "Parameters"})
847839
normalized_variants = [{variant["BUILD"]: variant["SPDI"]} for variant in variants]
848840

849841
if variants and not ranges:
850-
try:
851-
normalized_variants = list(map(common.get_variant, variants))
852-
except Exception as err:
853-
print(f"Unexpected {err=}, {type(err)=}")
854-
abort(422, 'Failed LiftOver')
842+
normalized_variants = list(map(common.get_variant, variants))
855843

856844
# Result Object
857845
result = OrderedDict()
@@ -1110,22 +1098,13 @@ def find_subject_dx_implications(
11101098
ranges = list(map(common.get_range, ranges))
11111099
common.get_lift_over_range(ranges)
11121100

1113-
try:
1114-
variants = common.get_variants(ranges, query)
1115-
except Exception as err:
1116-
print(f"Unexpected {err=}, {type(err)=}")
1117-
abort(422, 'Failed LiftOver')
1118-
1101+
variants = common.get_variants(ranges, query)
11191102
if not variants:
11201103
return jsonify({"resourceType": "Parameters"})
11211104
normalized_variants = [{variant["BUILD"]: variant["SPDI"]} for variant in variants]
11221105

11231106
if variants and not ranges:
1124-
try:
1125-
normalized_variants = list(map(common.get_variant, variants))
1126-
except Exception as err:
1127-
print(f"Unexpected {err=}, {type(err)=}")
1128-
abort(422, 'Failed LiftOver')
1107+
normalized_variants = list(map(common.get_variant, variants))
11291108

11301109
# Result Object
11311110
result = OrderedDict()
@@ -1488,11 +1467,7 @@ def find_population_specific_variants(
14881467
# Parameters
14891468
variants = list(map(lambda x: x.strip().split(","), variants))
14901469
for i in range(len(variants)):
1491-
try:
1492-
variants[i] = list(map(common.get_variant, variants[i]))
1493-
except Exception as err:
1494-
print(f"Unexpected {err=}, {type(err)=}")
1495-
abort(422, 'Failed LiftOver')
1470+
variants[i] = list(map(common.get_variant, variants[i]))
14961471

14971472
# Query
14981473
query = {}
@@ -2001,11 +1976,7 @@ def find_population_tx_implications(
20011976
return jsonify({"resourceType": "Parameters"})
20021977

20031978
if variants:
2004-
try:
2005-
variants = list(map(common.get_variant, variants))
2006-
except Exception as err:
2007-
print(f"Unexpected {err=}, {type(err)=}")
2008-
abort(422, 'Failed LiftOver')
1979+
variants = list(map(common.get_variant, variants))
20091980

20101981
condition_code_list = []
20111982
if conditions:
@@ -2217,11 +2188,7 @@ def find_population_dx_implications(
22172188
return jsonify({"resourceType": "Parameters"})
22182189

22192190
if variants:
2220-
try:
2221-
variants = list(map(common.get_variant, variants))
2222-
except Exception as err:
2223-
print(f"Unexpected {err=}, {type(err)=}")
2224-
abort(422, 'Failed LiftOver')
2191+
variants = list(map(common.get_variant, variants))
22252192

22262193
condition_code_list = []
22272194
if conditions:

app/input_normalization.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
from utilities.spdi_refseq import normalize as spdi_normalize
88

9-
from . import common
9+
from .common import get_build_and_chrom_by_ref_seq, lift_over
1010

1111
# Set the HGVS_SEQREPO_URL env var so the hgvs library will use the local `utilities/seqfetcher` endpoint instead of
1212
# making NCBI API calls.
13-
port = os.environ('PORT', 5000) # The localhost debugger starts the app on port 5000
14-
os.environ('HGVS_SEQREPO_URL') = f"http://127.0.0.1:{port}/utilities/seqfetcher"
13+
port = os.environ.get('PORT', 5000) # The localhost debugger starts the app on port 5000
14+
os.environ['HGVS_SEQREPO_URL'] = f"http://127.0.0.1:{port}/utilities/seqfetcher"
1515

1616
database_schema = os.environ['UTA_DATABASE_SCHEMA']
1717
# Use the biocommons UTA database if we don't specify a custom one.
@@ -113,8 +113,8 @@ def process_NC_HGVS(NC_HGVS):
113113
print(f"b37normalized: {b37SPDI}; b38normalized: {b38SPDI}")
114114

115115
except Exception:
116-
provided_genomic_build = common.get_build_and_chrom_by_ref_seq(parsed_variant.ac)
117-
liftover = common.lift_over(parsed_variant.ac, str(parsed_variant.posedit.pos.start), str(parsed_variant.posedit.pos.end))
116+
provided_genomic_build = get_build_and_chrom_by_ref_seq(parsed_variant.ac)
117+
liftover = lift_over(parsed_variant.ac, str(parsed_variant.posedit.pos.start), str(parsed_variant.posedit.pos.end))
118118
iv = hgvs.location.Interval(start=liftover['start'], end=liftover['end'])
119119
posedit = hgvs.posedit.PosEdit(pos=iv, edit=parsed_variant.posedit.edit)
120120
lifted_variant = hgvs.sequencevariant.SequenceVariant(ac=liftover['refSeq'], type="g", posedit=posedit)

requirements.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,17 @@ pyfastx==2.0.1
99
pymongo==4.2.0
1010
pyranges==0.0.120
1111
python_dateutil==2.8.2
12-
requests==2.28.1
12+
requests==2.32.5
1313
streamlit==1.19.0
14-
<<<<<<< HEAD
1514
streamlit-aggrid==1.0.5
1615
pytest==7.1.1
17-
=======
18-
pytest==7.1.1
19-
deepdiff==6.7.1
20-
>>>>>>> 1b4630a (Add SPDI normalization with refseq files)
2116
python-dotenv==1.0.1
2217
toml==0.10.2
2318
pandas==2.2.2
2419
numpy==2.0.2
2520
pyliftover==0.4
2621
hgvs==1.5.4
2722
py-ard==1.5.3
28-
<<<<<<< HEAD
2923
openpyxl==3.1.5
3024
pyvcf3==1.0.3
3125
tqdm==4.65.1
32-
=======
33-
>>>>>>> 1b4630a (Add SPDI normalization with refseq files)

utilities/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
PROJECT_ROOT = BASE_DIR.parent
1212
load_dotenv(PROJECT_ROOT / "secrets.env")
1313

14-
utilities_data_client_uri = f"mongodb+srv://readonly:{os.environ('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/UtilitiesData"
14+
utilities_data_client_uri = f"mongodb+srv://readonly:{os.environ['MONGODB_READONLY_PASSWORD']}@cluster0.8ianr.mongodb.net/UtilitiesData"
1515
utilities_client = pymongo.MongoClient(utilities_data_client_uri)
1616
utilities_db = utilities_client.UtilitiesData
1717
transcript_data = utilities_db.Transcripts

utilities/vcf2json.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import common
88
import pyfastx
99
import vcf
10-
11-
from .gene_ref_seq import get_ref_seq_by_chrom
12-
from .spdi import normalize
10+
from gene_ref_seq import get_ref_seq_by_chrom
11+
from spdi import normalize
1312

1413
# Fasta file handles cache
1514
fasta_cache = {}
@@ -34,7 +33,7 @@ def get_fasta(file):
3433
def normalize_spdi(ref_seq, pos, ref, alt, build):
3534
fasta = get_fasta(BUILD37_FILE) if build == 'GRCh37' else get_fasta(BUILD38_FILE)
3635

37-
return normalize(fasta[ref_seq], pos, ref, alt)
36+
return normalize(fasta[ref_seq], ref_seq, pos, ref, alt)
3837

3938

4039
def add_phase_records(record, phased_rec_map, sample_position):

0 commit comments

Comments
 (0)