Biopython Sequences

Posted September 28, 2023 by Rohith and Anusha ‐ 2 min read

In the ever-evolving field of bioinformatics, researchers and scientists are constantly seeking ways to analyze and manipulate biological data efficiently. Biopython, a powerful open-source library, has emerged as an invaluable tool for bioinformaticians. Among its many features, Biopython provides extensive functionality for working with biological sequences, making it an indispensable resource for tasks ranging from sequence retrieval to advanced analyses. In this blog post, we will delve into the world of Biopython sequences and explore some of the essential tools and techniques it offers.

Getting Started with Biopython Sequences

  • Before we dive into specific examples, it’s crucial to understand the basics of working with biological sequences in Biopython.

  • Biopython supports a wide range of sequence formats, including FASTA, GenBank, and Swiss-Prot, making it flexible for various data sources.

To get started, you’ll need to install Biopython using pip:

pip install biopython
  • Once installed, you can start working with sequences in your Python environment.

Sequence Retrieval

  • Biopython provides functions to retrieve sequences from local files or online databases.

For example, you can fetch a sequence from the NCBI GenBank database:

from Bio import Entrez = ""
accession_number = "NM_001301717"  # Replace with your accession number

handle = Entrez.efetch(db="nucleotide", id=accession_number, rettype="gb", retmode="text")
sequence_record =, "genbank")


Sequence Manipulation

  • Biopython offers numerous methods to manipulate sequences.

You can perform operations such as reverse complement, translation, transcription, and more:

from Bio.Seq import Seq

my_dna_sequence = Seq("ATGCGTA")

# Reverse complement
reverse_complement = my_dna_sequence.reverse_complement()

# Transcription
messenger_rna = my_dna_sequence.transcribe()

# Translation
protein_sequence = my_dna_sequence.translate()


Sequence Alignment

Biopython provides tools for sequence alignment, including pairwise and multiple sequence alignment using algorithms like BLAST and ClustalW:

from Bio import AlignIO
from Bio.Blast import NCBIWWW
from Bio.Seq import Seq

# Perform a BLAST search
result_handle = NCBIWWW.qblast("blastn", "nt", Seq("AGTCAAGT"))

# Parse and print the BLAST results
blast_records = NCBIXML.parse(result_handle)
for record in blast_records:
    for alignment in record.alignments:

# Perform multiple sequence alignment
from Bio.Align.Applications import ClustalOmegaCommandline

input_file = "my_sequences.fasta"
output_file = "aligned_sequences.fasta"

clustalomega_cline = ClustalOmegaCommandline(infile=input_file, outfile=output_file, verbose=True, auto=True)

aligned_sequences =, "fasta")


  • Biopython is a versatile and indispensable library for anyone working in the field of bioinformatics.

  • In this blog post, we’ve barely scratched the surface of its capabilities when it comes to working with biological sequences.

  • Whether you’re retrieving sequences, manipulating them, or performing complex sequence analyses, Biopython provides a comprehensive toolkit to streamline your research and analysis efforts.

  • To unlock its full potential, consider exploring the extensive documentation and community resources available to bioinformaticians.

  • With Biopython, you’re well-equipped to embark on exciting journeys in genomics, proteomics, and beyond.

quick-references blog biopython-sequences biopython

Subscribe For More Content