Martin Krzywinski / Genome Sciences Center / Martin Krzywinski / Genome Sciences Center / - contact me Martin Krzywinski / Genome Sciences Center / on Twitter Martin Krzywinski / Genome Sciences Center / - Lumondo Photography Martin Krzywinski / Genome Sciences Center / - Pi Art Martin Krzywinski / Genome Sciences Center / - Hilbertonians - Creatures on the Hilbert Curve
This love loves love. It's a strange love, strange love.Liz Fraserfind a way to lovemore quotes

orbits: exciting

In Silico Flurries: Computing a world of snow. Scientific American. 23 December 2017

visualization + design

Martin Krzywinski @MKrzywinski
The 2018 Pi Day art celebrates the 30th anniversary of `\pi` day and connects friends stitching road maps from around the world. Pack a sandwich and let's go!

`\pi` Day 2016 Art Posters

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2018 `\pi` day shrinks the world and celebrates road trips by stitching streets from around the world together. In this version, we look at the boonies, burbs and boutique of `\pi` by drawing progressively denser patches of streets. Let's go places.

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2017 `\pi` day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2016 `\pi` approximation day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2016 `\pi` day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2015 `\pi` day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2014 `\pi` approx day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2014 `\pi` day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
2013 `\pi` day

Pi Day 2016 Art Posters
 / Martin Krzywinski @MKrzywinski
Circular `\pi` art

On March 14th celebrate `\pi` Day. Hug `\pi`—find a way to do it.

For those who favour `\tau=2\pi` will have to postpone celebrations until July 26th. That's what you get for thinking that `\pi` is wrong.

If you're not into details, you may opt to party on July 22nd, which is `\pi` approximation day (`\pi` ≈ 22/7). It's 20% more accurate that the official `\pi` day!

Finally, if you believe that `\pi = 3`, you should read why `\pi` is not equal to 3.

Martin Krzywinski @MKrzywinski
All art posters are available for purchase.
I take custom requests.

This year's `\pi` day art collection celebrates not only the digit but also one of the fundamental forces in nature: gravity.

In February of 2016, for the first time, gravitational waves were detected at the Laser Interferometer Gravitational-Wave Observatory (LIGO).

The signal in the detector was sonified—a process by which any data can be encoded into sound to provide hints at patterns and structure that we might otherwise miss—and we finally heard what two black holes sound like. A buzz and chirp.

The art is featured in the Gravity of Pi article on the Scientific American SA Visual blog.

this year's theme music

All the art was processed while listening to Roses by Coeur de Pirate, a brilliant female French-Canadian songwriter, who sounds like a mix of Patricia Kaas and Lhasa. The lyrics Oublie-moi (Forget me) are fitting with this year's theme of gravity.

Mais laisse-moi tomber, laisse-nous tomber
Laisse la nuit trembler en moi
Laisse-moi tomber, laisse nous tomber
Cette fois

But let me fall, let us fall
Let the night tremble in me
Let me fall, let us fall
This time

simulating gravity in 2d

The gravitational force between two masses `m_1` located at `(x_1,y_1)` and `m_2` located at `(x_2,y_2)` is given by

$$F = \frac{G m_1 m_2}{r^2} \tag{1} $$

where `r` is the distance between the masses given by

$$r = \sqrt{ \Delta x ^2 + \Delta y ^2 } = \sqrt{ (x_2-x_1)^2 + (y_2-y_1)^2 } \tag{2} $$

The force is directed along the vector formed by `r` and can be decomposed into `x` and `y` components using \begin{align} F_x &= F \frac{ \Delta x}{r} = F \frac{x_2-x_1}{r} \tag{3} \\ F_y &= F \frac{ \Delta y}{r} =F \frac{y_2-y_1}{r} \tag{4} \end{align}

The acceleration of each mass can be obtained using `F = ma` and similarly decomposed into `x` and `y` components \begin{align} a_{1x} &= \frac { F_{1x} }{ m_1} = \frac{G m_2 \Delta x}{r^3} \tag{5} \\ a_{1y} &= \frac { F_{1y} }{ m_1} = \frac{G m_2 \Delta y}{r^3} \tag{6} \\ a_{2x} &= \frac { F_{2x} }{ m_2} = -\frac{G m_1 \Delta x}{r^3} \tag{7} \\ a_{2y} &= \frac { F_{2y} }{ m_2} = -\frac{G m_1 \Delta y}{r^3} \tag{8} \end{align}

When there are `n` masses in the system, the acceleration of mass `i` is the sum of the accelerations due to all other masses \begin{align} a_{ix} &= \sum_{i \ne j} \frac{G m_j \Delta x_{ij}}{r_{ij}^3} \tag{9} \\ a_{iy} &= \sum_{i \ne j} \frac{G m_j \Delta y_{ij}}{r_{ij}^3} \tag{10} \end{align}

The equations of motion for the masses over a period of time `\Delta t` are

\begin{align} \Delta v_x &= \Delta t a_x \tag{11} \\ \Delta v_y &= \Delta t a_y \tag{12} \\ \Delta x &= \Delta t \left( v_x + a_x \frac{\Delta t}{2} \right) \tag{13} \\ \Delta y &= \Delta t \left( v_y + a_y \frac{\Delta t}{2} \right) \tag{14} \end{align}

numerical simulation

There are various ways in which the numerical simulation can be performed. The Euler, Verlet, Runge-Kutta methods are perhaps the most common. I use the Verlet approach.

