Sequence Sanitiser

Foundational Bioinformatics DNA Sets Filtering Data Cleaning
Significance:

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:

  1. Convert every character to uppercase.
  2. Remove every character that is not A, C, G or T.

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
Sample 1
Input
ACGTacgtNNRY
Expected Output
ACGTACGT
4
Lowercase bases are kept after uppercasing; N, R and Y are dropped.
Sample 2
Input
ACGT
Expected Output
ACGT
0
Already clean — nothing removed.

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) <= 1000
  • s contains 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 a gets 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.

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: s (str)
Next Problem
Primer Melting Temperature