Back to Tinkering

Building a Tissue Simulator

github.com/CGATCG/digital_tissue

I built a simulation of a tissue, specifically a gut. At the simplest level, it is a 2D grid. Each position can be a living cell, empty space, or a structural feature like a lumen. That spatial layout matters, because molecules diffuse through extracellular space, cells can only divide if there is nearby room, and the geometry of the tissue changes how nutrients, signals, and damage move through it.

Inside that grid, each cell has actual molecular machinery. The simulator tracks genes, RNAs, proteins, metabolites, transporters, and pathways as separate layers. In the larger models there are hundreds of these layers. One of the cancer organism models has more than 460. So instead of saying a cell "has metabolism" or "takes up glucose," the simulator represents the full chain of events that makes that possible.

A cell can have a gene for some protein, transcribe it into RNA, translate that into protein, use that protein to import nutrients, and then use those nutrients to make ATP and stay alive. If any part of that chain starts to fail, the consequences propagate. If the cell loses the proteins needed to import glucose, ATP drops. If ATP drops too much, the cell dies. If a pathway enzyme is missing, pathway throughput drops. If damage accumulates past a threshold, the cell dies for that reason instead.

That is the core idea: cells have to live with the consequences of their biology.

The simulator updates all of this using explicit rules each tick. Some rules are simple mathematical expressions over the grid. Some expand across whole classes of molecules using foreach-style loops, so you can define one generic transcription or translation rule and apply it across many genes. There are also physically motivated diffusion rules, active transport across membranes using importer and exporter proteins, cell division rules that split molecular contents between parent and daughter, and pathway rules that behave like little enzyme-modulated directed graphs.

Tissue simulator screenshot

I also built stochasticity into the system from the start. Diffusion can be stochastic, transport can be stochastic, and there are built-in random field generators for biological variability. So even with the same starting conditions, runs do not have to play out identically. The system is noisy in the same way biology is noisy.

Another part I wanted was to make the outputs feel less like raw simulator internals and more like experimental readouts. So the simulator can generate assay-like outputs, including bulk RNA sequencing, proteomics, metabolomics, and spatial transcriptomics style data with realistic noise models like Gamma-Poisson sampling, log-normal scaling, ambient contamination, bleed-through, and dropout. That means you can ask not just what is happening in the tissue, but what you would actually be able to observe from it experimentally.

It also supports perturbation screens and evolutionary optimization. You can overexpress or knock down proteins, run the simulation forward, and measure effects on tissue health. You can also define a fitness function, like maximizing alive cells or minimizing starvation deaths, and evolve the initial molecular state of the tissue to search for better solutions. There is a simple global scaling genetic algorithm mode, and a more flexible per-cell optimization mode using the Cross-Entropy Method.

Tissue simulator optimization screenshot

Everything lives in a single JSON file. The grid dimensions, all the layers, all the update rules, all the measurements, all the pathway definitions. So the whole tissue is explicit, inspectable, and reproducible. You can diff it, version it, generate it programmatically, and share the full state of an experiment as one file.

So the project is basically an attempt to make a tissue simulator where the cells are not just abstract agents on a grid, but little molecular systems embedded in space, trying to survive. And once you build enough of that machinery in, interesting behavior starts to emerge on its own.

The goal of this project is to have a complex biology-like system that AIs can use to play and try to control, and for me to study how they attempt to do it and what we can build for them to do this better.