Skip to Content
Mastering Python for Bioinformatics
book

Mastering Python for Bioinformatics

by Ken Youens-Clark
May 2021
Intermediate to advanced
456 pages
10h 44m
English
O'Reilly Media, Inc.
Content preview from Mastering Python for Bioinformatics

Chapter 3. Reverse Complement of DNA: String Manipulation

The Rosalind REVC challenge explains that the bases of DNA form pairs of A-T and G-C. Additionally, DNA has directionality and is usually read from the 5'-end (five-prime end) toward the 3'-end (three-prime end). As shown in Figure 3-1, the complement of the DNA string AAAACCCGGT is TTTTGGGCCA. I then reverse this string (reading from the 3'-end) to get ACCGGGTTTT as the reverse complement.

mpfb 0301
Figure 3-1. The reverse complement of DNA is the complement read from the opposite direction

Although you can find many existing tools to generate the reverse complement of DNA—and I’ll drop a spoiler alert that the final solution will use a function from the Biopython library—the point of writing our own algorithm is to explore Python. In this chapter, you will learn:

  • How to implement a decision tree using a dictionary as a lookup table

  • How to dynamically generate a list or a string

  • How to use the reversed() function, which is an example of an iterator

  • How Python treats strings and lists similarly

  • How to use a list comprehension to generate a list

  • How to use str.maketrans() and str.translate() to transform a string

  • How to use Biopython’s Bio.Seq module

  • That the real treasure is the friends you make along the way

Getting Started

The code and tests for this program are in the 03_revc directory. To get a feel for how ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Bioinformatics Programming Using Python

Bioinformatics Programming Using Python

Mitchell L Model

Publisher Resources

ISBN: 9781098100872Errata Page