The reverse-complement of a DNA sequence is the sequence of nucleotides (base pairs) obtained by reversing the original sequence and replacing each nucleotide with its complementary counterpart. In DNA, the bases pair as:
- Adenine (A) pairs with Thymine (T)
- Cytosine (C) pairs with Guanine (G)
- Guanine (G) pairs with Cytosine (C)
- Thymine (T) pairs with Adenine (A)
For example, if the input DNA sequence is 5'-ATGC-3', its reverse-complement would be 5'-GCAT-3'.
- Input: A DNA sequence string (e.g., "ATGC").
- Reverse: Reverse the sequence (e.g., "ATGC" becomes "CGTA").
- Complement: Replace each nucleotide with its complementary base:
- A → T
- T → A
- C → G
- G → C
- Output: The reverse-complement of the input DNA sequence.
- Input: A DNA sequence
Sof lengthn. - Reverse the sequence: Reverse the string
Sto getS_reversed. - Complement the sequence: Replace every character in
S_reversedas follows:- Replace
AwithT - Replace
TwithA - Replace
CwithG - Replace
GwithC
- Replace
- Output: Return the modified string, which is the reverse-complement.
Function ReverseComplement(DNA_sequence):
reversed_sequence = reverse(DNA_sequence) # Step 1: Reverse the sequence
complement_sequence = "" # Initialize empty string for complement
for base in reversed_sequence: # Step 2: Iterate through the reversed sequence
if base == 'A':
complement_sequence += 'T'
else if base == 'T':
complement_sequence += 'A'
else if base == 'C':
complement_sequence += 'G'
else if base == 'G':
complement_sequence += 'C'
return complement_sequence # Step 3: Return the reverse-complement
The process involves two main steps:
- Reversing the input DNA sequence.
- Replacing each nucleotide with its complementary nucleotide.
ATGC
- Reverse:
CGTA - Complement:
C→GG→CT→AA→T
GCAT
- Reversing the string: O(n), where
nis the length of the input string. - Complementing the string: O(n), because we need to iterate through each character and replace it with the complementary base.
Thus, the total time complexity is O(n).
- The space complexity is O(n) because we are creating a new string of length
nfor the reversed and complemented sequence.
- Biology Textbooks/Resources: For understanding the biological context of DNA and base pairing.
- Wikipedia: Information on DNA sequencing and complementary base pairing.
- Programming Algorithms: General string manipulation and sequence processing algorithms.