acelerap.com

Creating Stunning Bioinformatics Visualizations Using Biopython

Written on

Chapter 1: Introduction to the Art of Science

There's a widespread belief that science is merely clinical, lacking in humor and creativity; however, this perception is misguided! With the right visualizations, raw DNA can be transformed into captivating figures that convey complex information with ease.

Biopython is an essential open-source library for bioinformatics, or computational molecular biology, in Python. It offers tailored classes, parsing capabilities for standard biological file types, and the ability to interface with various bioinformatics tools like BLAST, EMBOSS, and ClustalW. For this discussion, we will focus on how it can create stunning visual representations of biological data.

We will begin by exploring Biopython's techniques for manipulating DNA, RNA, and protein sequences. From there, we'll advance to more intricate analyses involving entire genomes and how these genomes evolve over time, depicted through phylogenetic tree visualizations. This journey will empower you to examine any genome of interest and derive insights from raw data.

Section 1.1: Working with Sequences

Biopython features a base class called Seq (Sequence), which is akin to the standard Python string class but enriched with methods tailored for biological applications. For instance, we can import a DNA sequence as follows:

>>> my_sequence = Seq('AGTCC')

We can utilize standard string functions on this object, such as iterating through each character or using len() to determine its length:

# Print length

>>> print(len(my_sequence))

5

# Print each basepair in the sequence

>>> for basepair in my_sequence:
>>>     print(basepair)

A

G

T

C

C

Furthermore, we can access specific base pairs by their index and slice the sequence. This slicing operation produces a new Seq() object, which can be stored in a different variable or can replace the original sequence:

# Select basepair by index

>>> my_sequence[2]

'T'

# Slice sequence (returns a new Seq() object)

>>> my_sequence[1:4]

Seq('GTC')

Subsection 1.1.1: Generating Complement and Reverse Complement

Biopython also provides methods to generate the complement and reverse complement of a DNA sequence. This functionality is crucial, as DNA replication involves separating strands to create complementary sequences. Adenine (A) pairs with thymine (T), while guanine (G) pairs with cytosine (C). For instance, a sequence of 'ACTG' would pair with 'TGAC'. In RNA, uracil (U) substitutes for thymine (T), transforming a DNA sequence like 'ACTG' during transcription into an RNA sequence of 'UGAC':

>>> my_sequence = Seq('AGTCC')

# Generate complement sequence

>>> my_sequence.complement()

Seq('TCAGG')

To obtain the reverse complement, we generally analyze DNA from the coding strand running 5' → 3':

# Generate reverse complement sequence

>>> my_sequence.reverse_complement()

Seq('GGACT')

Section 1.2: Calculating GC Content

Biopython can also determine the ratio of GC bases to AT (or U) bases in a DNA or RNA sequence, which is crucial for biological analysis. The GC-content varies across species, making it useful for identifying unknown genomes by comparing them to known GC-content profiles. Typically, coding regions (genes) exhibit a higher GC-content compared to non-coding regions.

# Calculate GC proportion

>>> from Bio.SeqUtils import GC
>>> GC(my_sequence)

60.0

Chapter 2: Advanced Visualization Techniques

To illustrate genomes effectively, Biopython includes a module called GenomeDiagram, which is designed to create linear or circular genome diagrams, particularly useful for prokaryotes. Example genomes can be accessed from GitHub or downloaded from GenBank, the NIH genetic sequence database, in various formats like .gbk or .fasta.

# Import Libraries

from reportlab.lib import colors

from reportlab.lib.units import cm

from Bio.Graphics import GenomeDiagram

from Bio import SeqIO

from Bio.SeqFeature import SeqFeature, FeatureLocation

# Read in our genome

record = SeqIO.read("NC_005816.gb", "genbank")

gd_diagram = GenomeDiagram.Diagram(record.id)

gd_track_for_features = gd_diagram.new_track(1, name="Annotated Features")

gd_feature_set = gd_track_for_features.new_set()

As we create the diagram, we can color-code genes for clarity and annotate restriction sites for popular enzymes:

for feature in record.features:

if feature.type != "gene":

continue

color = colors.blue if len(gd_feature_set) % 2 == 0 else colors.lightblue

gd_feature_set.add_feature(

feature, sigil="ARROW", color=color, label=True, label_size=14, label_angle=0

)

Visualizations can be striking, as seen in the genome for Yersinia pestis biovar Microtus, an avirulent strain developed as a vaccine.

The art of science and the science of art | Ikumi Kayama | TEDxFoggyBottom - YouTube

This presentation explores the intersection of art and science, emphasizing how creativity can enhance scientific endeavors.

Science and Art are not as different as we think | Kristin Levier | TEDxUIdaho - YouTube

Levier discusses the similarities between science and art, highlighting the importance of creativity in scientific research.

Phylogeny and the Evolution of Genomes

As we progress from basic DNA sequences to entire genomes, it's evident that genomes are not static; they undergo frequent mutations, especially in viruses. This variability poses challenges in vaccine development. By comparing new sequences to a reference sequence, we can track the emergence of variants over time. For instance, the initial strain of SARS-CoV-2 from Wuhan serves as a baseline for tracking mutations.

Nextstrain offers tools that allow public health officials and researchers to visualize and analyze new strains of Covid-19, producing dynamic visuals based on various features like mutation count and country of origin.

Conclusion: Embracing Biopython for Bioinformatics

Biopython serves as a pivotal tool for bioinformatics applications in Python. This guide has provided an overview of its capabilities, from analyzing sequences to visualizing entire genomes. The extensive documentation available alongside resources from NCBI enables users to explore and manipulate genomic data effectively. I encourage you to experiment with genomes that interest you and create compelling visualizations!

Connect with Me

I am always eager to connect with fellow enthusiasts and explore collaborative projects! Feel free to follow me on GitHub or LinkedIn, and check out my other articles on Medium. You can also find me on Twitter!

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Maximize Your Study Potential with Active Recall and Notion

Discover how to enhance your study sessions using active recall with Notion, a technique that can significantly boost your exam performance.

Understanding the Complex Landscape of Alzheimer's Disease

Explore the intricate cellular changes in Alzheimer's, recent research findings, and the hope for future treatments.

Unlocking Potential: The Unseen Effects of Limited Choices in Family Offices

Explore the hidden impacts of restricted choices in family offices and discover strategies to empower individuals for lasting success.

Unveiling Hidden Gems: 10 Exceptional Showcases on Medium

Discover 10 remarkable showcases that highlight exceptional stories on Medium, fostering community and creativity among writers.

Understanding Emotional Eating: Confronting the Obesity Epidemic

Explore emotional eating's role in the obesity crisis and discover strategies for healthier relationships with food.

Essential Items for a Smooth Daily Commute to Work

Discover the essential items that enhance your daily commute experience, making travel more enjoyable and efficient.

Navigating Fear to Propel Your Startup's Growth

Explore how managing fear and risk is crucial for startup success and growth.

Finding Love Within: Transforming Your Heart from Loneliness

Explore how to fill the emptiness in your heart with love and connection, transforming loneliness into warmth and fulfillment.