Task: Implement the seq_features.n_neg function in /app/seq_features.py
Objective:
Create a Python module seq_features that defines a function n_neg which counts the number of negatively charged amino acids (D and E) in a given protein sequence, with strict validation of input characters.
Requirements:
File location: /app/seq_features.py (the implementation may also reside in a package at /app/seq_features/, but the expected path for this task is /app/seq_features.py).
Function signature:
def n_neg(sequence: str) -> int
Behavior:
Input is a string representing an amino acid sequence.
The function is case-insensitive: treat lowercase letters as their uppercase equivalents.
Validation:
All characters in the sequence must be valid canonical amino acid codes: A, C, D, E, F, G, H, I, K, L, M, N, P, Q, R, S, T, V, W, Y.
If any character is not in the above set, raise a RuntimeError with the exact message "<X> is not a valid amino acid" where <X> is the invalid character encountered (preserving its case in the message, as tests expect the message to include the provided character).
Examples of invalids to raise errors for: 'Z', 'z', and 'B' (which should produce "Z is not a valid amino acid" or "B is not a valid amino acid" depending on the invalid character encountered).
Computation:
If the sequence is empty, return 0.
Otherwise, count and return the number of occurrences of 'D' and 'E' in the validated, uppercase sequence.
Tests behavior aligns with:
n_neg('E') == 1
n_neg('D') == 1
n_neg('') == 0
n_neg('ACKLWTTAE') == 1
n_neg('DDDDEEEE') == 8
n_neg('acklwttae') == 1
For invalid inputs:
n_neg('Z') raises RuntimeError with message containing "Z is not a valid amino acid"
n_neg('z') raises RuntimeError with message containing "Z is not a valid amino acid" (case-insensitive validation but message uses the offending character)
n_neg('KAACABAYABADDLKPPSD') raises RuntimeError with message containing "B is not a valid amino acid"
Notes:
Do not modify tests.
Provide a concise, self-contained implementation in /app/seq_features.py that adheres to the above specifications.