Final answer:
To write a function that returns the reverse complement of a DNA sequence, you can reverse the sequence and then replace each base with its complement using a dictionary.
Step-by-step explanation:
To write a function that returns the reverse complement of a DNA sequence, you can follow these steps:
- Reverse the sequence by using the reverse() function.
- Create a dictionary to store the complement base pairs. For example, {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}.
- Use a list comprehension to iterate over each base in the reversed sequence and replace it with its complement using the dictionary. Join the resulting list to get the reverse complement sequence.
Example code:
def goback(dna_seq):
reverse_seq = dna_seq[::-1]
complement_dict = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
reverse_complement_seq = ''.join([complement_dict[base] for base in reverse_seq])
return reverse_complement_seq
rand_dna = 'TTAAGC'
rand_goback = goback(rand_dna)
print(rand_goback)
Output:
GCTTAA