# CODING DETAILS

DEFINING THE PARAMETERS:

Number of F cells at time t = 0 (nf0)

Number of R cells at t = 0 (nr0)

F cells division time (tf)

R cells division time (tr)

Probability that a cell will switch phenotype every minute (ps)

Total modelling duration (tTotal)

Number of trials (trials)

The initial “cell age” was randomised and the cell division function was defined.

### HOW CELLS SWITCH THEIR PHENOTYPES

Four states were defined, namely F state, Ft state, R state, and Rt state. Bf, Br, Bft, Brt represents
the number of cells undergoing phenotype switching during the cell cycle in F state, Ft state, R state,
and Rt state respectively simulated by binomial distribution. Such events were represented by red and
yellow lines on the figure. Cells undergoing phenotype switching during cell division were represented
by white lines.

For cells in Ft and Rt state, they would enter F state and R state respectively after cell division
represented by the green lines.

### COMPUTATIONAL METHODS

Within each state, a matrix was used to represent the number of cells at a certain cell age (row) over
time (column).

Using F state matrix as an example, it has dimensions of tf x (tTotal + 1) which row 0 denotes
newly-divided cells, row tf-1 denotes cells approaching division, column 0 represents number of cells at
t = 0, while column tTotal represents that at t = tTotal.

Using the flow chart above, we can derive the following equations for non-dividing cells (which j ≠
tf-1) and for dividing cells (which j = tf-1) which are used to compute the values of the matrixes.

The total number of cells in F state and R state over time were computed by summing up F state & Ft
state matrices, and R state & Rt state matrices respectively across each column, and were returned in
the function.

Subsequently, the simulations were repeated over a defined number of trials and the mean, standard
deviation, 95% range, coefficient of variation (CV) for F cells, R cells, and total number of cells over
time were calculated. The proportion of F cells and R cells over time, the ratio of F cells to R cells
over time were also computed..

Exponential regression of mean cells and standard deviation for F cells, R cells and total number of
cells with R2 values, along with the converging values of CV for F cells, R cells, and all cells as well
as the values of F cells proportion, R cells proportion, and F:R ratio were calculated.