Free book sample

Deep Learning for Biological Systems

Building Computational Models with PyTorch for Real-World Biological Problems

You'll move from understanding PyTorch fundamentals to building production-ready deep learning models that solve real biological challenges.

222 pages11 chaptersJun 19, 2026Deep Learning

Download sample:

About this book

This book guides you through the complete workflow of computational biology projects: from formulating biological questions as machine learning problems, through data acquisition and preprocessing, to model development, validation, and deployment. You'll learn how to work with diverse biological data types—genomic sequences, protein structures, medical images, and time-series measurements—using PyTorch's flexible architecture. Each chapter combines theoretical foundations with practical code examples, showing you how to handle the messy realities of biological data including class imbalance, missing values, and limited samples. You'll discover how to leverage transfer learning, implement custom loss functions for biological objectives, and validate models using domain-specific metrics. By the end, you'll have the skills to design computational solutions that bridge the gap between cutting-edge machine learning and meaningful biological discovery.

Table of contents

  1. IntroductionWhy PyTorch for Computational Biology, What This Book Covers, How to Use This Book, Prerequisites and SetupRead below
  2. Chapter 1: PyTorch Fundamentals for Biological ComputingTensors and Core Operations, Automatic Differentiation and Backpropagation, Building Neural Networks with nn.Module
  3. Chapter 2: Understanding Biological DataTypes of Biological Data: Sequences, Images, and Graphs, Accessing and Retrieving Biological Datasets, Common Challenges in Biological Data
  4. Chapter 3: Data Preprocessing and Feature EngineeringCleaning and Validating Biological Data, Normalization and Scaling Strategies, Feature Engineering for Biological Signals
  5. Chapter 4: Sequence Models for Genomics and ProteomicsRNNs, LSTMs, and GRUs for Sequence Analysis, Transformers and Attention Mechanisms, Practical Applications: Gene Prediction and Protein Classification
  6. Chapter 5: Convolutional Networks for Biological ImagingCNN Architecture and Design Principles, Medical Image Analysis with Deep Learning, Microscopy Image Processing and Cell Detection
  7. Chapter 6: Graph Neural Networks for Molecular SystemsGraph Representations of Molecules and Proteins, Graph Convolutional Networks and Message Passing, Drug Discovery and Molecular Property Prediction
  8. Chapter 7: Addressing Data Imbalance and Limited SamplesTechniques for Handling Class Imbalance, Data Augmentation Strategies for Biological Data, Transfer Learning and Pre-trained Models
  9. Chapter 8: Training, Validation, and OptimizationBuilding Robust Training Loops, Custom Loss Functions for Biological Objectives, Hyperparameter Tuning and Model Selection
  10. Chapter 9: Evaluation and Biological ValidationChoosing Appropriate Evaluation Metrics, Cross-Validation and Statistical Testing, Model Interpretability and Biological Insights
  11. Chapter 10: Deployment and Production WorkflowsSaving, Loading, and Versioning Models, Software Engineering Best Practices, Ensuring Reproducibility and Documentation
  12. Chapter 11: End-to-End Case StudiesCase Study 1: Disease Classification from Medical Images, Case Study 2: Protein Function Prediction from Sequences, Case Study 3: Molecular Property Prediction with Graphs
  13. ConclusionKey Takeaways and Next Steps, Future Directions in Computational Biology
  14. Appendix: Resources and ReferencesPyTorch Documentation and Tutorials, Biological Databases and Data Sources, Further Reading and Research Papers

Introduction

Biology is generating data at a pace that no human team can fully analyze on its own. A single genomics lab can sequence thousands of genomes in a week. A hospital imaging department produces millions of scans every year. Drug discovery pipelines screen billions of molecular candidates. The sheer volume, complexity, and variety of biological data have created an urgent need for computational tools that can find patterns, make predictions, and surface insights at scale. Deep learning has emerged as one of the most powerful answers to that need, and PyTorch has become the framework of choice for researchers and engineers building those tools.

This book sits at the intersection of two fields that are rapidly converging. Computational biology has long used statistical and algorithmic methods to make sense of biological systems. Deep learning, meanwhile, has transformed fields from computer vision to natural language processing by learning rich representations directly from raw data. When these two disciplines meet, the results are remarkable: models that predict protein structures with near-experimental accuracy, neural networks that detect cancer in medical images as reliably as expert radiologists, and graph-based systems that accelerate drug discovery by predicting molecular properties before a single compound is synthesized.[1]

