Steve Jobs once said:
“Everybody in this country should learn to program a computer, because it teaches you how to think”.
I fully agree with this, programming is not just a way to solve problems or getting things done, but it can be so much more.
If you learn programming, you will see how your coding skills can affect the ways you think as you progress to gain more knowledge. After all, if you know a problem well enough to describe it to a computer, you probably know it better than most.
This TED talk (10 min) by Christian Genco sums up the argument in a nice way.
Python is a general programming language, the world's most popular in 2019 and its popularity has only increased since. Python is especially popular in the fields of data science and bioinformatics, two fields that should be of interest to a biology student.
Python has a compact syntax (not many keywords to remeber) and easily readable code since it contains few special characters, such as semicolons.
Compare the two programs below, the first one in C++, another popular coding language and then the same program in Python.
// This C++ program prints Hello, World!
#include <iostream>
int main()
{
std::cout << "Hello, World!";
return 0;
}
# This Python program prints Hello, World!
print("Hello, World!")
The goal of the program is to print the message "Hello World!" on the screen, which is probably obvious. I think most people would agree that the Python version is more intuitive.
This is not to say that one computer language (such as Python) is necessarily better than another for all purposes. However, it is safe to say that Python is probably one of the best for beginners.
Because of its simplicity, Python is also suitable for people who do not code every day (like me). It is suitable both for quick scripts for automation of some repetitive task but also for complex software with graphical interfaces and websites.
One of the most important advantages of Python is the large size of its community, since this means that you can often find questions and answers to your coding problems by a simply searching with google.
An added benefit is the large variety of functionality that has been created and made available in software packages.
A software package is a collection of files, usually to solve common problems in a specific area such as statistics or bioinformatics, that has been packaged for distribution and installation.
Widely used Python packages include:
- Numpy - comprehensive mathematical functions
- SciPy - algorithms for optimization, integration, interpolation
- Biopython - tools for biological computation
- Pandas - data analysis and manipulation
- Matplotlib - static, animated, and interactive visualizations
- scikit-learn - efficient tools for predictive data analysis and machine learning
- NLTK - programs to work with human language data
- Pillow - powerful image processing
Python is used for everything from
- Graphical User Interface for sequence checksums (code).
- Stock and cryptocurrency trading (video).
- Quantitative Economics (lectures).
- Population dynamics (blog).
- Reading data from a commercial temperature data logger (code).
- Controlling the height of a standing desk code video.
You can even make games using Python:
We will spend one hour (or so) learning the basics of Python using simple examples. The exercises are aimed at complete beginners with no previous programming experience.
The tutor will demonstrate basic data types, repetition and decision making in the logical flow of a program. We will use the Spyder integrated development environment (IDE). At the end we will code a simple example relevant to biology/bioinformatics.
The free Anaconda Scientific Python distribution from Continuum analytics is a nice way to install python on just about any computer. Anaconda is available for the Microsoft Windows, MacOSX and Linux platforms. Anaconda makes it easy to install Python packages with extra functionality. The the whole installation is located in one folder in the user's directory that is easy to uninstall.
Go to the Anaconda website and download the Anaconda installation file for your operating system. Follow the installation instructions to save the file. Beware that the installation file is large ~600 mb.
Double click the installer and follow the instructions. Select default options when asked.
For installation on Linux, type: bash Anaconda3-2021.05-Linux-x86_64.sh
. in the terminal to start the installation
If you have any trouble installing, check the detailed instructions here.
The next step is to start the Python editor Spyder. Start “Spyder” from the start menu of your computer.
The Spyder editor was installed with the Anaconda distribution that you should have installed before this class (See previous section).
Download and save the file spyder_session.py
by clicking on the download button above.
IMPORTANT! Save the file with a ".py" ending, sometimes MS Windows wants to add a ".txt" file type. This file will not be recognized by Spyder as a Python file.
Start Spyder from the start menu of your computer. Open the file using the file>open menu of Spyder. It should look like in the picture below:
Spyder has two important parts, the text editor to the left and the interactive console to the right at the bottom.
We will go through the content of spyder_session.py
together.
I hope this hour has inspired you to learn how to code with Python or another programming language. As any new language that you might try to learn, you will lose your new knowledge if you do not practise. The challenge is to practise by finding something in your daily life, however small, where you can apply programming to save time or improve quality.
Here is a list of ten suggested programming projects for beginners.
"This course bridges the gap between introductory and advanced courses in Python. While there are many excellent introductory Python courses available, most typically do not go deep enough for you to apply your Python skills to research projects. In this course, after first reviewing the basics of Python 3, we learn about tools commonly used in research settings. This version of the course includes a new module on statistical learning."
Rosalind is a platform for learning bioinformatics through problem solving.
LeetCode is an online judge platforms that you can use to practice your programming skills by solving coding questions.
Here you'll find resources for learning to program in Python for people with a background in biology
Want to learn and master Python? Exercism’s free Python Track for access to 129 exercises grouped into 15 Python Concepts.
Tutorial - Learn Python in 10 minutes
"The course consists of few hundreds of programming assignments for Python, ranging from basics up to complex topics. Right now Stepik is developing an adaptive learning engine which chooses content for each learner individually – by his/her level and knowledge gaps. In this course you can try out the first prototype of this engine."
Pythonroom lets anyone teach computer science.
How to Think Like a Computer Scientist: Interactive Edition