Modeling a Disease-model in python
Introduction
Modeling a Disease-model in python
Introduction
Disease modeling is among one the important tool to understand cellular dynamics and interactions between cells and tumors. This is essentially simulating the process of infection and tumor growth in a microenvironment, computationally. This lets us explore various therapeutic methods and circumstances to gain knowledge about the underlying biological mechanisms and treatment options.
[embed]Learn more about cell division
Immune cells and cancer cells are examples of cellular systems that are dynamic and complicated with many interacting parts. Researchers can investigate these systems’ temporal behavior and capture their complexity through modeling. Models can be used to study things like how immune cells and cancer cells interact, how various treatments affect tumor development, and how drug resistance develops.
A variety of quantitative methods, from straightforward differential equations to more intricate agent-based models, can be used to create models. Researchers can test their hypotheses and improve their knowledge of the underlying biology by calibrating these models using experimental data.

Learn More about Disease Modelling
Overall, disease modeling is a useful instrument for comprehending how cells and tumors behave and has the potential to guide the creation of novel therapies and treatment plans.
The Model
The model considered here is shown below with the progression of cancer depicted in this diagram as an illness. The model has five different variables: C, H, IL, T, and S
The equations are as follows :
dCdt = rC C (1 — (T/K)) (1 — S) — dC C
dHdt = rH * H
dILdt = kIL * H
dTdt = -kCT C T
dSdt = s * T
C represents the concentration of cancer cells.
H represents the concentration of healthy cells.
IL represents the concentration of interleukins (proteins involved in immune response)
T represents the concentration of tumor cells.
S represents the effect of treatment.
What would the diagrammatic model would look like for the above equations:

