Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a8b277a
Create new_branch
sdromigny Oct 18, 2023
2501c11
Merge pull request #3 from sdromigny/sdrom
robertdoanesolomon Oct 18, 2023
9b667a9
add 2 functions for the 2 PK models : intravenous IV and subcutaneous…
sdromigny Oct 18, 2023
e85b08d
committing codecov file
robertdoanesolomon Oct 18, 2023
53ae6fb
committing basic.yml for codecov
robertdoanesolomon Oct 18, 2023
d67f4ab
Update basic.yml
robertdoanesolomon Oct 18, 2023
2f4cb5d
Update basic.yml
robertdoanesolomon Oct 18, 2023
fcaac26
Update basic.yml
robertdoanesolomon Oct 18, 2023
a220a41
testing
robertdoanesolomon Oct 18, 2023
180833f
Merge branch 'dev' of github.com:robertdoanesolomon/software-engineer…
robertdoanesolomon Oct 18, 2023
9b9ae29
Update basic.yml
robertdoanesolomon Oct 18, 2023
f883140
committing codecov thing
robertdoanesolomon Oct 18, 2023
40c8c2e
Update test_model.py
robertdoanesolomon Oct 18, 2023
255b77b
Remove old test files.
tristramwalsh Oct 18, 2023
91a5a1b
Update basic.yml
robertdoanesolomon Oct 18, 2023
52a8f18
Update test_model.py
robertdoanesolomon Oct 18, 2023
4a63c0e
Add basic pyproject.toml for setuptools, and comment out all code in …
tristramwalsh Oct 18, 2023
c22ad8f
Change name of continuous integration branch to 'master' instead of '…
tristramwalsh Oct 19, 2023
21c008a
Minimal working installable package structure. src/package structure …
tristramwalsh Oct 19, 2023
6936e25
Merge branch 'packaging' into rob_packaging
tristramwalsh Oct 19, 2023
20f0405
Merge pull request #16 from robertdoanesolomon/rob_packaging
tristramwalsh Oct 19, 2023
ab9b084
updated model.p but still not working (issue #7 and #15)
sdromigny Oct 19, 2023
1c6e4dc
parametreisation works, nowI just need to write function for integrat…
sdromigny Oct 19, 2023
df4afb6
Merge branch 'packaging' into dev
tristramwalsh Oct 19, 2023
31dc31f
upl
robertdoanesolomon Oct 19, 2023
e076bb0
git uncommit
robertdoanesolomon Oct 19, 2023
98ef1dd
uploading plot code
robertdoanesolomon Oct 19, 2023
837af92
Update path to package for continuous integration, to be aligned with…
tristramwalsh Oct 19, 2023
f5ca045
issue #7 and #15 are resolved:parametrising and integration functions…
sdromigny Oct 19, 2023
58529d6
try to make the dev and the sixtine-functions braches merge
sdromigny Oct 19, 2023
4d2829d
Merge branch 'dev' into sixtine_functions
tristramwalsh Oct 19, 2023
3fd39b7
solution.py updated with still faulty visualisation
sdromigny Oct 19, 2023
8589c60
Rhiannon-s code added in solution.py in srd/pkmodel
sdromigny Oct 19, 2023
02fd8f9
solution.py works!
sdromigny Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Coverage

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev]
python -m pip install pytest
python -m pip install pytest-cov

- name: Run coverage
run: |
pytest --cov-config=.coveragerc --cov=./pkmodel --cov-report=xml --cov-branch
cat coverage.xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: coverage.xml
120 changes: 119 additions & 1 deletion pkmodel/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#
# Model class
#
import matplotlib.pylab as plt
import numpy as np
import scipy.integrate
from scipy.integrate import odeint

class Model:
"""A Pharmokinetic (PK) model
Expand All @@ -13,5 +17,119 @@ class Model:

"""
def __init__(self, value=42):
self.value = value
self.value = value

class IV(Model):
# Your class definition here
def __init__(self, parameters=[0, 0, 0, 0, 0]):
super().__init__()
self.parameters = parameters

def paramIV(self, y, t):
Q_p1, V_c, V_p1, CL, X = self.parameters
q_c, q_p1 = y
transition = Q_p1 * (q_c / V_c - q_p1 / V_p1)
dqc_dt = X - q_c / V_c * CL - transition
dqp1_dt = transition
return [dqc_dt, dqp1_dt]

