Project: Analyze a Real DNA Sequence

Put it all together: download the real human insulin gene from a public database and analyze it - base composition, GC content, the protein it codes for, and a chart - all in your own Python.

๐ŸŸขโ†’๐ŸŸก Beginner project โฑ๏ธ ~1.5 hr ๐Ÿ Python ยท Biopython ๐Ÿงฌ Real data

Before you start

Learning objectives

By the end of this lesson you will be able to: fetch a real gene from NCBI; calculate base composition and GC content; translate a gene into its protein; and produce a chart in Python.

This is where it gets real. You'll pull an actual gene sequence from NCBI - the same database working scientists use every day - and analyze it with the Python you just learned. The gene is human insulin (accession NM_000207): the molecule that lets your body use sugar, and the first medicine made with recombinant DNA technology (approved in 1982).

โ–ถ Code along

Use a Jupyter notebook in your bionexus environment, or open a free Colab. Run each block as you go.

Open this project in Colab โ†’

1Fetch a real gene from NCBI

Biopython's Entrez module talks to NCBI for you. (NCBI asks you to say who you are with an email address. Use your real one, so NCBI can contact you if something goes wrong; please don't make one up.) In Colab, run !pip install biopython first.

from Bio import Entrez, SeqIO

Entrez.email = "your.email@example.com"   # use your own email

# Fetch the human insulin mRNA as a FASTA record
handle = Entrez.efetch(db="nucleotide", id="NM_000207",
                       rettype="fasta", retmode="text")
record = SeqIO.read(handle, "fasta")
handle.close()

seq = str(record.seq)
print(record.description)
print("Length:", len(seq), "bases")
Network blocked? Some school or work networks block NCBI. If the fetch fails, no problem - download the FASTA by hand from ncbi.nlm.nih.gov/nuccore/NM_000207 (Send to โ†’ File โ†’ FASTA), then load it with record = SeqIO.read("NM_000207.fasta", "fasta").

2Base composition

Use the loop pattern from the basics lesson to count each base:

tally = {}
for base in seq:
    tally[base] = tally.get(base, 0) + 1

print(tally)
for base, n in tally.items():
    print(base, n, round(n/len(seq)*100, 1), "%")

3GC content - reuse your function

def gc_content(s):
    return round((s.count("G") + s.count("C")) / len(s) * 100, 1)

print("GC content:", gc_content(seq), "%")

Why GC content is interesting

A G-C pair is held by three hydrogen bonds and an A-T pair by two, and GC-rich DNA is generally more stable. GC content varies a lot between genes and between genomes. Comparing GC content across genes and organisms is a real, everyday bioinformatics task.

4From gene to protein

The whole point of insulin's gene is the protein it builds. But an mRNA record starts with a stretch that is not translated (the 5' untranslated region), so first find the start codon, ATG, then let Biopython translate from there:

from Bio.Seq import Seq

start = seq.find("ATG")              # first start codon
print("Start codon at position", start)

cds = seq[start:]
cds = cds[:len(cds) // 3 * 3]          # keep whole codons only
protein = Seq(cds).translate(to_stop=True)
print("Protein length:", len(protein), "amino acids")
print("First 20:", protein[:20])

You should see 110 amino acids starting MALWMRLLPLL.... That is preproinsulin, the protein the ribosome actually makes; the cell then trims it into the 51-amino-acid insulin hormone. You just decoded a gene.

Why not translate the whole record?

If you translate from base 1, Biopython reads the untranslated region in the wrong frame and gives you nonsense. For insulin the first ATG is the real start, but that is not true for every gene. The reliable way is to use the coding region (CDS) that NCBI annotates in the GenBank record.

5Visualize it

import matplotlib.pyplot as plt

bases = ["A", "C", "G", "T"]
heights = [tally.get(b, 0) for b in bases]

plt.bar(bases, heights, color=["#5b9cf8","#a855f7","#10b981","#f59e0b"])
plt.title("Base composition of human insulin (NM_000207)")
plt.ylabel("Count")
plt.show()

That bar chart is a small but complete piece of analysis - and it's yours. You fetched real data, processed it, and visualized a result.

๐Ÿš€ Make it your own

The best way to cement a skill is to push past the tutorial. Try one (or all) of these:

  • Fetch a different gene - try NM_000518 (beta-globin, the blood gene behind sickle-cell). Compare its GC content to insulin.
  • Write a function that returns the reverse complement of a sequence (hint: Biopython's Seq(seq).reverse_complement()).
  • Count the most common codon in the sequence using a loop over seq[i:i+3].
  • Portfolio move: save your notebook to GitHub with a short README. That's your first public bioinformatics project.

What you just did

Step back and notice the shape of what happened: you connected to a real scientific database, retrieved real data, applied your own code to it, and produced a result and a figure. That loop - get data โ†’ analyze โ†’ visualize - is the core of nearly every bioinformatics project, no matter how advanced. You now own the whole pattern.

I got a "Partial codon" warning when translating. Is that bad?

Not for this project. It means the piece you translated was not a whole number of codons, because the end of the mRNA (the 3' untranslated region) is included. The line cds[:len(cds) // 3 * 3] trims the leftover bases so the warning goes away, and to_stop=True stops at the first stop codon anyway.

Check your understanding

In the project, where do you fetch the real gene sequence from?
The project downloads the insulin mRNA record NM_000207 from NCBI's nucleotide database with Biopython's Entrez module.
Turning a gene's DNA into a protein sequence is called:
Transcription copies DNA into RNA; translation reads the RNA three bases (one codon) at a time to build the protein.
Which Biopython module does the project use to talk to NCBI and fetch the gene?
Biopython's Entrez module connects to NCBI to retrieve records; you set Entrez.email and call efetch to download the FASTA.
In the project, what does GC content measure?
GC content is the share of G and C bases in a sequence; GC-rich DNA is generally more stable because a G-C pair has three hydrogen bonds.
The general pattern the project teaches is best summarised as:
Fetching real data, processing it, and producing a figure is the get data, analyze, visualize loop at the core of nearly every bioinformatics project.

Sources & further reading

  1. Cock PJA, Antao T, Chang JT, et al. Biopython: freely available Python tools for computational molecular biology and bioinformatics. Bioinformatics 25: 1422-1423, 2009. doi:10.1093/bioinformatics/btp163
  2. Biopython Tutorial and Cookbook, chapter "Accessing NCBI's Entrez databases". biopython.org
  3. NCBI Nucleotide record NM_000207 (Homo sapiens insulin, INS, mRNA). ncbi.nlm.nih.gov
  4. Perkel JM. Programming: Pick up Python. Nature 518: 125-126, 2015. doi:10.1038/518125a

Last reviewed: October 2026.

Next foundation

Start the R series: installing R & RStudio โ†’