potential interaction map of the equations set above.
To better comprehend the dynamics of cancer progression and therapy, use the diagram that illustrates the intricate interactions between various disease model components.
eq1. dCdt = rC C (1 — (T/K)) (1 — S) — dC C
dCdt represents the change in the concentration of cancer cells over time and is dependent on the rate of growth of cancer cells (rC), the competition for resources with other cells (1-(T/K)), the effect of treatment (1-S), and the death rate of cancer cells (dC).
eq2. dHdt = rH H*
eq3. dILdt = kIL H*
Hdt and dILdt represent the changes in the concentration of healthy cells and interleukins over time, respectively, and are dependent on the growth rate of healthy cells (rH) and the production rate of interleukins (kIL)
eq4. dTdt = -kCT C T
dTdt represents the change in the concentration of tumor cells over time and is dependent on the competition for resources with other cells, the death rate of tumor cells due to treatment (kCT), and the concentration of tumor cells themselves (T).
eq5. dSdt = s T*
dSdt represents the change in the effect of treatment over time and is dependent on the concentration of tumor cells (T) and the effectiveness of the treatment (s).
Some other parameters we could talk about include:
T/K: the ratio of tumor cells to the carrying capacity of the environment.
When T/K is close to 1, the environment is at capacity and there is limited space for further tumor growth.
S: the effect of treatment on cancer cell growth.
When S is 0, there is no treatment; when S is 1, the treatment is fully effective in stopping cancer cell growth.
Code discussion
from flask import Flask, render_template, request
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
app = Flask(__name__)
# Define the model
def model(y, t, rC, dC, rH, kIL, kCT, s, K):
C, H, IL, T, S = y
dCdt = rC * C * (1 - (T/K)) * (1 - S) - dC * C
dHdt = rH * H
dILdt = kIL * H
dTdt = -kCT * C * T
dSdt = s * T
return [dCdt, dHdt, dILdt, dTdt, dSdt]
The model function defines the differential equations for the system. It takes as input a vector y of the state variables (C, H, IL, T, S), the time t, and the parameters of the model (rC, dC, rH, kIL, kCT, s, K). It returns a list of the derivatives of the state variables, which represent the rate of change of each variable with respect to time.
The odeint function from the scipy.integrate the library is used to solve the differential equations for the system. It takes as input the model function, the initial state of the system y0, an array of time points t, and the parameters of the model (rC, dC, rH, kIL, kCT, s, K). It returns an array sol containing the values of the state variables at each time point.
# Define the route for the homepage
@app.route('/', methods=['GET', 'POST'])
def home():
# Default values for the model parameters
rC = 0.1
dC = 0.05
rH = 0.05
kIL: float = 0.1
kCT = 0.01
s = 0.01
K = 1000
# If the form has been submitted, update the parameters
if request.method == 'POST':
rC = float(request.form.get('rC', 0.1))
dC = float(request.form.get('dC', 0.05))
rH = float(request.form.get('rH', 0.05))
kIL = float(request.form.get('kIL', 0.1))
kCT = float(request.form.get('kCT', 0.01))
s = float(request.form.get('s', 0.01))
K = float(request.form.get('K', 1000))
Here it defines a route for the homepage of a web application created with Flask.
The function home() is executed when the homepage is requested, and it handles both GET and POST requests. At the beginning of the function, default values for several model parameters are defined. These values are used in case no data is submitted through the form.
If the form has been submitted, the function updates the model parameters using the values submitted via the POST request. request.form.get() is a method used to retrieve the values submitted via the form with the corresponding keys ('rC', 'dC', 'rH', etc.).
After updating the model parameters, the function proceeds to solve the differential equations defined in the model() function using the updated parameters. Finally, the function renders the homepage template with the updated parameters and the graph of the simulation results.
t = np.linspace(0, 100, 1000)
y0 = [50, 10, 0, 1000, 0]
sol = odeint(model, y0, t, args=(rC, dC, rH, kIL, kCT, s, K))
# Plot the results
fig, ax = plt.subplots()
ax.plot(t, sol[:,0], 'b', label='CTL cells')
ax.plot(t, sol[:,1], 'g', label='Th cells')
ax.plot(t, sol[:,2], 'r', label='IL-2')
ax.plot(t, sol[:,3], 'm', label='Tumour cells')
ax.plot(t, sol[:,4], 'y', label='Immune suppression factor')
ax.set_xlabel('Time')
ax.set_ylabel('Population')
ax.legend()
plt.savefig('static/plot.png')
# Render the homepage template with the current parameters and the graph
return render_template('index.html', rC=rC, dC=dC, rH=rH, kIL=kIL, kCT=kCT, s=s, K=K)
# Define the route for the results page
@app.route('/results')
def results():
# Render the results template with the graph
return render_template('results.html')
if __name__ == '__main__':
app.run(debug=True)
The second route is the results page, which displays only the graph. In the homepage route, the default values for the model parameters are defined. If the form has been submitted (i.e., the request method is POST), the parameters are updated with the values entered in the form.
The model is then solved using the updated parameters and the results are plotted using Matplotlib. The plot is saved as a PNG file in the static folder. Finally, the homepage template is rendered with the current parameters and the graph.
In the results route, the results template is rendered with the saved graph. The if name == ‘main’: statement checks if this file is being run as the main program, and if so, starts the Flask development server in debug mode.

index page
When a user accesses the application for the first time, they land on the home screen. Users can enter numbers for different model parameters on the page’s form. The home() method in the Python code is called when the submit button on the form causes a POST request to be sent to the server.
The function changes the parameter values after reading them from the form. Using the modified parameter values, the program then solves a differential equation model and produces a plot. The user can then either browse to the results page to view the plot in greater detail or resubmit the form with new parameter values.

result page
An image file created by the Flask program is displayed on the results page. The simulation findings are plotted in this image file after the mathematical model specified in the code has been solved. The plot image file is only mentioned once in the img element of the results.html template.
Flask renders the results.html template and gives it as the response when a user accesses the /results URL. As a consequence, the image file displaying the simulation findings is displayed on the page.
Hope you enjoyed reading this article and learned something!!
Thanks for reading 😊👍
Disease model: https://www.embl.org/topics/disease-models/#:~:text=Understanding%20the%20causes%20of%20disease,of%20the%20same%20disease%20processes.
메타데이터
- post_id
- 7ed129c1d19d
- slug
- modeling-a-disease-model-in-python-7ed129c1d19d
- url
- https://medium.com/@anoopjohny2000/modeling-a-disease-model-in-python-7ed129c1d19d
- canonical_url
- https://medium.com/@anoopjohny2000/modeling-a-disease-model-in-python-7ed129c1d19d
- author_url
- https://medium.com/@anoopjohny2000
- status
- ok
- fetched_at
- 2026-06-09 15:37:30