Real sequence data is dirty. Files arrive with lowercase bases from one tool, N
placeholders where the base caller had no confidence, and IUPAC ambiguity codes (R, Y, S, W)
from consensus calling. Every pipeline needs a sanitisation step before analysis, and skipping it is
one of the most common causes of silently wrong results downstream — a GC content calculation that
quietly ignores 12% of the read is worse than one that errors out.
Statement
You are given a raw DNA sequence that may contain lowercase letters, ambiguity codes,
and N characters.
Clean it by applying these rules, in order:
- Convert every character to uppercase.
- Remove every character that is not
A,C,GorT.
Print the cleaned sequence on the first line, and the number of characters removed on the second line.
If the cleaned sequence is empty, print an empty first line.
Input — read from standard input
| Variable | Type | Description |
|---|---|---|
s
line 1
|
str |
The raw DNA sequence, possibly containing lowercase and non-ACGT characters
1 <= len(s) <= 1000, printable ASCII letters only
|
These variables are already read for you in the starter code on the right.
Output
str cleaned uppercase ACGT-only sequence on line 1, count of removed characters on line 2
Sample Cases
ACGTacgtNNRY
ACGTACGT
4
ACGT
ACGT
0
Submit also runs your code against 5 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.
Constraints
1 <= length(s) <= 1000scontains only ASCII letters (upper or lower case) — no whitespace, digits or punctuation- The output count refers to characters removed, not characters changed by case conversion
Further Reading
- Uppercase first, then filter — doing it the other way round means lowercase
agets discarded. - A set membership test (
c in "ACGT") is clearer and faster than four separate comparisons. - The removed count is simply the difference between the input length and the cleaned length.