April 21, 2020

## What is life?

Biology is the study of life

Life is a complex phenomenon

To understand life, biologists invented Systems Theory

## Systems Theory

Systems Theory was invented in 1948 by the biologist Ludwig von Bertalanffy

Today it is used by engineers, psychologists, managers, and other scientists

It is going to be one of the important ways of thinking in this century

## Systems

A system is a group of parts that are interconnected and affect each other

• The parts are separated and well defined
• Instead of parts, we can say items or components
• They have interactions, for example a process that transforms some items into others

## Example: cell-food system

Today we will study a system with two items

• Cells
• Food

and one process

• Eating, which also was cell duplication

## How to draw the system

The arrows going into a box show which items are required for the process

• The items that point towards a process are the inputs that will be consumed by the process
• When a item is consumed by a process, its amount gets smaller
• The arrows going out of a box show which are the products of the process
• The amount of these items will increase with the process.

## Each item has two values

At any given moment, there is some amount of each item in the system

• for example, the number of cells

Also, we can know how much did the amount changed between the previous moment and this moment

• for example, the growth of cells

## Representing items in R

Each item (circle) has two values, that change with time

We will represent these values with vectors

• The amount of item will be called item
• The change of item will be called d_item

## These are dynamical systems

Dynamical system means that the system changes with time

We will represent time by a positive integer number

Time i represents “now”. The units can be seconds, hours, days, years, or whatever is best to understand the system

If we use “days”, then i-1 means “yesterday”. It can also be “last year” or “one second ago”

## Systems are in a state

1. The particular condition that someone or something is in at a specific time
• water in a liquid state.
2. The amounts of all items (circles) in a system.
• cells[i]
• food[i]

## The state of the system changes with time

In any fixed time, the state is all the values of items’ quantities

• one value for each item
• Examples:
• cells[i], food[i]
• Concentration of H, O, Water
• Number of foxes and rabbits
• Number of primers and DNA molecules

## How items change

The “boxes” of the system represent processes

They do not change with time

The have one constant value called rate

For each process we have a value process_rate

## The state today depends only on the past states

The new state depends only on the past states, nothing else

If we know the initial state and rate constants, we can calculate everything

## Finding the formulas for boxes

For each box in the graph we get only one term

We multiply the rate constant and each of the amount variables of the circles connected by incoming arrows

We use the index i-1. Processes depend on the previous values

If there are several incoming arrows from the same circle, then the variable is multiplied several times

The outgoing arrows are not important in this part

## Example: cell–food system

We will write the formulas for the cell–food system

• First write the terms for each box (process)
• Then write the formulas for each circle (item)

## Example: cell–food system

There are two arrows coming into the eating box

The formula for this box is

eating_rate * cells[i-1] * food[i-1]

We use the index i-1 because we do not know yet the value of cells[i] or food[i]

We will calculate them later

At the begin of “today” we only know “yesterday”

## Formulas for circles

To get the formula for each circle

• sum all the terms of boxes connected with incoming arrows,
• minus all the terms of boxes connected with outgoing arrows

This value is assigned to the delta variable of the circle.

In our example the formula for delta_food is

d_food[i] <-  -eating_rate * cells[i-1] * food[i-1]

since the food circle has only one outgoing arrow

## Formula for the circle (cont…)

The cell circle has two incoming arrows
from eat and one outgoing arrow to eat.
Therefore

d_cells[i] <-   eating_rate * cells[i-1] * food[i-1]
+ eating_rate * cells[i-1] * food[i-1]
- eating_rate * cells[i-1] * food[i-1]

which, after simplification, is just

d_cells[i] <- eating_rate * cells[i-1] * food[i-1]

resulting on a final result of one positive incoming arrow

## If there are several arrows

In the last slide we had several arrows between the cells circle and the eating box

It is easy to see that we only care about the resulting number and direction of arrows

Two input - One output = One input

## In summary

Now we can write the formulas
for all the delta variables

d_food[i]  <- -eating_rate * cells[i-1] * food[i-1]
d_cells[i] <-  eating_rate * cells[i-1] * food[i-1]

Finally, the amount variables have to be updated

Each amount variable is the cumulative sum of the delta variables

food[i]  <- food[i-1]  + d_food[i]
cells[i] <- cells[i-1] + d_cells[i]

## Initial conditions

The last missing piece are the initial values of the circles’ variables.

The value of cells[i] depends on the value of cells[i-1], and we can only calculate that for i >= 2

We will use the variables cells_ini and food_ini to define the values used in cells[1] and food[1]

For the delta variables, we can assume that they are initially zero.

## All code togethers

N <- 168
cells   <- d_cells <- rep(NA, N)
food    <- d_food  <- rep(NA, N)
cells[1] <- 1
food[1]  <- 20
d_cells[1] <- d_food[1]  <- 0

for(i in 2:N) {
d_cells[i] <- cells[i-1]*food[i-1]*eating_rate
d_food[i]  <- -cells[i-1]*food[i-1]*eating_rate
cells[i]  <- cells[i-1] + d_cells[i]
food[i]   <- food[i-1]  + d_food[i]
}

## We will write it as a function

cell_culture <- function(N, eating_rate, cells_ini, food_ini) {
cells   <- d_cells <- rep(NA, N)
food    <- d_food  <- rep(NA, N)
cells[1] <- cells_ini
food[1]  <- food_ini
d_cells[1] <- d_food[1]  <- 0
for(i in 2:N) {
d_cells[i] <- cells[i-1]*food[i-1]*eating_rate
d_food[i]  <- -cells[i-1]*food[i-1]*eating_rate
cells[i]  <- cells[i-1] + d_cells[i]
food[i]   <- food[i-1]  + d_food[i]
}
return(data.frame(cells, food, d_cells, d_food))
}

## This is what you have to remember

system_name <- function(N, rates, initial_cond) {
state   <- d_state <- rep(NA, N)
state[1] <- initial_cond
d_state[1]  <- 0
for(i in 2:N) {
d_state[i] <- some formula
state[i]  <- state[i-1] + d_state[i]
}
return(data.frame(state, d_state))
}

## Notation

In R we can write several assignments in one line

A <- rep(NA, N)
C <- rep(NA, N)
A <- B <- C <- rep(NA, N)