Skip to content

Commit

Permalink
Attempt to add support for CTD abbreviations
Browse files Browse the repository at this point in the history
  • Loading branch information
kimrutherford committed Mar 5, 2024
1 parent 71b9d09 commit d1f26d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ctd_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
ctd_mutation_regex = f'{aa}\d+{aa}(?:{ctd_repetition_regex})?'
ctd_deletion_regex = f'(?:delta|\u0394|∆)(?:{ctd_repetition_regex})?'

ctd_abbreviations = f'(?:CTD_S2|CTD_T4|CTD_S5|CTD_S7)'

# This dictionary has keys that are the systematic IDs of the genes that have CTDs,
# the value is a dictionary with:
# - positions: a dictionary with keys that are the residues of the canonical repeat
Expand Down Expand Up @@ -136,4 +138,4 @@ def ctd_format_for_transvar(capture_groups: list[str], gene: dict) -> list[str]:

def ctd_apply_syntax(ctd_substring: str):
ctd_bits = re.findall(f'({ctd_mutation_regex}|{ctd_deletion_regex})', ctd_substring)
return 'CTD-' + ','.join(ctd_bits)
return 'CTD-' + ','.join(ctd_bits)
4 changes: 2 additions & 2 deletions grammar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
from ctd_support import ctd_apply_syntax, ctd_further_check, ctd_format_for_transvar
from ctd_support import ctd_mutation_regex, ctd_deletion_regex
from ctd_support import ctd_mutation_regex, ctd_deletion_regex, ctd_abbreviations
from grammar_funs_and_vars import aa, nt, num, multi_nt_regex, multi_nt_apply_syntax, multi_nt_check_sequence, \
multi_aa_regex, multi_aa_apply_syntax, multi_aa_check_sequence, \
multi_aa_format_for_transvar, insertion_aa_format_for_transvar, multi_nt_format_for_transvar, \
Expand Down Expand Up @@ -145,7 +145,7 @@
{
'type': 'amino_acid_deletion_and_mutation',
'rule_name': 'CTD',
'regex': f'(CTD-(?:(?:{ctd_mutation_regex}|{ctd_deletion_regex}),?\s?)+)$',
'regex': f'(CTD-(?:(?:{ctd_mutation_regex}|{ctd_deletion_regex}),?\s?)+|{ctd_abbreviations})$',
'apply_syntax': lambda g: ctd_apply_syntax(g[0]),
'further_check': ctd_further_check,
'format_for_transvar': ctd_format_for_transvar
Expand Down
4 changes: 4 additions & 0 deletions test_syntax_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def test_class_methods_CTD(self):
groups = syntax_rule.get_groups('CTD-delta(r1-r12-2),Y1F(r1-r12),Y2F', genome['SPBC28F2.12'])
self.assertEqual(groups, ('CTD-delta(r1-r12-2),Y1F(r1-r12),Y2F', ))

syntax_rule = find_rule(syntax_rules, 'amino_acid_deletion_and_mutation', 'CTD')
groups = syntax_rule.get_groups('CTD_S2', genome['SPBC28F2.12'])
self.assertEqual(groups, ('CTD_S2', ))

def test_class_methods_nucleotides(self):

syntax_rules = [SyntaxRule.parse_obj(r) for r in nucleotide_grammar]
Expand Down

0 comments on commit d1f26d8

Please sign in to comment.