Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "SyntaxWarning: invalid escape sequence '\d'" #116

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions protein_modification_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def check_func(row, genome, allowed_mod_dict):
dummy_rule = SyntaxRule(
type='dummy',
rule_name='dummy',
regex=f'(?<!{aa})({aa})(\d+){aa}?',
regex=fr'(?<!{aa})({aa})(\d+){aa}?',
apply_syntax=lambda x: f'{x[0]}{x[1]}',
)
# Special abbreviations for CTD modifications
Expand All @@ -74,7 +74,7 @@ def check_func(row, genome, allowed_mod_dict):
# Extract the matched and unmatched elements
match_groups: list[tuple[re.Match, SyntaxRule]] = list(filter(lambda x: type(x) != str, result))
# The regex excludes non-digit non-letter characters
unmatched = list(filter(lambda x: type(x) == str and not re.match('^[^a-zA-Z\d]+$', x), result))
unmatched = list(filter(lambda x: type(x) == str and not re.match(r'^[^a-zA-Z\d]+$', x), result))

if len(unmatched):
return 'pattern_error', ''
Expand Down Expand Up @@ -110,7 +110,7 @@ def check_func(row, genome, allowed_mod_dict):
# Get all letters in the sequence_position
# We use ([A-Za-z])(?=\d) instead of [A-Za-z] so that CTD abbreviations such as CTD_S2
# are also supported
residues = set(x for x in re.findall('([A-Za-z])(?=\d)', row['sequence_position']))
residues = set(x for x in re.findall(r'([A-Za-z])(?=\d)', row['sequence_position']))
if any(residue not in allowed_mod_dict[row['modification']] for residue in residues):
return 'residue_not_allowed', change_sequence_position_to

Expand Down
Loading