Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Bioinformatics with Python Cookbook

You're reading from   Bioinformatics with Python Cookbook Solve advanced computational biology problems and build production pipelines with Python and AI tools

Arrow left icon
Product type Paperback
Published in Dec 2025
Publisher Packt
ISBN-13 9781836642756
Length 618 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Shane Brubaker Shane Brubaker
Author Profile Icon Shane Brubaker
Shane Brubaker
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Chapter 1: Computer Specifications and Python Setup 2. Chapter 2: Basics of Data Manipulation FREE CHAPTER 3. Chapter 3: Modern Coding Practices and AI-Generated Coding 4. Chapter 4: Data Science and Graphing 5. Chapter 5: Alignment and Variant Calling 6. Chapter 6: Annotation and Biological Interpretation 7. Chapter 7: Genomes and Genome Assembly 8. Chapter 8: Accessing Public Databases 9. Chapter 9: Protein Structure and Proteomics 10. Chapter 10: Phylogenetics 11. Chapter 11: Population Genetics 12. Chapter 12: Metabolic Modeling and Other Applications 13. Chapter 13: Genome Editing 14. Chapter 14: Cloud Basics 15. Chapter 15: Workflow Systems 16. Chapter 16: More Workflow Systems 17. Chapter 17: Deep Learning and LLMs for Nucleic Acid and Protein Design 18. Chapter 18: Single-Cell Technology and Imaging 19. Chapter 19: Unlock Your Exclusive Benefits 20. Index 21. Other Books You May Enjoy

Introduction to Jupyter Notebook

All of our work will be developed inside Jupyter Notebook. Jupyter has become the de facto standard for writing interactive data analysis scripts. Unfortunately, the default format for Jupyter notebooks is based on JSON. JSON is JavaScript Object Notation (https://www.json.org/json-en.html). This format is difficult to read, difficult to compare, and needs exporting to be fed into a normal Python interpreter. To obviate that problem, we will extend Jupyter with jupytext (https://jupytext.readthedocs.io/), which allows us to save Jupyter notebooks as normal Python programs. We will start with an overview of Jupyter Notebook, and then look into jupytext. Recall that we installed Jupyter Notebook in the first recipe of this chapter, when we installed the jupyterlab package using conda.

How to do it…

  1. To run Jupyter, on the Terminal, type the following:
    jupyter notebook

    This will open the Jupyter browser, and you will see a home page that looks something like this:

Figure 1.1 – The Jupyter browser home page

This home page gives you an overview of your files, so you can open, rename, and download them, and so on.

  1. Let’s click on one of the files and open it. We will see something like this:

Figure 1.2 – An example of a notebook

Here, we see a menu that allows us to save or download files and perform other actions. Each cell can be executed by clicking the play button. You can also run multiple cells. When you run a cell, you will see its output below.

In some cases, you may need to restart your kernel – use the Kernel | Restart Kernel... method.

Jupyter notebook resources

This would be a good time to pause and take some time to learn more about Jupyter notebooks. There are numerous keyboard shortcuts that are worth learning to speed up your development:

Tutorial: https://www.datacamp.com/tutorial/tutorial-jupyter-notebook

Keyboard Shortcuts: https://towardsdatascience.com/jypyter-notebook-shortcuts-bf0101a98330

Now that we have set up our Jupyter Notebook environment, let’s take a look at a handy tool called Jupytext.

Jupytext

Sometimes, you will want to convert your notebooks into formats other than ipynb – for example, you might want to get them into .py format. For this, we can use jupytext - https://github.com/mwouts/jupytext. This handy plugin will allow us to save Jupyter notebooks in formats other than .ipynb. Remember to get out of the Jupyter browser first. To do this on a Mac, you would close the Jupyter browser window, then go to the Terminal where you started it. Then, click Ctrl + Z to kill the process.

To install jupytext, we will run the following:

pip install jupytext

Now let’s start up the Jupyter browser again:

jupyter notebook

Now we’ve launched the Jupyter browser again, open the Welcome notebook. Go to the File | Jupytext menu. Here is what it looks like:

Figure 1.3 – The Jupytext menu within the Jupyter browser

To save your notebook in another format, you pair it and choose a format. For instance, if you choose to pair it with the light format, you will get a regular Python (.py) formatted file in your current working directory.

Here is what our Welcome.py file looks like in our working directory when paired with the light format:

Figure 1.4 – The Welcome.py notebook in the Light format produced by Jupytext

There are several other popular formats supported by Jupytext. You can read more about them here: https://jupytext.readthedocs.io/en/latest/index.html.

Warning

Remember that the recipes in this book are normally meant to be run inside Jupyter notebooks. This means, typically, we will not always use print to output content. In a notebook, if you simply put the name of a variable and run it, it will print out the result for you. If you are not using notebooks (e.g. you are writing Python scripts and executing them from the terminal), you may want to add print statements to your code. Even within a notebook, you may find it useful at times to add your own print statements to inspect variables and debug code.

In addition to the Jupyter browser, there is a more integrated environment called JupyterLab: https://jupyterlab.readthedocs.io/en/latest/. It allows you to run Terminals and other widgets inside the same environment as your notebook. To get to it, you can click View | Open JupyterLab. You can check it out if you are interested, but it is not necessary to get through the book.

A welcome notebook called Welcome.ipynb has been placed in the GitHub repository for this book in the Ch01 folder. You can use it to test out your notebook environment. This notebook also contains many handy links to help you learn Python and explore bioinformatics!

To recap everything, here are your main options for performing the recipes in this book:

System

Components

Pros

Cons

MacBook Pro Laptop

Anaconda; pip; brew; Jupyter

Best system for compatibility and ease of use

You may not own one

Mac Cloud Workstation or Mac AWS EC2 Instance

Anaconda; pip; brew; Jupyter

Convenient solution; identical to Mac laptop

May incur some costs

Windows Machine + Docker

Docker

Portable solution

Some increased overhead

Windows + VirtualBox or WSL2

Anaconda; pip; brew; Jupyter

Let’s you interact with a Linux OS

Some installation or compatibility issues may arise

Linux Machine

Anaconda; pip; brew; Jupyter

Let’s you interact with a Linux OS

Some installation or compatibility issues may arise

Table 1.2 – System and OS options for use with this book

See also

lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Bioinformatics with Python Cookbook
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime
Modal Close icon
Modal Close icon