Yet the path from a biological question to a working deep learning model is rarely straightforward. Biological data is messy, heterogeneous, and often scarce. The domain knowledge required to interpret results correctly is deep and specialized. The gap between a proof-of-concept notebook and a production-ready pipeline is wide. This book is designed to help you close all three of those gaps. Whether you are a software developer moving into computational biology or a bioinformatician looking to add deep learning to your toolkit, the chapters ahead will give you the practical skills and conceptual grounding to build models that actually work on real biological problems.

The approach throughout is hands-on and concrete. Every major concept is paired with PyTorch code, real datasets, and worked examples drawn from genomics, proteomics, medical imaging, and molecular biology. The goal is not just to teach you how to use PyTorch, but to help you think like a computational biologist who happens to be an expert in deep learning. That means understanding why certain architectural choices make sense for sequence data but not for graph-structured molecules, why accuracy alone is a misleading metric for imbalanced clinical datasets, and why a model that performs well on a benchmark may still fail to produce biologically meaningful results.

Why PyTorch for Computational Biology

PyTorch has become the dominant framework in academic research, and computational biology is no exception. A 2023 survey of machine learning papers in top venues found that PyTorch was used in roughly 75% of published deep learning research, a share that has grown steadily since the framework's release in 2016.[2] That dominance is not accidental. PyTorch was designed with researchers in mind, and its core design philosophy aligns remarkably well with the exploratory, iterative nature of computational biology work.

The most important technical reason to choose PyTorch is its dynamic computation graph, also called define-by-run execution. In frameworks that use static graphs, you define the entire computation before running it. In PyTorch, the graph is built on the fly as your code executes. For biological data, this matters enormously. Protein sequences vary in length. Molecular graphs have different numbers of atoms and bonds. Genomic windows may need to be resized based on the region being analyzed. Dynamic graphs handle all of this naturally, without requiring padding tricks or graph compilation workarounds.

PyTorch also integrates tightly with the Python scientific ecosystem. Libraries like NumPy, SciPy, Pandas, and Biopython are standard tools in computational biology workflows. PyTorch tensors can be converted to and from NumPy arrays with a single function call, and the framework plays well with visualization tools like Matplotlib and Seaborn. This interoperability means you can move fluidly between data exploration, preprocessing, model training, and result analysis without switching environments or reformatting data.

The biological deep learning community has built a rich ecosystem of PyTorch-based tools that you can leverage directly. Consider a few examples:

  • PyTorch Geometric (PyG): A library for graph neural networks, widely used for molecular property prediction and protein interaction modeling.
  • ESM (Evolutionary Scale Modeling): Meta's protein language model, built in PyTorch, which provides pre-trained embeddings for protein sequences.
  • MONAI: A PyTorch-based framework specifically designed for medical image analysis, with built-in support for 3D imaging formats and clinical data pipelines.
  • Scanpy and scVI-tools: Single-cell analysis tools that use PyTorch under the hood for variational autoencoders and deep generative models.

Debugging is another area where PyTorch shines for biological applications. When a model produces biologically implausible outputs, you need to inspect intermediate activations, trace gradient flow, and test individual components in isolation. PyTorch's eager execution mode makes this straightforward. You can insert a print() statement anywhere in your forward pass, use Python's standard debugger, or inspect tensor values interactively in a Jupyter notebook. This transparency is invaluable when you are trying to understand why a model is making a particular prediction about a gene or a drug candidate.

Finally, PyTorch's training infrastructure has matured significantly. Tools like PyTorch Lightning reduce boilerplate in training loops while preserving full flexibility. The torch.utils.data module provides efficient data loading with multi-worker support, which is critical when working with large genomic datasets or high-resolution microscopy images. And PyTorch's support for distributed training across multiple GPUs means that as your datasets grow, your infrastructure can scale with them without requiring a complete rewrite of your codebase.

Choosing a framework is a long-term commitment. The code you write today will be read, modified, and extended by collaborators and future versions of yourself. PyTorch's clean, Pythonic API and its alignment with how biologists and bioinformaticians already think about data make it the right foundation for the work ahead.

What This Book Covers

This book follows the complete arc of a computational biology deep learning project, from the first lines of PyTorch code to a deployed, documented, and reproducible model. Each chapter builds on the previous ones, but the structure also allows you to jump to specific topics if you already have experience in certain areas. Here is a map of the journey ahead.

