Skip to content

Commit 28289d4

Browse files
committed
fix: update logic in patch_target_sequence_type to handle cases with no nucleotide variants
1 parent efe1ca4 commit 28289d4

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/dcd_mapping/mavedb_data.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,19 @@ def get_scoreset_records(
329329
def patch_target_sequence_type(
330330
metadata: ScoresetMetadata, records: dict
331331
) -> ScoresetMetadata:
332-
"""If target sequence type is DNA but all variants are protein-level, change to protein.
332+
"""If target sequence type is DNA but no nucleotide variants are defined, treat the target as if
333+
it were a protein level target.
333334
This avoids BLAT errors in cases where the target sequence was codon-optimized
334335
for a non-human organism
335336
"""
336337
for target_label, target in metadata.target_genes.items():
337-
if target.target_sequence_type == TargetSequenceType.DNA:
338-
all_protein = True
339-
for record in records.get(target_label, []):
340-
if record.hgvs_pro == "NA" or not record.hgvs_pro:
341-
all_protein = False
342-
break
343-
if all_protein:
344-
msg = f"Changing target sequence type for {metadata.urn} target {target_label} from DNA to protein because all variants are protein-level"
345-
_logger.info(msg)
346-
target.target_sequence = _get_protein_sequence(target.target_sequence)
347-
target.target_sequence_type = TargetSequenceType.PROTEIN
338+
if target.target_sequence_type == TargetSequenceType.DNA and not any(
339+
record.hgvs_nt for record in records.get(target_label, [])
340+
):
341+
msg = f"Changing target sequence type for {metadata.urn} target {target_label} from DNA to protein because target only has protein-level variants"
342+
_logger.info(msg)
343+
target.target_sequence = _get_protein_sequence(target.target_sequence)
344+
target.target_sequence_type = TargetSequenceType.PROTEIN
348345
return metadata
349346

350347

0 commit comments

Comments
 (0)