Reverse Complement one line script

by:

Bioinformatics

Finding the reverse complement for DNA is a pretty common task in bioinformatics. Below is a simple Python implementation on how the task can be accomplished.

This blog post posts a simple function to solve the problem – Enjoy it!

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")

More Resources

Here are three of my favorite Python Bioinformatics Books in case you want to learn more about it.

Related Posts