A profile matrix summarises a set of aligned sequences into per-position base frequencies, and the
consensus string reads off the most common base at each position. This is exactly how position
weight matrices for transcription-factor binding sites are built, and it is the representation
that motif-finding and sequence-logo tools operate on.
Statement
Given a collection of DNA strings of equal length, build the profile matrix and the consensus
string.
The first line holds n, the number of sequences; the next n lines hold them.
Print five lines:
- The consensus string — at each position, the most frequent base. If several bases tie, choose
the one that comes first alphabetically (A<C<G<T), so the answer is unique. A:followed by the count ofAat each position, space-separated.- The same for
C:. - The same for
G:. - The same for
T:.
Input — read from standard input
| Variable | Type | Description |
|---|---|---|
n
line 1
|
int |
How many sequences follow
1 <= n <= 20
|
sequences
line 2
|
list[str] |
The aligned DNA sequences, one per line, all the same length
each 1 <= length <= 200, uppercase A, C, G, T only
|
These variables are already read for you in the starter code on the right.
Output
str the consensus string, then four count rows labelled 'A: ', 'C: ', 'G: ', 'T: '
Sample Cases
7
ATCCAGCT
GGGCAACT
ATGGATCT
AAGCAACC
TTGGAACT
ATGCCATT
ATGGCACT
ATGCAACT
A: 5 1 0 0 5 5 0 0
C: 0 0 1 4 2 0 6 1
G: 1 1 6 3 0 1 0 0
T: 1 5 0 0 0 1 1 6
1
ACGT
ACGT
A: 1 0 0 0
C: 0 1 0 0
G: 0 0 1 0
T: 0 0 0 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 <= n <= 20- Every sequence has the same length, between 1 and 200
- Ties in the consensus are broken alphabetically (
A<C<G<T)
Further Reading
- Transpose the sequences so you can count each column independently.
- Iterating the bases in the order
"ACGT"and keeping the first maximum gives the alphabetical
tie-break for free.