

She did so well analysing a sequence! Now her supervisor just handed her 10,000 DNA sequences β she needs ORFs, GC content and a report by Friday.
One sequence takes ~10 minutes manually. 10,000 sequences = 69 days of non-stop work.
A 30-line program processes all 10,000 sequences in under a minute. Claudia spends Friday interpreting the results β not counting bases.
You will be able to write that program β and adapt it to your own research questions.
Python is the 2nd best language for everything β and #1 for science.
Slower than C, but vastly easier to learn. A bigger ecosystem and more applications than R.
| Language | Best for | Learning curve |
|---|---|---|
| πPython | ML, AI, Data Science β and almost everything else | β β β β β Easy |
| R | Statistics, niche data analysis | β β β β β Moderate |
| JavaScript | Web development | β β β β β Moderate |
| Java | Enterprise apps, Android | β β β β β Challenging |
| C / C++ | Systems, games, raw performance | β β β β β Difficult |
ML, AI, Data Science β and almost everything else
Statistics, niche data analysis
Web development
Enterprise apps, Android
Systems, games, raw performance
ML, AI, Data Science. Deep learning, NLP, computer vision, bioinformatics β Python is the lingua franca.
Web, systems, biology, automation. From Instagram's backend to NASA mission scripts β Python turns up everywhere.
Guido van Rossum starts Python as a hobby project during the Christmas break at CWI in Amsterdam.
Python establishes itself as a simple, readable scripting language for automation and system administration.
NumPy (2006) and SciPy lay the groundwork for scientific computing. Pandas (2008) follows β academic researchers start to adopt Python.
The data-science explosion. Jupyter notebooks and scikit-learn make Python the default in research labs.
TensorFlow (2015) and PyTorch (2016) cement Python as the lingua franca of deep learning.
COVID-19 accelerates data-science adoption. Python usage nearly doubles β 8M+ active developers worldwide.

Guido van Rossum
BDFL β Benevolent Dictator for Life
βI was looking for a hobby programming project that would keep me occupied during the week around Christmas.β
π©Named after Monty Python's Flying Circus β not the snake!
Practice writing code YOURSELF and work on YOUR OWN PROJECTS!
You don't get fit by watching fitness videos
You don't learn guitar by watching YouTube
You don't learn coding by following a lecture
An overview of what Python does for biology β still worth knowing.
You start coding for real β solving your own problems, building your own tools.
Generative AI tools must only be used in an assistive role in this module.
See Canvas for full details of permitted use of AI for assessments.
Core concepts, introduced with live coding and biological examples
You write the code; demonstrators circulate to help
Learn about the assessed projects and get started with hands-on support
An in-class Python fundamentals test and two projects using real data.
Slides, Colab notebooks, DataCamp, practice quizzes, cheat sheets
In-class, discussion board, and bookable meetings with us
Every component builds towards your final project β from your first variable to building a working analysis pipeline.


Three pieces, each building on the one before β nothing arrives without a run-up.
Week 6 Β· In-class MCQ test, 1 hour
Week 7 Β· Take-home
Theme: a next-generation sequencing task β to be confirmed.
Week 11 Β· Take-home
Theme: still being decided.
Full details of the projects will be covered in the Week 5 Project Practical. Projects are submitted via Canvas.
We value your feedback and do our best to act on it!
Polls in workshops
End-of-term questionnaire
In person / by email
Three places you'll run Python on this course β each hands you more control and flexibility.
Pyodide β Python running right on the slide. Zero install. Great for quick experiments in lectures.
Free cloud notebooks with the biology stack pre-installed. Run anywhere, share a link, collaborate.
VS Code + UV β the real-world workflow. For when you want to write actual research code.
By the end of today you'll have written a working GC-content calculator β the first step of Claudia's pipeline.
Try it now β edit the code and hit Run.
The = sign means assignment, not equality β read it as βput this value into this nameβ. Once stored, you reuse the value by its name.
Run it β nothing appears. The values are stored; showing them is the next step.
Hand any value to print() and Python displays it. Pass several values separated by commas and it prints them on one line, with spaces in between.
This is how you check a variable holds what you expect.
Run it, then try printing your own values:
Prefix a string with f and wrap any variable name in { } β the value is swapped in, with the spacing exactly as you typed it.
f-strings are straightforward, versatile, and easy to understand.
A built-in function works out of the box β no import needed. The pattern is always the same: function(value).
Forgotten what one does? Pass it to help() and Python prints the official documentation β for any function. Try round(2.5) too: Python rounds half to even, so the answer is 2, not 3.
When Python hits something it can't do, it stops and prints a traceback.
Don't panic β read the last line. It names the error type and tells you exactly what went wrong. Every programmer reads these all day long.
Run your code β did you get an error? Read the last line of the traceback for the error type. Above that, Python tells you exactly which line the error occurred on.
The code is written wrongly β a missing quote, bracket or colon.
Count your brackets and quotes.
You used a name Python has never seen β usually a typo or a missing assignment.
Check the spelling matches where you defined it.
You asked for something the value canβt do β like adding text to a number.
Convert first: "ATG" + str(5).
Three bugs stand between this script and a clean gene report.
Fix one bug at a time and re-run. The error message moves as you go β that's progress, not a new problem.
Sequences, names, IDs
Counts: bases, codons, samples
Fractions, concentrations, p-values
Yes/no answers: is_coding, passes_qc
Pass any value to type() and Python reports its type. The classic trap: "16" (a string) is not 16 (an integer) β and you can't do maths on text.
Run it β then try 9 / 16 vs 16 > 0:
Integers and Floats work with mathematical operators, either directly or when assigned to a variable
This is the first half of the GC calculation we'll finish in a moment.
Even when the numbers divide evenly. That decimal point is Python keeping your fractions accurate β exactly what GC content needs.
9 / 3 # 3.0 (a float, not 3!) gc_count = 9 length = 16 gc_frac = gc_count / length # 0.5625
A fraction like 0.5625 becomes a friendlier percentage once you multiply by 100 and round it.
gc_frac * 100 # 56.25 round(gc_frac * 100, 1) # 56.2 percent (1 decimal place)
Beyond function(value), every value carries its own toolkit β methods, written value.method().
A sneak preview for now β we'll discover more methods as we progress through the module. Try using .count() for different substrings β how many "GC"s are there in sequence?
No new concepts β every line uses something we've seen today.
Try it: swap in a new sequence (e.g. "GGGGAAAATTTTCCCC") and re-run.
A quick anonymous quiz to close β just for fun!
It tells me what to go over again β so a wrong answer here is worth more to me than a right one.
Which line prints Sample S-014 has pH 7.4?
sample = "S-014" ph = 7.4
print("Sample {sample} has pH {ph}")print(f"Sample {sample} has pH {ph}")print("Sample $sample has pH $ph")print(f"Sample {{sample}} has pH {{ph}}")A reading arrives from a file as "3.14", quotes included. What is it?
print(type("3.14"))<class 'float'><class 'str'><class 'int'><class 'decimal'>Which of these will Python accept as a variable name?
2nd_samplebuffer phbuffer_ph.count
One step at a time β and you've already written a real bioinformatics program. Take a break, grab a coffee. β
Today you analysed one sequence. But Claudia has a whole folder of them β first we need a way to hold many at once, and to look inside each one.
πͺ Coding is a muscle β it grows by use. Half an hour of practice between sessions is worth more than re-watching the lecture.
See you next week!