Skip to content

Commit e22898c

Browse files
committed
Assert type for mypy
1 parent cb11f5d commit e22898c

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/mavedb/scripts/populate_mapped_hgvs.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,31 @@ def get_target_info(score_set: ScoreSet) -> tuple[bool, Optional[str]]:
3030
target_is_coding = True
3131
# only get transcript accession if coding
3232
# accession-based
33-
if target.accession_id:
33+
if target.target_accession and target.target_accession.accession:
3434
# only use accession info if a transcript was specified
35-
if target.accession_id.startswith(("NM", "ENST")):
36-
transcript_accession = target.accession_id
35+
if target.target_accession.accession.startswith(("NM", "ENST")):
36+
transcript_accession = target.target_accession.accession
3737
# sequence-based
38-
elif target.post_mapped_metadata and target.post_mapped_metadata.get("cdna", {}).get("sequence_accessions"):
39-
if len(target.post_mapped_metadata["cdna"]["sequence_accessions"]) == 1:
40-
transcript_accession = target.post_mapped_metadata["cdna"]["sequence_accessions"][0]
38+
if target.post_mapped_metadata:
39+
# assert that post_mapped_metadata is a dict for mypy
40+
assert isinstance(target.post_mapped_metadata, dict)
41+
if target.post_mapped_metadata.get("cdna", {}).get("sequence_accessions"):
42+
if len(target.post_mapped_metadata["cdna"]["sequence_accessions"]) == 1:
43+
transcript_accession = target.post_mapped_metadata["cdna"]["sequence_accessions"][0]
44+
else:
45+
raise ValueError(
46+
f"Multiple cDNA accessions found in post-mapped metadata for target {target.name} in score set {score_set.urn}. Cannot determine which to use."
47+
)
48+
# if sequence-based and no cDNA accession, warn that no transcript was specified
4149
else:
42-
raise ValueError(
43-
f"Multiple cDNA accessions found in post-mapped metadata for target {target.urn} in score set {score_set.urn}. Cannot determine which to use."
50+
# for coding score sets, the mapper should have returned a cdna post mapped metadata entry. Use mane transcript from clingen for now, but warn that we are assuming transcript.
51+
logger.warning(
52+
f"No cDNA accession found in post-mapped metadata for target {target.name} in score set {score_set.urn}. This is expected if variants were only provided at the protein level. If variants are at the nucleotide level, will assume MANE transcript from ClinGen for coding variant."
4453
)
45-
# if sequence-based and no cDNA accession, warn that no transcript was specified
4654
else:
4755
# for coding score sets, the mapper should have returned a cdna post mapped metadata entry. Use mane transcript from clingen for now, but warn that we are assuming transcript.
4856
logger.warning(
49-
f"No cDNA accession found in post-mapped metadata for target {target.urn} in score set {score_set.urn}. This is expected if variants were only provided at the protein level. If variants are at the nucleotide level, will assume MANE transcript from ClinGen for coding variant."
57+
f"No post-mapped metadata for target {target.name} in score set {score_set.urn}. Will assume MANE transcript from ClinGen for coding variant."
5058
)
5159
else:
5260
target_is_coding = False

0 commit comments

Comments
 (0)