Chapters 1 through 3 establish the foundations. Chapter 1 covers PyTorch fundamentals: tensors, automatic differentiation, and building neural networks with nn.Module. These are not just introductory concepts; they are the building blocks you will use in every subsequent chapter. Chapter 2 surveys the landscape of biological data, covering the major types (sequences, images, and graphs), where to find them, and the challenges they present. Chapter 3 dives into preprocessing and feature engineering, which is often where the most important work in a computational biology project happens.

Chapters 4 through 6 cover the three major architectural families used in biological deep learning, each matched to a specific data type:

  • Chapter 4 (Sequence Models): RNNs, LSTMs, GRUs, and Transformers for genomic and proteomic sequences. You will build models for gene prediction and protein classification.
  • Chapter 5 (Convolutional Networks): CNN architectures for biological imaging, including medical image analysis and microscopy-based cell detection.
  • Chapter 6 (Graph Neural Networks): GNNs for molecular systems, with applications in drug discovery and molecular property prediction.

Chapters 7 through 9 address the practical challenges that separate toy examples from real-world systems. Chapter 7 tackles class imbalance, data augmentation, and transfer learning, which are essential skills when working with the small, skewed datasets common in biology. Chapter 8 covers training loops, custom loss functions, and hyperparameter tuning. Chapter 9 focuses on evaluation and validation, including how to choose metrics that are meaningful for biological problems and how to make your model's predictions interpretable to domain experts.

Chapter 10 covers deployment and production workflows, including model serialization, software engineering best practices, and reproducibility. This chapter is often skipped in machine learning books, but it is critical for anyone who wants their models to be used by others or to stand up to scientific scrutiny. Chapter 11 brings everything together with three end-to-end case studies: disease classification from medical images, protein function prediction from sequences, and molecular property prediction with graph networks.

Throughout the book, you will find code examples written in PyTorch that are designed to run on a standard laptop with a modest GPU, or even on CPU for smaller experiments. All datasets used are publicly available, and the appendix provides links to databases, documentation, and further reading. The goal is to give you a complete, self-contained resource that you can return to repeatedly as your projects evolve.

One thing this book deliberately does not do is treat biology as a backdrop for machine learning demonstrations. The biological context matters. When a chapter discusses loss functions, it explains why cross-entropy may be inappropriate for certain genomic prediction tasks and what to use instead. When a chapter covers evaluation metrics, it explains what precision-recall tradeoffs mean in the context of rare disease detection. The computational and biological reasoning are always presented together, because that integration is what makes the difference between a model that scores well on a benchmark and one that produces genuine scientific value.

How to Use This Book

This book is designed to be read sequentially on a first pass, but it is also structured to serve as a reference you can return to for specific topics. The chapters follow a logical progression, and later chapters assume familiarity with concepts introduced earlier. If you are new to PyTorch, working through Chapters 1 through 3 in order before moving on will save you significant confusion later. If you already have PyTorch experience, you can skim Chapter 1 and focus on the biological data sections starting in Chapter 2.

Each chapter follows a consistent structure that is worth understanding before you begin:

  1. Conceptual foundation: The chapter opens with the key ideas and why they matter for biological applications, without assuming you already know the material.
  2. Technical deep dive: Core concepts are explained with enough depth to understand what is happening under the hood, not just how to call the right function.
  3. Code examples: Practical PyTorch implementations are woven throughout, not saved for the end. You should be running code as you read.
  4. Biological context: Each technical concept is grounded in a real biological application, so you understand not just the how but the why.
  5. Common pitfalls: Each chapter highlights mistakes that are easy to make and explains how to avoid or recover from them.

The code examples in this book are meant to be run, not just read. The most effective way to use this book is to have a Python environment open alongside it. Type out the code examples rather than copying and pasting them. Modify the parameters. Break things intentionally and observe what happens. This active engagement will build intuition that passive reading cannot provide. All code is written to be clear and educational rather than maximally optimized, so you can follow the logic without getting lost in performance tricks.

For readers who are primarily developers with limited biology background, pay special attention to the biological context sections in each chapter. Understanding why a problem is structured the way it is will help you make better architectural and preprocessing decisions. A useful habit is to look up any biological term you encounter that you do not recognize. Resources like the NCBI Genetics Home Reference and UniProt's help documentation are written for non-specialists and can fill gaps quickly.

