Every downstream tool in genomics — from base-calling QC to variant callers — starts with the
same primitive: knowing the base composition of a sequence. Nucleotide counting is also the first
check a bioinformatician runs against a FASTA file to sanity-test it, which is why it's the
"Hello World" of computational biology. It forces you to treat a string as a biological object
rather than just characters.
Statement
Given a single-stranded DNA sequence composed only of the characters A, C, G and T, count
how many times each nucleotide occurs.
Print four integers separated by single spaces, in the fixed order A C G T, on one line.
Input — read from standard input
| Variable | Type | Description |
|---|---|---|
s
line 1
|
str |
The DNA sequence to count bases in
1 <= len(s) <= 1000, uppercase A, C, G, T only
|
These variables are already read for you in the starter code on the right.
Output
str four space-separated counts in the order A C G T, on one line
Sample Cases
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
20 12 17 21
ACGT
1 1 1 1
Submit also runs your code against 4 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 uppercaseA,C,G,T— noN, no lowercase, no internal whitespace
Further Reading
- Python's
str.count()gives each total in a single pass. - In R,
lengths(regmatches(s, gregexpr("A", s)))counts occurrences of a character.
My Notes
Private to you. Saved to your account, separate from your code.
- Ctrl + Enter run · Ctrl + Shift + Enter submit