Introduction to Python for Bioinformatics - available at https://github.com/kipkurui/Python4BioinformaticsV2.
Python Version: 3.13 (Latest stable release)
These tutorials are an adaptation of the Introduction to Python for Maths by Andreas Ernst, available from https://gitlab.erc.monash.edu.au/andrease/Python4Maths.git. The original version was written by Rajath Kumar and is available at https://github.com/rajathkumarmp/Python-Lectures.
These notes have been greatly amended and updated for the MSC Bioinformatics and Molecular Biology at Pwani university, sponsored by EANBiT by Caleb Kibet
Throughout this course, we will be using Jupyter Notebooks.These notes are provided for you want to set it up in your Computer.
The Jupyter Notebook is an interactive computing environment that enables users to author notebooks, which contain a complete and self-contained record of a computation. These notebooks can be shared more efficiently. The notebooks may contain:
- Live code
- Interactive widgets
- Plots
- Narrative text
- Equations
- Images
- Video
It is good to note that "Jupyter" is a loose acronym meaning Julia, Python, and R; the primary languages supported by Jupyter.
The notebook can allow a computational researcher to create reproducible documentation of their research. As Bioinformatics is datacentric, use of Jupyter Notebooks increases research transparency, hence promoting open science.
-
Download Miniconda or Anaconda for your specific OS
- Linux:
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh - Mac:
curl https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh - Windows: Download installer
- Linux:
-
Install Miniconda:
- Linux/Mac:
bash Miniconda3-latest-*.sh - Windows: Run the downloaded .exe installer
- Follow all prompts (accept defaults if unsure)
- Linux/Mac:
-
Close and re-open your terminal
-
Verify installation:
conda --version
-
Create the conda environment using the provided
environment.ymlfile:conda env create -f environment.yml
-
Activate the environment:
conda activate python4bioinformatics
If you prefer to create the environment manually:
conda create --name python4bioinformatics python=3.13
conda activate python4bioinformatics
conda install -c conda-forge jupyterlab numpy pandas matplotlib seaborn scipy biopython-
Clone the repository:
git clone https://github.com/kipkurui/Python4BioinformaticsV2.git cd Python4BioinformaticsV2Or download as ZIP:
wget https://github.com/kipkurui/Python4BioinformaticsV2/archive/master.zip unzip master.zip rm master.zip cd Python4BioinformaticsV2-master -
Create and activate the conda environment:
conda env create -f environment.yml conda activate python4bioinformatics
-
Launch Jupyter Lab:
jupyter lab
Using Jupyter Notebooks:
- Each notebook contains cells with Python code or text
- Execute a cell: Press
Shift-Enter(run and move to next) orCtrl-Enter(run without moving) - We recommend using Jupyter Lab for the best experience
- Download Anaconda from https://www.anaconda.com/download
- Run the installer and follow the installation wizard
- Anaconda includes Jupyter Notebook by default
- Download Miniconda from https://docs.conda.io/en/latest/miniconda.html
- Install and open "Anaconda Prompt" from Start menu
- Install Jupyter:
conda install jupyter
- Open Command Prompt or PowerShell
- Install Jupyter:
pip install jupyter
- Open Anaconda Navigator from Start menu
- Click "Launch" under Jupyter Notebook
- Open "Anaconda Prompt" (or Command Prompt/PowerShell if using pip)
- Navigate to your project directory:
cd C:\path\to\your\project
- Launch Jupyter:
jupyter notebook
- Browser window opens automatically at http://localhost:8888
- Click "New" → "Python 3" to create a new notebook
- Type code in cells and press
Shift + Enterto run - Use
Ctrl + Enterto run cell without moving to next - Press
Escfor command mode,Enterfor edit mode - Save with
Ctrl + Sor File → Save
Command Mode (press Esc):
A- Insert cell aboveB- Insert cell belowDD- Delete cellM- Convert to markdownY- Convert to code
Edit Mode (press Enter):
Shift + Enter- Run cell and move to nextCtrl + Enter- Run cell in placeTab- Code completion
Navigate to the project directory and launch Jupyter:
cd C:\path\to\Python4BioinformaticsV2
jupyter notebookTo learn more about Jupyter notebooks, check the official introduction and some useful Jupyter Tricks.
Book: http://www.ict.ru.ac.za/Resources/cspw/thinkcspy3/thinkcspy3.pdf
Python is a modern, robust, high-level programming language. It is straightforward to pick up even if you are entirely new to programming.
Python, similar to other languages like Matlab or R, is interpreted hence runs slowly compared to C++, Fortran or Java. However, writing programs in Python is very quick. Python has an extensive collection of libraries for everything from scientific computing to web services. It caters for object-oriented and functional programming with a module system that allows large and complex applications to be developed in Python.
These lectures are using Jupyter notebooks which mix Python code with documentation. The python notebooks can be run on a web server or stand-alone on a computer.
This course is broken up into a number of notebooks (lectures).
- 00 This introduction with additional information below on how to get started in running python
- 01 Basic data types and operations (numbers, strings)
- 02 String manipulation
- 08 Data Analysis and plotting with Pandas
- 09 Reproducible Bioinformatics Research
- 10 Reproducible Bioinformatics Research
This is a tutorial style introduction to Python. For a quick reminder/summary of Python syntax, the following Quick Reference Card may be useful. A longer and more detailed tutorial style introduction to python is available from the python site at: https://docs.python.org/3/tutorial/.
To contribute, fork the repository, make some updates and send me a pull request.
Alternatively, you can open an issue.
This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.