For readers who are primarily biologists or bioinformaticians with limited deep learning experience, the opposite advice applies: spend extra time with the PyTorch fundamentals in Chapter 1 and do not rush past the autograd section. Understanding how gradients flow through a network is not just theoretical knowledge; it directly informs decisions about architecture, initialization, and debugging. The investment in that foundation pays dividends in every subsequent chapter.

A practical suggestion: keep a project notebook alongside this book. As you work through each chapter, identify one aspect of your own research or work where the techniques covered could apply. Sketch out how you would adapt the examples to your specific data and problem. By the time you finish the book, you will have the outline of a real project, not just a collection of completed exercises.

The case studies in Chapter 11 are particularly valuable as integration exercises. After reading each case study, try to identify the decisions made at each stage of the pipeline and ask yourself whether you would have made the same choices. Consider what would change if the dataset were smaller, the class imbalance more severe, or the biological question slightly different. This kind of critical engagement with worked examples is one of the fastest ways to develop genuine expertise.

Finally, do not skip the deployment and reproducibility chapter (Chapter 10), even if your immediate goal is research rather than production software. The practices covered there, including version control for models, documentation standards, and reproducible experiment tracking, are habits that will make your research more credible, more collaborative, and easier to build on over time. Science that cannot be reproduced is not science, and models that cannot be understood by others have limited impact.

Prerequisites and Setup

This book assumes a specific level of background knowledge. Being clear about those assumptions upfront will help you assess where you stand and what gaps you might want to fill before diving in. The prerequisites fall into three categories: programming, mathematics, and biology.

Programming prerequisites are the most important. You should be comfortable with Python 3 at an intermediate level. Specifically, you should be able to:

  • Write and use Python classes, including inheritance and method overriding
  • Work with NumPy arrays, including indexing, slicing, and broadcasting
  • Use Pandas DataFrames for data manipulation and filtering
  • Read and write files in common formats (CSV, FASTA, JSON, HDF5)
  • Use virtual environments and manage dependencies with pip or conda
  • Navigate a terminal and run scripts from the command line

Mathematical prerequisites are more modest than you might expect. You do not need a graduate-level mathematics background, but you should be comfortable with the following concepts at an intuitive level:

  • Linear algebra: matrix multiplication, dot products, vector norms
  • Calculus: the concept of a derivative and the chain rule (you do not need to compute them by hand)
  • Probability and statistics: distributions, mean, variance, conditional probability, and basic hypothesis testing
  • Logarithms and exponentials, which appear frequently in loss functions and activation functions

Biology prerequisites are intentionally kept accessible. You do not need a biology degree to benefit from this book. Each chapter introduces the biological concepts needed to understand the problem being solved. That said, some familiarity with the following will help you move faster:

  • The central dogma of molecular biology (DNA to RNA to protein)
  • Basic genomics terminology: genes, exons, introns, mutations, variants
  • The concept of protein structure and function at a high level
  • What a molecular formula and chemical structure represent

For the software environment, the recommended setup uses Python 3.10 or later with PyTorch 2.0 or later. The following packages are used throughout the book and should be installed in your environment:

pip install torch torchvision torchaudio
pip install torch-geometric
pip install biopython
pip install scikit-learn pandas numpy matplotlib seaborn
pip install monai
pip install jupyter notebook
pip install captum  # for model interpretability

If you have access to a CUDA-compatible GPU, PyTorch will use it automatically once the CUDA version of PyTorch is installed. For most examples in this book, a GPU with 8GB of VRAM is sufficient. If you do not have a local GPU, Google Colab provides free access to GPU instances and works well for all the code examples in this book. Simply upload the notebook files and run them in the Colab environment. The appendix includes links to pre-configured Colab notebooks for each chapter.

To verify that your environment is set up correctly, run the following quick check in a Python interpreter or Jupyter notebook:

import torch
import torch_geometric
import Bio

print(f"PyTorch version: {torch.__version__}")
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"PyTorch Geometric version: {torch_geometric.__version__}")
print(f"Biopython version: {Bio.__version__}")

If all four lines print without errors, your environment is ready. If you encounter installation issues, the PyTorch website provides platform-specific installation commands at pytorch.org/get-started, and the PyTorch Geometric documentation at pytorch-geometric.readthedocs.io covers common installation pitfalls for that library. Most issues arise from mismatched CUDA versions, and the documentation walks through how to resolve them step by step.