def integrate():
iv_instance = IV()
t_eval = np.linspace(0, 1, 1000)
y0 = [0.0, 0.0]
iv_instance.parameters = parameters
solution = odeint(iv_instance.paramIV, y0, t_eval)
q_c, q_p1 = solution.T
return np.array([q_c,q_p1])

############TESTING IF CLASS WORKS
# parameters = [0.7, 1, 2, 3, 4]
# test1=IV.integrate()
# print('test1',test1.shape)

############INTEGRATION OUTSIDE THE CLASS
# # Create an instance of the IV class
# iv_instance = IV()

# # Define the time points at which you want to evaluate the solution
# t_eval = np.linspace(0, 1, 1000)

# # Initial conditions
# y0 = [0.0, 0.0]

# # Parameters
# parameters = [0.7, 1, 2, 3, 4]

# # Set the parameters in the instance
# iv_instance.parameters = parameters

# # Solve the ODEs using odeint
# solution = odeint(iv_instance.paramIV, y0, t_eval)

# # Extract the results
# q_c, q_p1 = solution.T

# Print the results
# print(q_c)
# print(q_p1)


class SC(Model):
"subcutaneous model"
def __init__(self, parameters=[0, 0, 0, 0, 0,0]):
super().__init__()
self.parameters = parameters

def paramSC(self, y, t):
Q_p1, V_c, V_p1, CL, X, ka = self.parameters
q_c, q_p1, q_0= y
dq0_dt = X - ka*q_0
transition = Q_p1 * (q_c / V_c - q_p1 / V_p1)
dqc_dt = ka*q_0 - q_c / V_c * CL - transition
dqp1_dt = transition
return [dqc_dt, dqp1_dt,dq0_dt]

def integrate():
sc_instance = SC()
t_eval = np.linspace(0, 1, 1000)
y0 = [0.0, 0.0, 0.0]
sc_instance.parameters = parameters
solution = odeint(sc_instance.paramSC, y0, t_eval)
q_c, q_p1, q_0 = solution.T
return np.array([q_c,q_p1,q_0])


############TESTING IF CLASS WORKS
# parameters = [0.7, 1, 2, 3, 4, 5]
# test2=SC.integrate()
# print('test2',test2.shape)

############INTEGRATION OUTSIDE THE CLASS
# # Create an instance of the IV class
# sc_instance = SC()

# # Define the time points at which you want to evaluate the solution
# t_eval = np.linspace(0, 1, 1000)

# # Initial conditions
# y0 = [0.0, 0.0,0]

# # Parameters
# parameters = [0.7, 1, 2, 3, 4,7]

# # Set the parameters in the instance
# sc_instance.parameters = parameters

# # Solve the ODEs using odeint
# solution = odeint(sc_instance.paramSC, y0, t_eval)

# print(solution.shape)

# # Extract the results
# # print(solution.T.shape)
# q_c, q_p1, q_0 = solution.T

# # Print the results
# # print(q_c.shape)
# # print(q_p1.shape)
# # print(solution.y[0, :])
38 changes: 24 additions & 14 deletions pkmodel/solution.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#
# Solution class
#
import numpy as np
import matplotlib.pylab as plt
import model

class Solution:
"""A Pharmokinetic (PK) model solution
def visualise(modeldata):
time=np.linspace(0,1,1000)
fig, ax = plt.subplots()
# Plot q_c
plt.plot(time, modeldata[0,:], label = 'q_c')
# Plot q_p1
plt.plot(time, modeldata[1,:], label = 'q_p1')
# Plot q_0
if np.shape(modeldata) == (3, 1000):
plt.plot(time, modeldata[2,:], label = 'q_0')
plt.title('Subcutaneous model')
else:
plt.title('IV model')
plt.legend()
ax.set_ylabel('drug mass (ng)')
ax.set_xlabel('time [h]')
#plt.savefig('plot.png')
plt.show()

Parameters
----------

value: numeric, optional
an example paramter

"""
def __init__(self, value=44):
self.value = value
parameter=[1,2,3,4,5]

