Lesson 2 of 15
Complement & Reverse Complement
Two Strands, One Molecule
DNA is double-stranded. The two strands are complementary — each base pairs with its partner:
- A pairs with T
- T pairs with A
- G pairs with C
- C pairs with G
The complement of ATCG is TAGC.
But DNA strands run in opposite directions (antiparallel). To get the sequence of the other strand in the conventional 5'→3' direction, you take the complement and reverse it — the reverse complement:
def complement(seq):
table = {"A": "T", "T": "A", "G": "C", "C": "G"}
return "".join(table[b] for b in seq)
def reverse_complement(seq):
return complement(seq)[::-1]
print(complement("ATCG")) # TAGC
print(reverse_complement("ATCG")) # CGAT
When AlphaGenome receives a DNA input, it analyzes both strands — the sequence and its reverse complement. Regulatory elements can sit on either strand.
Your Task
Implement complement(seq) and reverse_complement(seq).
Python runtime loading...
Loading...
Click "Run" to execute your code.