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

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 protein ever made as a medicine.

โ–ถ Code along

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

Open a blank Colab โ†’

1Fetch a real gene from NCBI

Biopython's Entrez module talks to NCBI for you. (NCBI just asks that you tell them who you are via an email - any address is fine.)

from Bio import Entrez, SeqIO

Entrez.email = "your.email@example.com"   # put any email here

# 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

GC pairs bond more tightly than AT pairs, so GC-rich regions are more stable and often mark important, actively-used genes. 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. Biopython can translate the coding sequence into amino acids for you:

from Bio.Seq import Seq

protein = Seq(seq).translate(to_stop=True)
print("Protein length:", len(protein), "amino acids")
print("First 20:", protein[:20])

The first amino acids you see (starting M..., the standard "start" residue) are the beginning of the real insulin protein. You just decoded a gene.

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.

The translation gave a warning about length not being a multiple of three. Is that bad?

Not necessarily - the FASTA includes untranslated regions around the coding sequence, so the full mRNA isn't a clean multiple of three. For a precise translation you'd extract just the coding region (CDS); for this project, to_stop=True gives you the protein up to the first stop, which is what we want.

Check your understanding

In the project, where do you fetch the real gene sequence from?
Turning a gene's DNA into a protein sequence is called:
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 pairs bond more tightly, so GC-rich regions tend to be more stable.
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.
Next foundation

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