Skip to content

Commit 87859df

Browse files
committed
Fix mypy issues resulting from get() calls
1 parent 478671d commit 87859df

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/mavedb/worker/jobs.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ async def map_variants_for_score_set(
347347

348348
try:
349349
if mapping_results:
350-
if not mapping_results.get("mapped_scores"):
350+
mapped_scores = mapping_results.get("mapped_scores")
351+
if not mapped_scores:
351352
# if there are no mapped scores, the score set failed to map.
352353
score_set.mapping_state = MappingState.failed
353354
score_set.mapping_errors = {"error_message": mapping_results.get("error_message")}
@@ -359,10 +360,15 @@ async def map_variants_for_score_set(
359360
# TODO(VariantEffect/dcd-mapping2#3) after adding accession-based score set mapping support:
360361
# this also assumes that the score set is based on a target sequence, not a target accession
361362

362-
if mapping_results.get("computed_genomic_reference_sequence"):
363-
target_sequence = mapping_results["computed_genomic_reference_sequence"]["sequence"]
364-
elif mapping_results.get("computed_protein_reference_sequence"):
365-
target_sequence = mapping_results["computed_protein_reference_sequence"]["sequence"]
363+
computed_genomic_ref = mapping_results.get("computed_genomic_reference_sequence")
364+
mapped_genomic_ref = mapping_results.get("mapped_genomic_reference_sequence")
365+
computed_protein_ref = mapping_results.get("computed_protein_reference_sequence")
366+
mapped_protein_ref = mapping_results.get("mapped_protein_reference_sequence")
367+
368+
if computed_genomic_ref:
369+
target_sequence = computed_genomic_ref["sequence"]
370+
elif computed_protein_ref:
371+
target_sequence = computed_protein_ref["sequence"]
366372
else:
367373
raise NonexistentMappingReferenceError()
368374

@@ -377,11 +383,8 @@ async def map_variants_for_score_set(
377383
).one()
378384

379385
excluded_pre_mapped_keys = {"sequence"}
380-
if (
381-
mapping_results.get("computed_genomic_reference_sequence")
382-
and mapping_results.get("mapped_genomic_reference_sequence")
383-
):
384-
pre_mapped_metadata = mapping_results.get("computed_genomic_reference_sequence")
386+
if computed_genomic_ref and mapped_genomic_ref:
387+
pre_mapped_metadata = computed_genomic_ref
385388
target_gene.pre_mapped_metadata = cast(
386389
{
387390
"genomic": {
@@ -392,13 +395,10 @@ async def map_variants_for_score_set(
392395
JSONB,
393396
)
394397
target_gene.post_mapped_metadata = cast(
395-
{"genomic": mapping_results.get("mapped_genomic_reference_sequence")}, JSONB
398+
{"genomic": mapped_genomic_ref}, JSONB
396399
)
397-
elif (
398-
mapping_results.get("computed_protein_reference_sequence")
399-
and mapping_results.get("mapped_protein_reference_sequence")
400-
):
401-
pre_mapped_metadata = mapping_results.get("computed_protein_reference_sequence")
400+
elif computed_protein_ref and mapped_protein_ref:
401+
pre_mapped_metadata = computed_protein_ref
402402
target_gene.pre_mapped_metadata = cast(
403403
{
404404
"protein": {
@@ -409,14 +409,14 @@ async def map_variants_for_score_set(
409409
JSONB,
410410
)
411411
target_gene.post_mapped_metadata = cast(
412-
{"protein": mapping_results.get("mapped_protein_reference_sequence")}, JSONB
412+
{"protein": mapped_protein_ref}, JSONB
413413
)
414414
else:
415415
raise NonexistentMappingReferenceError()
416416

417417
total_variants = 0
418418
successful_mapped_variants = 0
419-
for mapped_score in mapping_results.get("mapped_scores"):
419+
for mapped_score in mapped_scores:
420420
total_variants += 1
421421
variant_urn = mapped_score.get("mavedb_id")
422422
variant = db.scalars(select(Variant).where(Variant.urn == variant_urn)).one()
@@ -440,9 +440,9 @@ async def map_variants_for_score_set(
440440
post_mapped=mapped_score.get("post_mapped", null()),
441441
variant_id=variant.id,
442442
modification_date=date.today(),
443-
mapped_date=mapping_results.get("mapped_date_utc", null()),
443+
mapped_date=mapping_results["mapped_date_utc"],
444444
vrs_version=mapped_score.get("vrs_version", null()),
445-
mapping_api_version=mapping_results.get("dcd_mapping_version", null()),
445+
mapping_api_version=mapping_results["dcd_mapping_version"],
446446
error_message=mapped_score.get("error_message", null()),
447447
current=True,
448448
)
@@ -456,7 +456,7 @@ async def map_variants_for_score_set(
456456
else:
457457
score_set.mapping_state = MappingState.complete
458458

459-
logging_context["mapped_variants_inserted_db"] = len(mapping_results["mapped_scores"])
459+
logging_context["mapped_variants_inserted_db"] = len(mapped_scores)
460460
logging_context["variants_successfully_mapped"] = successful_mapped_variants
461461
logging_context["mapping_state"] = score_set.mapping_state.name
462462
logging_context["mapping_errors"] = score_set.mapping_errors

0 commit comments

Comments
 (0)