Module 6

Functions with biological data

Applying functions to sequences.

A GC content function

Let's write a function that computes GC content. This is a real bioinformatics task.

Python
def gc_content(seq):
    g = seq.count("G")
    c = seq.count("C")
    return (g + c) / len(seq) * 100

print(gc_content("ATGCGCAT"))
50.0
Your task

GC content function

  • Define gc_content(seq) and test it with ATGCGCAT.
Biology connection

You just wrote your first bioinformatics function. This is the kind of tool you will build throughout the course.