cdot 0.2.34__tar.gz → 0.2.35__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cdot-0.2.34 → cdot-0.2.35}/PKG-INFO +1 -1
- {cdot-0.2.34 → cdot-0.2.35}/cdot/__init__.py +1 -1
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/clean.py +102 -23
- {cdot-0.2.34 → cdot-0.2.35}/cdot.egg-info/PKG-INFO +1 -1
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_clean_hgvs.py +29 -0
- {cdot-0.2.34 → cdot-0.2.35}/LICENSE +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/README.md +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/data_release.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/__init__.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/_version_replacement_blocklist.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/dataproviders/__init__.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/dataproviders/ensembl_tark_data_provider.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/dataproviders/fasta_seqfetcher.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/dataproviders/json_data_provider.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/dataproviders/seqfetcher.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/gene_hgvs.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/translation.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/hgvs/version_safety.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/models.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/pyhgvs/__init__.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot/pyhgvs/pyhgvs_transcript.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot.egg-info/SOURCES.txt +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot.egg-info/dependency_links.txt +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot.egg-info/requires.txt +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/cdot.egg-info/top_level.txt +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/pyproject.toml +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/setup.cfg +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_cdot_gene_info.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_cdot_json_gencode_hgnc.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_cdot_json_gene_info.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_cdot_json_merge.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_check_new_sources.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_data_release.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_docs_in_sync.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_fasta_seqfetcher.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_gene_hgvs.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_gff_parser_golden.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_gff_parsers.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_json_data_provider_ensembl.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_json_data_provider_refseq.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_json_loading.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_models.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_public_api.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_pyhgvs.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_quickstart.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_rest_data_provider_errors.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_rest_data_provider_prefetch.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_retrieve_many.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_struct_dict_compat.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_translation.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_uta_conversion.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_version_safety.py +0 -0
- {cdot-0.2.34 → cdot-0.2.35}/tests/test_version_safety_real_records.py +0 -0
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
a client can read data whose schema (major.minor) is not newer than its own, see
|
|
14
14
|
:func:`get_data_schema_int`.
|
|
15
15
|
"""
|
|
16
|
-
__version__ = "0.2.
|
|
16
|
+
__version__ = "0.2.35"
|
|
17
17
|
# Data version is kept in generate_transcript_data/json_schema_version.py
|
|
18
18
|
|
|
19
19
|
def get_data_schema_int(version: str) -> int:
|
|
@@ -12,6 +12,7 @@ retain full control over HGVS compatibility.
|
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
import re
|
|
15
|
+
import unicodedata
|
|
15
16
|
import warnings
|
|
16
17
|
from dataclasses import dataclass, replace
|
|
17
18
|
from enum import Enum
|
|
@@ -47,6 +48,7 @@ class HGVSFixCode(Enum):
|
|
|
47
48
|
LOWERCASED_MUTATION_TYPE = "lowercased_mutation_type"
|
|
48
49
|
STRIPPED_UNBALANCED_BRACKETS = "stripped_unbalanced_brackets"
|
|
49
50
|
STRIPPED_SURROUNDING_PUNCTUATION = "stripped_surrounding_punctuation"
|
|
51
|
+
REPLACED_UNICODE_DASH = "replaced_unicode_dash"
|
|
50
52
|
FIXED_MULTIPLE_DOT = "fixed_multiple_dot"
|
|
51
53
|
FIXED_PREFIX_COLON = "fixed_prefix_colon"
|
|
52
54
|
STRIPPED_LEADING_JUNK = "stripped_leading_junk"
|
|
@@ -121,6 +123,7 @@ class HGVSCleanOp(Enum):
|
|
|
121
123
|
relies on warns with HGVSCleanOpWarning.
|
|
122
124
|
"""
|
|
123
125
|
STRIP_SURROUNDING_PUNCTUATION = "strip_surrounding_punctuation"
|
|
126
|
+
REPLACE_UNICODE_DASH = "replace_unicode_dash"
|
|
124
127
|
STRIP_PROTEIN_SUFFIX = "strip_protein_suffix"
|
|
125
128
|
STRIP_CONTIG_NAME = "strip_contig_name"
|
|
126
129
|
STRIP_BUILD_NAME = "strip_build_name"
|
|
@@ -285,8 +288,9 @@ def _reference_type(s: str) -> Optional[str]:
|
|
|
285
288
|
|
|
286
289
|
# A trailing protein annotation after a nucleotide allele, eg
|
|
287
290
|
# "NM_000059.4:c.68del p.(Glu23fs)". Any whitespace separates them (a tab is as
|
|
288
|
-
# common as a space in pasted text)
|
|
289
|
-
|
|
291
|
+
# common as a space in pasted text), or a comma/semicolon, which is removed with
|
|
292
|
+
# the annotation ("NM_000059.4:c.68del, p.(Glu23fs)").
|
|
293
|
+
_P_HGVS_REMOVAL = re.compile(r"^(?P<main>.*?)(?:\s*[,;]\s*|\s+)(p\.|[(]p\.).*$")
|
|
290
294
|
# The part before the protein annotation must hold a nucleotide allele (a
|
|
291
295
|
# non-protein kind, or something other than "p." after the colon). Otherwise the
|
|
292
296
|
# "p." is the allele itself, eg "NP_000050.2 p.Arg1Gly", and must be kept.
|
|
@@ -296,10 +300,12 @@ _HAS_NUCLEOTIDE_ALLELE = re.compile(r":\s*(?!p\.)\S|[cgmnr]\.", re.IGNORECASE)
|
|
|
296
300
|
# the type table, used to repair an accession missing its underscore. Requires
|
|
297
301
|
# 6+ digits (every RefSeq accession has at least six) so a real gene symbol that
|
|
298
302
|
# starts with these letters plus a stray digit (eg NR3C1, NS1, ZP3) is never
|
|
299
|
-
# mistaken for an accession and mangled.
|
|
303
|
+
# mistaken for an accession and mangled. A stray bracket, dot or colon typed in
|
|
304
|
+
# place of the underscore ("NM)000059.4", "NM.000059.4", "NM:000059.4") is
|
|
305
|
+
# replaced by it.
|
|
300
306
|
_TWO_LETTER_PREFIXES = sorted({p[:2] for p in _REFSEQ_PREFIX_TYPE})
|
|
301
307
|
_TRANSCRIPT_NO_UNDERSCORE = re.compile(
|
|
302
|
-
rf"^({'|'.join(_TWO_LETTER_PREFIXES)})(\d{{6,}})", re.IGNORECASE)
|
|
308
|
+
rf"^({'|'.join(_TWO_LETTER_PREFIXES)})[().:]?(\d{{6,}})", re.IGNORECASE)
|
|
303
309
|
|
|
304
310
|
# Second letters for which prepending "N" yields a real genomic/transcript prefix
|
|
305
311
|
# (NM, NC, NR, NG, NT, NW, NS, NZ, NP) — used to restore a dropped leading "N".
|
|
@@ -364,15 +370,36 @@ _MISSING_REFERENCE = re.compile(rf"^(?:[:.]|{_KIND}(?:[.:]|{_COORD_START}))")
|
|
|
364
370
|
_PREFIX_COLON_UNDERSCORE = re.compile(
|
|
365
371
|
rf"^({'|'.join(_TWO_LETTER_PREFIXES)}):_", re.IGNORECASE)
|
|
366
372
|
|
|
367
|
-
# Leading junk before an accession
|
|
368
|
-
#
|
|
369
|
-
# "
|
|
370
|
-
|
|
373
|
+
# Leading junk before an accession: a literal "\t", whitespace, or a genome-build
|
|
374
|
+
# prefix like "GRCh38.p2 " / "GRCh37.p12#". Stray punctuation and symbols ("#",
|
|
375
|
+
# ":", "-", a bullet...) are stripped by _is_stray_mark. Only stripped when an
|
|
376
|
+
# accession actually follows.
|
|
377
|
+
_LEADING_JUNK = re.compile(r"GRCh\d+(?:\.p\d+)?[#\s]*|\\t|\s", re.IGNORECASE)
|
|
378
|
+
|
|
379
|
+
# Characters that may end a valid HGVS string (eg "c.(?_-1)", "p.(=)", "c.*") or
|
|
380
|
+
# be part of a truncated one, so are never stripped as a stray trailing mark
|
|
381
|
+
_HGVS_END_CHARS = frozenset(")]=?*>+-_")
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _is_stray_mark(c: str) -> bool:
|
|
385
|
+
""" Punctuation or a symbol (Unicode category P* or S*), eg a bullet, dagger,
|
|
386
|
+
backslash or full stop, as left by copy/paste around an HGVS string """
|
|
387
|
+
return unicodedata.category(c)[0] in "PS"
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def _rstrip_stray_marks(s: str) -> str:
|
|
391
|
+
""" Strip stray marks from the end, keeping any of _HGVS_END_CHARS """
|
|
392
|
+
end = len(s)
|
|
393
|
+
while end and s[end - 1] not in _HGVS_END_CHARS and _is_stray_mark(s[end - 1]):
|
|
394
|
+
end -= 1
|
|
395
|
+
return s[:end]
|
|
371
396
|
|
|
372
397
|
# Gene symbol wedged between extra colons, e.g. "tx:(GENE):c." / "tx:(GENE)c." /
|
|
373
398
|
# "tx:GENE:c." — should be "tx(GENE):c."
|
|
374
399
|
_GENE_WRAPPER = re.compile(
|
|
375
400
|
rf"^({_ANY_ACCESSION_PREFIX}[\w.]+):\(?([A-Za-z][A-Za-z0-9-]+)\)?:?({_KIND}[.,])", re.IGNORECASE)
|
|
401
|
+
# Gene symbol repeated after its parens, e.g. "tx(GENE):GENE:c." -> "tx(GENE):c."
|
|
402
|
+
_GENE_REPEATED_AFTER_PARENS = re.compile(rf"\(([A-Za-z][A-Za-z0-9-]*)\):\1:(?={_KIND}\.)", re.IGNORECASE)
|
|
376
403
|
# Stray colon inside the gene parens, e.g. "(RAD51C:)" -> "(RAD51C)"
|
|
377
404
|
_GENE_PARENS_COLON = re.compile(r"\(([A-Za-z][A-Za-z0-9-]*):\)")
|
|
378
405
|
# Parens wrapping the whole accession, e.g. "(NM_000059.4):c." -> "NM_000059.4:c."
|
|
@@ -417,12 +444,13 @@ _CHROM_NAME = rf"chr(?:{'|'.join(_CHROMOSOMES)})"
|
|
|
417
444
|
_CONTIG_NAME_BEFORE_ACCESSION = re.compile(
|
|
418
445
|
rf"(?<![\w.])({_CHROM_NAME})\s+(?=(NC_\d+)(\.\d+)?(?![\w.]))", re.IGNORECASE)
|
|
419
446
|
|
|
420
|
-
# A gene symbol, whitespace, then an accession, e.g.
|
|
421
|
-
# "APC NM_001407446.1:c.-40G>A"
|
|
447
|
+
# A gene symbol, whitespace (or a ':' or '.'), then an accession, e.g.
|
|
448
|
+
# "APC NM_001407446.1:c.-40G>A" or "APC:NM_001407446.1:c.-40G>A" ->
|
|
449
|
+
# "NM_001407446.1(APC):c.-40G>A". Runs before
|
|
422
450
|
# whitespace stripping, which would otherwise glue the symbol onto the accession
|
|
423
451
|
# ("APCNM_001407446.1"), leaving something that parses as neither.
|
|
424
452
|
_SYMBOL_BEFORE_ACCESSION = re.compile(
|
|
425
|
-
rf"^(?!{_CHROM_NAME}\s)([A-Za-z][A-Za-z0-9-]{{1,9}})\s+({_ANY_ACCESSION_PREFIX}[\w.]+)", re.IGNORECASE)
|
|
453
|
+
rf"^(?!{_CHROM_NAME}[\s:.])([A-Za-z][A-Za-z0-9-]{{1,9}})(?:\s*[:.]\s*|\s+)({_ANY_ACCESSION_PREFIX}[\w.]+)", re.IGNORECASE)
|
|
426
454
|
|
|
427
455
|
# A genome build / assembly name at the start, e.g. "hg19 NM_000059.4:c.68del" or
|
|
428
456
|
# "GRCh38 BRCA2 NM_000059.4:c.68del". Without this the symbol-before-accession
|
|
@@ -702,12 +730,13 @@ def _op_strip_whitespace(s: str) -> tuple[str, list[HGVSFix]]:
|
|
|
702
730
|
|
|
703
731
|
|
|
704
732
|
def _op_strip_surrounding_punctuation(s: str) -> tuple[str, list[HGVSFix]]:
|
|
705
|
-
# Strip stray wrapping quotes/backticks and trailing
|
|
706
|
-
# copy/paste or search boxes, e.g. "NM_000059.4:c.123A>G'"
|
|
707
|
-
# "NM_000059.4:c.123A>G;".
|
|
733
|
+
# Strip stray wrapping quotes/backticks and trailing punctuation or symbols
|
|
734
|
+
# left by copy/paste or search boxes, e.g. "NM_000059.4:c.123A>G'",
|
|
735
|
+
# "NM_000059.4:c.123A>G;", "NM_000059.4:c.123A>G." or a footnote mark
|
|
736
|
+
# ("NM_000059.4:c.123A>G†"). No valid HGVS string starts/ends with these.
|
|
708
737
|
# Surrounding whitespace on its own is left for the whitespace step to strip
|
|
709
738
|
# and report (this op runs first).
|
|
710
|
-
s2 = s.strip().strip("'\"`")
|
|
739
|
+
s2 = _rstrip_stray_marks(s.strip().strip("'\"`")).strip()
|
|
711
740
|
if s2 != s.strip():
|
|
712
741
|
return s2, [HGVSFix(
|
|
713
742
|
severity=HGVSFixSeverity.WARNING,
|
|
@@ -781,9 +810,35 @@ def _op_fix_multiple_kind(s: str) -> tuple[str, list[HGVSFix]]:
|
|
|
781
810
|
original=s, fixed=s2,
|
|
782
811
|
))
|
|
783
812
|
s = s2
|
|
813
|
+
# The kind repeated on the second position of a range, eg
|
|
814
|
+
# "c.67+3_c.67+6del" -> "c.67+3_67+6del"
|
|
815
|
+
if f":{kind}." in s.lower():
|
|
816
|
+
s2 = re.sub(rf"(?<=[\d)])_{kind}\.(?=[\d*\-(])", "_", s, flags=re.IGNORECASE)
|
|
817
|
+
if s2 != s:
|
|
818
|
+
fixes.append(HGVSFix(
|
|
819
|
+
severity=HGVSFixSeverity.WARNING,
|
|
820
|
+
code=HGVSFixCode.FIXED_MULTIPLE_KIND,
|
|
821
|
+
message=f"Removed kind notation '{kind}.' repeated inside a range",
|
|
822
|
+
original=s, fixed=s2,
|
|
823
|
+
))
|
|
824
|
+
s = s2
|
|
784
825
|
return s, fixes
|
|
785
826
|
|
|
786
827
|
|
|
828
|
+
def _op_replace_unicode_dash(s: str) -> tuple[str, list[HGVSFix]]:
|
|
829
|
+
# A typographic dash (Unicode dash punctuation, eg a hyphen or en dash) from a
|
|
830
|
+
# word processor in place of "-", eg "c.67–2A>G" -> "c.67-2A>G"
|
|
831
|
+
s2 = "".join("-" if unicodedata.category(c) == "Pd" else c for c in s)
|
|
832
|
+
if s2 != s:
|
|
833
|
+
return s2, [HGVSFix(
|
|
834
|
+
severity=HGVSFixSeverity.WARNING,
|
|
835
|
+
code=HGVSFixCode.REPLACED_UNICODE_DASH,
|
|
836
|
+
message="Replaced typographic dash with '-'",
|
|
837
|
+
original=s, fixed=s2,
|
|
838
|
+
)]
|
|
839
|
+
return s, []
|
|
840
|
+
|
|
841
|
+
|
|
787
842
|
def _op_add_n_prefix(s: str) -> tuple[str, list[HGVSFix]]:
|
|
788
843
|
# Restore a dropped leading "N" on a RefSeq accession, eg "M_001234" →
|
|
789
844
|
# "NM_001234", "G_012337" → "NG_012337", "R_002196" → "NR_002196". Only fires
|
|
@@ -829,15 +884,15 @@ def _op_strip_unbalanced_brackets(s: str) -> tuple[str, list[HGVSFix]]:
|
|
|
829
884
|
# reconstruction). In the allele a bracket marks an uncertain position
|
|
830
885
|
# ("c.(100_200)del") or a predicted consequence ("p.(Glu23fs)"), and
|
|
831
886
|
# stripping it would make an uncertain variant look certain. The only
|
|
832
|
-
# unambiguous repair there is a
|
|
833
|
-
#
|
|
887
|
+
# unambiguous repair there is a bracket that closes/opens nothing: a
|
|
888
|
+
# trailing ")" or "(", or a "(" before the kind letter. Anything else is left
|
|
834
889
|
# alone and reported as an ERROR.
|
|
835
890
|
reference, sep, allele = _split_reference_allele(s)
|
|
836
891
|
fixes = []
|
|
837
892
|
if not _brackets_balanced(reference):
|
|
838
893
|
reference = reference.replace("(", "").replace(")", "")
|
|
839
894
|
if not _brackets_balanced(allele):
|
|
840
|
-
if allele.endswith(")") and _brackets_balanced(allele[:-1]):
|
|
895
|
+
if allele.endswith((")", "(")) and _brackets_balanced(allele[:-1]):
|
|
841
896
|
allele = allele[:-1]
|
|
842
897
|
elif allele.startswith("(") and _brackets_balanced(allele[1:]):
|
|
843
898
|
allele = allele[1:]
|
|
@@ -907,9 +962,17 @@ def _op_uppercase_bases(s: str) -> tuple[str, list[HGVSFix]]:
|
|
|
907
962
|
|
|
908
963
|
def _op_strip_leading_junk(s: str) -> tuple[str, list[HGVSFix]]:
|
|
909
964
|
# Strip junk before the transcript accession, e.g. "#NM_...", ":NM_...",
|
|
910
|
-
# "GRCh38.p2 NM_...". Only fires when a transcript prefix actually
|
|
911
|
-
# so a leading gene symbol (e.g. "BRCA1(NM_...)") is never touched.
|
|
912
|
-
|
|
965
|
+
# "• NM_...", "GRCh38.p2 NM_...". Only fires when a transcript prefix actually
|
|
966
|
+
# follows, so a leading gene symbol (e.g. "BRCA1(NM_...)") is never touched.
|
|
967
|
+
i = 0
|
|
968
|
+
while i < len(s):
|
|
969
|
+
if m := _LEADING_JUNK.match(s, i):
|
|
970
|
+
i = m.end()
|
|
971
|
+
elif s[i] not in "([" and _is_stray_mark(s[i]):
|
|
972
|
+
i += 1
|
|
973
|
+
else:
|
|
974
|
+
break
|
|
975
|
+
s2 = s[i:]
|
|
913
976
|
if s2 != s and re.match(_ANY_ACCESSION_PREFIX, s2, re.IGNORECASE):
|
|
914
977
|
return s2, [HGVSFix(
|
|
915
978
|
severity=HGVSFixSeverity.WARNING,
|
|
@@ -923,9 +986,11 @@ def _op_fix_gene_wrapper(s: str) -> tuple[str, list[HGVSFix]]:
|
|
|
923
986
|
# Normalise a gene symbol wedged between extra colons / stray parens:
|
|
924
987
|
# "tx:(GENE):c." "tx:(GENE)c." "tx:GENE:c." -> "tx(GENE):c."
|
|
925
988
|
# "tx(GENE:):c." -> "tx(GENE):c."
|
|
989
|
+
# "tx(GENE):GENE:c." -> "tx(GENE):c."
|
|
926
990
|
# "(NM_000059.4):c." -> "NM_000059.4:c."
|
|
927
991
|
# "BRCA1(NM_000059.4)c." -> "BRCA1(NM_000059.4):c."
|
|
928
992
|
s2 = _GENE_PARENS_COLON.sub(r"(\1)", s)
|
|
993
|
+
s2 = _GENE_REPEATED_AFTER_PARENS.sub(r"(\1):", s2)
|
|
929
994
|
s2 = _GENE_WRAPPER.sub(r"\1(\2):\3", s2)
|
|
930
995
|
s2 = _PARENS_WRAPPED_ACCESSION.sub(r"\1", s2)
|
|
931
996
|
s2 = _MISSING_COLON_BEFORE_KIND.sub(r"\1:\2", s2)
|
|
@@ -997,11 +1062,24 @@ def _op_strip_build_name(s: str) -> tuple[str, list[HGVSFix]]:
|
|
|
997
1062
|
|
|
998
1063
|
|
|
999
1064
|
def _op_fix_symbol_before_accession(s: str) -> tuple[str, list[HGVSFix]]:
|
|
1000
|
-
# Gene symbol written before the accession, separated by whitespace:
|
|
1065
|
+
# Gene symbol written before the accession, separated by whitespace, ':' or '.':
|
|
1001
1066
|
# "APC NM_001407446.1:c.-40G>A" -> "NM_001407446.1(APC):c.-40G>A"
|
|
1067
|
+
# "APC:NM_001407446.1:c.-40G>A" -> "NM_001407446.1(APC):c.-40G>A"
|
|
1002
1068
|
# "BRCA2 NM_000059.4 c.68del" -> "NM_000059.4(BRCA2) c.68del"
|
|
1003
1069
|
# (the remaining space is stripped and the colon restored by later steps).
|
|
1004
|
-
|
|
1070
|
+
# An accession that already has its gene symbol keeps it: a matching symbol
|
|
1071
|
+
# before it is dropped ("BRCA2 NM_000059.4(BRCA2):c.68del"), a different one
|
|
1072
|
+
# is left alone rather than guessing which is right.
|
|
1073
|
+
def _move_symbol(m: re.Match) -> str:
|
|
1074
|
+
symbol, accession = m.groups()
|
|
1075
|
+
rest = s[m.end():]
|
|
1076
|
+
if not rest.startswith("("):
|
|
1077
|
+
return f"{accession}({symbol})"
|
|
1078
|
+
if rest[1:].upper().startswith(symbol.upper() + ")"):
|
|
1079
|
+
return accession
|
|
1080
|
+
return m.group(0)
|
|
1081
|
+
|
|
1082
|
+
s2 = _SYMBOL_BEFORE_ACCESSION.sub(_move_symbol, s)
|
|
1005
1083
|
if s2 != s:
|
|
1006
1084
|
return s2, [HGVSFix(
|
|
1007
1085
|
severity=HGVSFixSeverity.WARNING,
|
|
@@ -1293,6 +1371,7 @@ _PIPELINE: list[_PipelineStep] = [
|
|
|
1293
1371
|
# Wrapping quotes first: the ops below that are anchored to the start of the
|
|
1294
1372
|
# string ('^') can't see an accession or symbol behind a leading quote.
|
|
1295
1373
|
_PipelineStep(HGVSCleanOp.STRIP_SURROUNDING_PUNCTUATION, _op_strip_surrounding_punctuation),
|
|
1374
|
+
_PipelineStep(HGVSCleanOp.REPLACE_UNICODE_DASH, _op_replace_unicode_dash),
|
|
1296
1375
|
_PipelineStep(HGVSCleanOp.STRIP_PROTEIN_SUFFIX, _op_strip_protein_suffix),
|
|
1297
1376
|
_PipelineStep(HGVSCleanOp.STRIP_CONTIG_NAME, _op_strip_contig_name),
|
|
1298
1377
|
_PipelineStep(HGVSCleanOp.STRIP_BUILD_NAME, _op_strip_build_name),
|
|
@@ -241,6 +241,35 @@ CLEAN_CASES = [
|
|
|
241
241
|
# gene symbol (was "NM_000059.4(hg19):c.68del" / "GRCh38BRCA2NM_000059.4:c.68del")
|
|
242
242
|
("hg19 NM_000059.4:c.68del", "NM_000059.4:c.68del", {C.STRIPPED_BUILD_NAME}),
|
|
243
243
|
("GRCh38 BRCA2 NM_000059.4:c.68del", "NM_000059.4(BRCA2):c.68del", {C.STRIPPED_BUILD_NAME, C.WRAPPED_GENE_SYMBOL}),
|
|
244
|
+
# #225: the accession already has the symbol, so the matching one before it is dropped
|
|
245
|
+
("BRCA2 NM_000059.4(BRCA2):c.68del", "NM_000059.4(BRCA2):c.68del", {C.WRAPPED_GENE_SYMBOL}),
|
|
246
|
+
# #225: protein annotation after a comma/semicolon goes with its separator
|
|
247
|
+
("NM_000059.4:c.68del, p.(Glu23fs)", "NM_000059.4:c.68del", {C.STRIPPED_PROTEIN_SUFFIX}),
|
|
248
|
+
("NM_001754.5(RUNX1):c.1415T>C; p.?", "NM_001754.5(RUNX1):c.1415T>C", {C.STRIPPED_PROTEIN_SUFFIX}),
|
|
249
|
+
# #225: bracket typed for the accession underscore
|
|
250
|
+
("NM)000059.4:c.68del", "NM_000059.4:c.68del", {C.ADDED_TRANSCRIPT_UNDERSCORE}),
|
|
251
|
+
# #225: trailing stray "(" opens nothing
|
|
252
|
+
("NM_000059.4:c.68del (", "NM_000059.4:c.68del", {C.STRIPPED_SURROUNDING_PUNCTUATION}),
|
|
253
|
+
# #227: gene symbol before the accession separated by ':' or '.'
|
|
254
|
+
("BRCA2:NM_000059.4:c.68del", "NM_000059.4(BRCA2):c.68del", {C.WRAPPED_GENE_SYMBOL}),
|
|
255
|
+
("BRCA2.NM_000059.4:c.68del", "NM_000059.4(BRCA2):c.68del", {C.WRAPPED_GENE_SYMBOL}),
|
|
256
|
+
("BRCA2: NM_000059.4:c.68del", "NM_000059.4(BRCA2):c.68del", {C.WRAPPED_GENE_SYMBOL}),
|
|
257
|
+
# #227: dot or colon in place of the accession prefix underscore
|
|
258
|
+
("NM.000059.4:c.68del", "NM_000059.4:c.68del", {C.ADDED_TRANSCRIPT_UNDERSCORE}),
|
|
259
|
+
("NM:000059.4:c.68del", "NM_000059.4:c.68del", {C.ADDED_TRANSCRIPT_UNDERSCORE}),
|
|
260
|
+
# #227: stray leading bullet/asterisk, trailing dot/footnote mark/backslash
|
|
261
|
+
("\u2022NM_000059.4:c.68del", "NM_000059.4:c.68del", {C.STRIPPED_LEADING_JUNK}),
|
|
262
|
+
("*NM_000059.4:c.68del", "NM_000059.4:c.68del", {C.STRIPPED_LEADING_JUNK}),
|
|
263
|
+
("NM_000059.4:c.68del.", "NM_000059.4:c.68del", {C.STRIPPED_SURROUNDING_PUNCTUATION}),
|
|
264
|
+
("NM_000059.4:c.68del\u2020", "NM_000059.4:c.68del", {C.STRIPPED_SURROUNDING_PUNCTUATION}),
|
|
265
|
+
("NM_000059.4:c.68del\\", "NM_000059.4:c.68del", {C.STRIPPED_SURROUNDING_PUNCTUATION}),
|
|
266
|
+
# #227: typographic dash in place of '-'
|
|
267
|
+
("NM_000059.4:c.67\u20102A>G", "NM_000059.4:c.67-2A>G", {C.REPLACED_UNICODE_DASH}),
|
|
268
|
+
("NM_000059.4:c.\u201340G>A", "NM_000059.4:c.-40G>A", {C.REPLACED_UNICODE_DASH}),
|
|
269
|
+
# #227: kind repeated on the second position of a range
|
|
270
|
+
("NM_000059.4:c.67+3_c.67+6del", "NM_000059.4:c.67+3_67+6del", {C.FIXED_MULTIPLE_KIND}),
|
|
271
|
+
# #227: gene symbol repeated after its parens
|
|
272
|
+
("NM_000059.4(BRCA2):BRCA2:c.68del", "NM_000059.4(BRCA2):c.68del", {C.FIXED_GENE_WRAPPER}),
|
|
244
273
|
]
|
|
245
274
|
|
|
246
275
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|