Using the equations of motions above, the Verlet simulation goes as follows

  1. calculate acceleration, `a_1` (eq 9,10)
  2. update position (eq 13,14)
  3. calculate new acceleration, `a_2` (eq 9,10)
  4. update velocity using `(a_1+a_2)/2` (eq 7,8)

The masses are initially uniformly distributed on a circle and given a zero initial velocity or a normally distributed random velocity.

I ran about 10,000 individual simulations with different values of `n` and `k` and collected ones that stood out as pretty.


The size of a mass is taken to be `s = m^{1/3}`. When two masses, `m_1` and `m_2` come within a distance of `\left( s_1 + s_2 \right)(1-z)` of each other, they collide. Here `z` is a collision margin parameter that I set to either `z=0` or `z=0.25`.

During the collision, a new body is created with mass `M = m_1 + m_2` given a speed that conserves momentum in the collision. \begin{align} v_x &= \frac{m_1 v_{1x} + m_2 v_{2x} }{M} \\ v_y &= \frac{m_1 v_{1y} + m_2 v_{2y} }{M} \end{align}


For my simulation, the following values are used

  • `G = 100`
  • mass for each digit, `d` is `(1+d)^k`
  • masses placed on circle with radius `216`
  • when randomized, `(v_x,v_y) \sim N(0,1)`
  • `\Delta t = 0.01`
  • simulation runs for up to 100,000 steps
  • canvas size is `1440 \times 1440`

news + thoughts

Oryza longistaminata genome cake

Mon 24-09-2018

Data visualization should be informative and, where possible, tasty.

Stefan Reuscher from Bioscience and Biotechnology Center at Nagoya University celebrates a publication with a Circos cake.

The cake shows an overview of a de-novo assembled genome of a wild rice species Oryza longistaminata.

Martin Krzywinski @MKrzywinski
Circos cake celebrating Reuscher et al. 2018 publication of the Oryza longistaminata genome.

Optimal experimental design

Tue 31-07-2018
Customize the experiment for the setting instead of adjusting the setting to fit a classical design.

The presence of constraints in experiments, such as sample size restrictions, awkward blocking or disallowed treatment combinations may make using classical designs very difficult or impossible.

Optimal design is a powerful, general purpose alternative for high quality, statistically grounded designs under nonstandard conditions.

Martin Krzywinski @MKrzywinski
Nature Methods Points of Significance column: Optimal experimental design. (read)

We discuss two types of optimal designs (D-optimal and I-optimal) and show how it can be applied to a scenario with sample size and blocking constraints.

Smucker, B., Krzywinski, M. & Altman, N. (2018) Points of significance: Optimal experimental design Nature Methods 15:599–600.

Background reading

Krzywinski, M., Altman, N. (2014) Points of significance: Two factor designs. Nature Methods 11:1187–1188.

Krzywinski, M. & Altman, N. (2014) Points of significance: Analysis of variance (ANOVA) and blocking. Nature Methods 11:699–700.

Krzywinski, M. & Altman, N. (2014) Points of significance: Designing comparative experiments. Nature Methods 11:597–598.

The Whole Earth Cataloguer

Mon 30-07-2018
All the living things.

An illustration of the Tree of Life, showing some of the key branches.

The tree is drawn as a DNA double helix, with bases colored to encode ribosomal RNA genes from various organisms on the tree.

Martin Krzywinski @MKrzywinski
The circle of life. (read, zoom)

All living things on earth descended from a single organism called LUCA (last universal common ancestor) and inherited LUCA’s genetic code for basic biological functions, such as translating DNA and creating proteins. Constant genetic mutations shuffled and altered this inheritance and added new genetic material—a process that created the diversity of life we see today. The “tree of life” organizes all organisms based on the extent of shuffling and alteration between them. The full tree has millions of branches and every living organism has its own place at one of the leaves in the tree. The simplified tree shown here depicts all three kingdoms of life: bacteria, archaebacteria and eukaryota. For some organisms a grey bar shows when they first appeared in the tree in millions of years (Ma). The double helix winding around the tree encodes highly conserved ribosomal RNA genes from various organisms.

Johnson, H.L. (2018) The Whole Earth Cataloguer, Sactown, Jun/Jul, p. 89

Why we can't give up this odd way of typing

Mon 30-07-2018
All fingers report to home row.

An article about keyboard layouts and the history and persistence of QWERTY.

My Carpalx keyboard optimization software is mentioned along with my World's Most Difficult Layout: TNWMLC. True typing hell.

Martin Krzywinski @MKrzywinski
TNWMLC requires seriously flexible digits. It’s 87% more difficult than using a standard Qwerty keyboard, according to Martin Krzywinski, who created it (Credit: Ben Nelms). (read)

McDonald, T. (2018) Why we can't give up this odd way of typing, BBC, 25 May 2018.

Molecular Case Studies Cover

Fri 06-07-2018

The theme of the April issue of Molecular Case Studies is precision oncogenomics. We have three papers in the issue based on work done in our Personalized Oncogenomics Program (POG).

The covers of Molecular Case Studies typically show microscopy images, with some shown in a more abstract fashion. There's also the occasional Circos plot.

I've previously taken a more fine-art approach to cover design, such for those of Nature, Genome Research and Trends in Genetics. I've used microscopy images to create a cover for PNAS—the one that made biology look like astrophysics—and thought that this is kind of material I'd start with for the MCS cover.

Martin Krzywinski @MKrzywinski
Cover design for Apr 2018 issue of Molecular Case Studies. (details)