One final note on mindset before you begin. Computational biology is a field where humility is a professional asset. The biological systems being modeled are genuinely complex, and even the best models are approximations. A model that achieves 95% accuracy on a held-out test set may still be capturing a spurious correlation rather than a meaningful biological signal. Throughout this book, the emphasis is on building models that are not just accurate but interpretable, reproducible, and grounded in biological reality. That standard is harder to meet than a benchmark score, but it is the standard that makes computational biology worth doing.

Back to contents

Notes

Introduction

  1. 1. J. Jumper and others, "Highly accurate protein structure prediction with AlphaFold," Nature, 2021
  2. 2. A. Paszke and others, PyTorch: An Imperative Style, High-Performance Deep Learning Library, NeurIPS 2019, 2019

This is the end of the free sample. The full book has 11 chapters.

Want this book written for you?

Tell us your goals and background, and get your own version of this book, tailored by AI to you.

User avatar
User avatar
User avatar
User avatar
User avatar
9,348 books created by readers like you
As seen on:
Product HuntRedditMediumDEV

Benefits of AI-tailored books

Read one book, not ten:
all the Deep Learning knowledge you need, gathered into a single book.
Save days of learning:
tell us your goals, choose your topics, and the whole book is built around them.
Learn effortlessly:
Deep Learning book written for your specific background and expertise.
Understand at a glance:
includes charts, tables, timelines, checklists, decision trees, and more.
Stay current:
written the day you order it, not years ago.
Trust what you read:
every book is checked for accuracy, with real research when your subject needs it.

Create your unique book in 3 steps

1. Select your focus

Select the focus of your Deep Learning book and share your background

Your Deep Learning book focus
2. Personalize your book

Specify your goals and choose sub-topics to include

3. Get your tailored book

Your book is ready in 10 minutes. Read it online, download as EPUB or PDF, or send to Kindle.

Frequently asked questions

What is TailoredRead?

TailoredRead creates complete, full-length nonfiction ebooks, written specifically for you. Tell us what you want to learn and why, and TailoredRead writes you a complete ebook on it, with charts, tables, and diagrams throughout. Read it online, on Kindle, or on any e-reader, or download it as a PDF or EPUB. Every book is written fresh the day you order it.

How is the book tailored to me?

Before anything is written, you answer a few short questions about your goals, your background, and the topics you care about. Your book is then planned around your answers: written at your level, focused on your goals, and covering the topics you chose, instead of the one-size-fits-all book a store sells everyone.

Will it read like generic AI content?

No. Your book isn't a chat transcript: it's planned chapter by chapter before a single word is written, told in a clear book voice, and explains ideas visually with charts, tables, and diagrams. After writing, every book goes through an editorial pass that polishes chapters so the book reads consistent from start to finish. Judge for yourself: browse thousands of sample books on our Explore Books page.

How accurate is the content?

Our AI first checks whether your subject needs live research. Niche and fast-moving subjects are researched before writing, and the book plan and chapters are grounded in what it finds. After writing, every book goes through a quality pass that checks its facts and consistency, and researched books list their sources in a Notes section at the back.

How long is the book?

You choose the length: Comprehensive (250-300 pages), Detailed (150-200 pages), Essential (70-100 pages), or Short (30-50 pages).

Does the book include visuals?

Yes. Every book includes charts, tables, and diagrams: timelines, checklists, step-by-step guides, decision trees, comparison tables, matrices, and bar charts. A typical book includes dozens of these visual elements.

Can I read it on Kindle? What formats can I download?

Yes. Every book can be read in our online reader or downloaded as a PDF or EPUB. The EPUB can be opened with Kindle, Apple Books, Kobo, and any e-reader. The Commercial and Author licenses also include an editable Word (DOCX) and Markdown download.

How much does it cost?

About the price of a regular ebook. The exact price depends on your book's length and complexity, from $2 for the shortest books to $35 for the most comprehensive, and it's shown when you review your book, before you commit to anything. Each book is a one-time purchase, yours to keep, no subscription. Licenses that let you share, teach, or publish your book range from $35.99 to $49.99.

Can I preview the book before purchasing?

Before you pay, you'll see what your book will cover: the title, a detailed description, the estimated length, and the complete chapter-by-chapter table of contents, so you know what you're getting before you decide. The full text itself is written after you purchase.

How long does it take to create a book?

About 10 minutes. You can start reading the opening chapters while the rest is still being written.

Personalize and buy this book

Get your personalized version, tailored by AI to your goals, background, and interests