33import os
44import subprocess
55import tempfile
6+ from collections .abc import Mapping
67from pathlib import Path
78from urllib .parse import urlparse
89
1920 ScoresetNotSupportedError ,
2021)
2122from dcd_mapping .lookup import get_chromosome_identifier , get_gene_location
22- from dcd_mapping .mavedb_data import LOCAL_STORE_PATH
23+ from dcd_mapping .mavedb_data import LOCAL_STORE_PATH , patch_target_sequence_type
2324from dcd_mapping .resource_utils import http_download
2425from dcd_mapping .schemas import (
2526 AlignmentResult ,
@@ -441,7 +442,7 @@ def parse_cdot_mapping(cdot_mapping: dict, silent: bool) -> AlignmentResult:
441442
442443def build_alignment_result (
443444 metadata : ScoresetMetadata , silent : bool
444- ) -> dict [str , AlignmentResult | None ]:
445+ ) -> Mapping [str , AlignmentResult | None ]:
445446 # NOTE: Score set must contain all accession-based target genes or all sequence-based target genes
446447 # This decision was made because it is most efficient to run BLAT all together, so the alignment function
447448 # works on an entire score set rather than per target gene.
@@ -462,7 +463,25 @@ def build_alignment_result(
462463 score_set_type = "sequence"
463464
464465 if score_set_type == "sequence" :
465- alignment_result = align (metadata , silent )
466+ try :
467+ alignment_result = align (metadata , silent )
468+ except AlignmentError as e :
469+ failed_at_nucleotide_level = any (
470+ target_gene .target_sequence_type == TargetSequenceType .DNA
471+ for target_gene in metadata .target_genes .values ()
472+ )
473+
474+ if failed_at_nucleotide_level :
475+ msg = f"BLAT alignment failed for { metadata .urn } at the nucleotide level. This alignment will be retried at the protein level."
476+ _logger .warning (msg )
477+ else :
478+ raise AlignmentError from e
479+
480+ # So long as force=True, the content of the records dict is irrelevant.
481+ alignment_result = align (
482+ patch_target_sequence_type (metadata , {}, force = True ), silent
483+ )
484+
466485 else :
467486 alignment_result = fetch_alignment (metadata , silent )
468487
0 commit comments