Finding the reverse complement for DNA is a pretty common task in bioinformatics. Below is a simple Python implementation of how the task can be accomplished.
This blog post posts a simple function to solve the problem – Enjoy it!
1 – What is a DNA sequence Reverse Complement?
The reverse complement of a DNA sequence refers to the reverse of the DNA sequence in which the original sequence’s base pairs have been inverted and the order of the bases has been reversed. In other words, if the original sequence is read from 5′ to 3′ (left to right), the reverse complement sequence is read from 3′ to 5′ (right to left).
In DNA, the four bases are adenine (A), cytosine (C), guanine (G), and thymine (T). The complement of each base is as follows:
- A -> T
- C -> G
- G -> C
- T -> A
Thus, the reverse complement of a DNA sequence is obtained by first reversing the order of the bases and then replacing each base with its complement. This can be useful in various molecular biology applications, such as in finding potential binding sites for specific proteins or in identifying the origin of replication in a DNA molecule.
2- Python Code: Reverse Complement DNA
Please find below the Python code find the reverse complement DNA:
# !/usr/bin/env python3 # -*- coding: utf-8 -*- RC_TRANS = str.maketrans('ACGTNacgtn', 'TGCANTGCAN') def reverse_complement(sequence): """This function finds the reverse complement for a given DNA sequence. Description: The reverse complement for a given DNA string can be identified by reversing the original string and translating each of the DNA bases with its complement. Args: sequence (str): DNA sequence. Returns: str: Reverse complement. """ return sequence[::-1].translate(RC_TRANS) rc = reverse_complement("ATCGTAGTGAC")
Here are three of my favorite Python Bioinformatics Books in case you want to learn more about it.
- Python for the Life Sciences: A Gentle Introduction to Python for Life Scientists Paperback by Alexander Lancaster
- Bioinformatics with Python Cookbook by Tiago Antao
- Bioinformatics Programming Using Python: Practical Programming for Biological Data by Mitchell L. Model