Skip to content

Commit

Permalink
begin building uncertain variants. Refer to #556
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-J-Freeman committed Dec 11, 2023
1 parent dd8b14e commit d76f357
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 107 deletions.
64 changes: 64 additions & 0 deletions VariantValidator/modules/complex_descriptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import re
import vvhgvs.exceptions

# Errors
class FuzzyPositionError(Exception):
pass
Expand All @@ -7,6 +10,13 @@ class FuzzyRangeError(Exception):
pass


class InvalidRangeError(Exception):
pass


class IncompatibleTypeError(Exception):
pass

def fuzzy_ends(my_variant):
"""
:param my_variant:
Expand All @@ -27,6 +37,60 @@ def fuzzy_ends(my_variant):

return False


def uncertain_positions(my_variant, validator):

print("AWOOO")
print(dir(my_variant))
print(my_variant.quibble)

print("Try it")

# Formats like NC_000005.9:g.(90136803_90144453)_(90159675_90261231)dup
if ")_(" in my_variant.quibble:
accession_and_type, positions_and_edit = my_variant.quibble.split(".(")
position_1, position_2 = positions_and_edit.split(")_(")
position_2, variation = position_2.split(")")
position_1 = position_1.replace(")", "")
position_2 = position_2.replace("(", "")
print(accession_and_type)
print(position_1)
print(position_2)
print(variation)
v1 = f"{accession_and_type}.{position_1}{variation}"
v2 = f"{accession_and_type}.{position_2}{variation}"
my_variant.reftype = f":{accession_and_type.split(':')[1]}."
print(my_variant.reftype)
try:
parsed_v1 = validator.hp.parse(v1)
validator.vr.validate(parsed_v1)
except vvhgvs.exceptions.HGVSError as e:
if "is not known to be compatible with variant type" in str(e):
raise IncompatibleTypeError(str(e))
import traceback
traceback.print_exc()
raise InvalidRangeError(f"{position_1} is an invlaid range for "
f"accession {accession_and_type.split(':')[0]}")
try:
parsed_v2 = validator.hp.parse(v2)
validator.vr.validate(parsed_v2)
except vvhgvs.exceptions.HGVSError as e:
if "is not known to be compatible with variant type" in str(e):
raise IncompatibleTypeError(str(e))
import traceback
raise InvalidRangeError(f"{position_1} is an invlaid range for "
f"accession {accession_and_type.split(':')[0]}")

my_variant.warnings = ["Uncertain positions are not fully supported, however the syntax is valid"]
if "NC_" in my_variant.quibble:
my_variant.hgvs_genomic = my_variant.quibble
if "NM_" in my_variant.quibble or "NR_" in my_variant.quibble or "ENST" in my_variant.quibble:
my_variant.hgvs_coding = my_variant.quibble
my_variant.hgvs_transcript_variant = my_variant.quibble


return

# <LICENSE>
# Copyright (C) 2016-2023 VariantValidator Contributors
#
Expand Down
30 changes: 22 additions & 8 deletions VariantValidator/modules/format_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import vvhgvs.exceptions
import copy
import logging
from .variant import Variant
from . import seq_data
from . import utils as fn
from VariantValidator.modules.variant import Variant
from VariantValidator.modules import seq_data
from VariantValidator.modules import utils as fn
import VariantValidator.modules.rna_formatter
from VariantValidator.modules import complex_descriptions, use_checking

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,7 +38,7 @@ def initial_format_conversions(variant, validator, select_transcripts_dict_plus_
return True

# Uncertain positions
toskip = uncertain_pos(variant)
toskip = uncertain_pos(variant, validator)
if toskip:
return True

Expand Down Expand Up @@ -1090,7 +1091,7 @@ def rna(variant, validator):
return False


def uncertain_pos(variant):
def uncertain_pos(variant, validator):
"""
check for uncertain positions in the variant and return unsupported warning
"""
Expand All @@ -1104,9 +1105,22 @@ def uncertain_pos(variant):
return False
elif ":r.(" in to_check:
return False
error = 'Uncertain positions are not currently supported'
variant.warnings.append(error)
logger.warning(str(error))
else:
try:
complex_descriptions.uncertain_positions(variant, validator)
except complex_descriptions.IncompatibleTypeError:
print("YYAYAYAY")

use_checking.refseq_common_mistakes(variant)



import traceback
traceback.print_exc()

# error = 'Uncertain positions are not currently supported'
# variant.warnings.append(error)
# logger.warning(str(error))
return True
else:
return False
Expand Down
5 changes: 5 additions & 0 deletions VariantValidator/modules/use_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def refseq_common_mistakes(variant):
"""
Evolving list of common mistakes, see sections below
"""

print("IN IT")
print(variant.quibble)

# NM_ .g
if (variant.quibble.startswith('NM_') or variant.quibble.startswith('NR_')) and variant.reftype == ':g.':
suggestion = variant.quibble.replace(':g.', ':c.')
Expand All @@ -36,6 +40,7 @@ def refseq_common_mistakes(variant):
'Did you mean ' + suggestion + '?'
variant.warnings.append(error)
logger.warning(error)
print("YahBoo")
return True

# NM_ NC_ NG_ NR_ p.
Expand Down
Loading

0 comments on commit d76f357

Please sign in to comment.