result=visualise(model.IV.integrate())
print(result)
58 changes: 44 additions & 14 deletions prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
def dose(t, X):
return X

def rhs(t, y, Q_p1, V_c, V_p1, CL, X):
#intravenous injection model

def IV(t, y, Q_p1, V_c, V_p1, CL, X):
q_c, q_p1 = y
transition = Q_p1 * (q_c / V_c - q_p1 / V_p1)
dqc_dt = dose(t, X) - q_c / V_c * CL - transition
dqp1_dt = transition
return [dqc_dt, dqp1_dt]

print(IV(2,[1,2],3,4,5,6,7))
model1_args = {
'name': 'model1',
'Q_p1': 1.0,
Expand All @@ -21,32 +23,60 @@ def rhs(t, y, Q_p1, V_c, V_p1, CL, X):
'X': 1.0,
}

#subcutaneous dosing
def SC(t, y, Q_p1, V_c, V_p1, CL, X, ka):
q_c, q_p1, q0= y
dq0_dt = dose(t,X) - ka*q0
transition = Q_p1 * (q_c / V_c - q_p1 / V_p1)
dqc_dt = ka*q0 - q_c / V_c * CL - transition
dqp1_dt = transition
return [dqc_dt, dqp1_dt,dq0_dt]


model2_args = {
'name': 'model2',
'Q_p1': 2.0,
'V_c': 1.0,
'V_p1': 1.0,
'CL': 1.0,
'X': 1.0,
'ka':1.0
}

t_eval = np.linspace(0, 1, 1000)
y0 = np.array([0.0, 0.0])

fig = plt.figure()
for model in [model1_args, model2_args]:
args = [
model['Q_p1'], model['V_c'], model['V_p1'], model['CL'], model['X']
]
sol = scipy.integrate.solve_ivp(
fun=lambda t, y: rhs(t, y, *args),
t_span=[t_eval[0], t_eval[-1]],
y0=y0, t_eval=t_eval
)
plt.plot(sol.t, sol.y[0, :], label=model['name'] + '- q_c')
plt.plot(sol.t, sol.y[1, :], label=model['name'] + '- q_p1')

args = [
model1_args['Q_p1'], model1_args['V_c'], model1_args['V_p1'], model1_args['CL'], model1_args['X']
]
sol = scipy.integrate.solve_ivp(
fun=lambda t, y: IV(t, y, *args),
t_span=[t_eval[0], t_eval[-1]],
y0=y0, t_eval=t_eval
)
plt.plot(sol.t, sol.y[0, :], label=model1_args['name'] + '- q_c')
plt.plot(sol.t, sol.y[1, :], label=model1_args['name'] + '- q_p1')



y0 = np.array([0.0, 0.0, 0.0])

args = [
model2_args['Q_p1'], model2_args['V_c'], model2_args['V_p1'], model2_args['CL'], model2_args['X'], model2_args['ka']
]
sol = scipy.integrate.solve_ivp(
fun=lambda t, y: SC(t, y, *args),
t_span=[t_eval[0], t_eval[-1]],
y0=y0, t_eval=t_eval
)
plt.plot(sol.t, sol.y[0, :], label=model2_args['name'] + '- q_c')
plt.plot(sol.t, sol.y[1, :], label=model2_args['name'] + '- q_p1')

plt.legend()
plt.ylabel('drug mass [ng]')
plt.xlabel('time [h]')
plt.show()

plt.savefig('plot.png')

31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "pkmodel"
version = "0.0.1"
authors = [
{ name="Rhiannon Ackland", email="[email protected]" },
{ name="Sarah Bull", email="[email protected]" },
{ name="Sixtine Dromigny", email="[email protected]" },
{ name="Robert Doane-Solomon", email="[email protected]" },
{ name="Tristram Walsh", email="[email protected]" },
]
description = "pkmodel is a Pharmokinetic modelling library."
readme = "README.md"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: Linux",
]
dependencies =[
'numpy',
'matplotlib',
'scipy',
'pytest',
]

[project.urls]
"Homepage" = "https://github.com/robertdoanesolomon/software-engineering-projects-pk"
"Bug Tracker" = "https://github.com/robertdoanesolomon/software-engineering-projects-pk/issues"
Loading