Skip to content

Commit

Permalink
Extend partials, minor changes (#13)
Browse files Browse the repository at this point in the history
v0.5.6
  • Loading branch information
PharmCat authored Jul 13, 2023
1 parent 39771c4 commit e14950c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ on:
- main
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
timeout-minutes: 40
steps:
- uses: actions/checkout@v3
- name: Update
run: sudo apt-get update
- name: Install Pandoc
run: sudo apt-get install pandoc texlive-latex-recommended texlive-xetex texlive-luatex pandoc-citeproc texlive-latex-extra
- uses: julia-actions/setup-julia@latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaNCA"
uuid = "097c2839-c7bc-4c4b-a5f2-b4167c1b4e7c"
authors = ["PharmCat <[email protected]>"]
version = "0.5.5"
version = "0.5.6"

[deps]

Expand Down
25 changes: 25 additions & 0 deletions change.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
0.5.6
- extend partials

0.5.5
- partials

0.5.4
- minor changes

0.5.3
- minor fix precompile
- 1.9 support
- minor changes

0.5.2
- minor fix pkimport
- minor changes

0.5.2
- minor fix pkimport
- minor changes

0.5.1
- minor changes

0.5.0
- change pkplot api
- Minor changes
Expand Down
2 changes: 1 addition & 1 deletion docs/src/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Calculate steady-state parameters.
If end of tau interval lies after all observation, than extrapolation used to compute Ctau and partial AUCs. Extrapolation based on using elimination parameters.


## [Unitful details](@ref unitful_details)
## [Unitful details](@id unitful_details)

!!! warning
**Unitful.jl**
Expand Down
8 changes: 8 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ dsnca = nca!(ds, adm = :ev, calcm = :lint)
dsnca[:, :AUClast]
```

# Partial AUC

```@example ncaexample
dsnca = nca!(ds, adm = :ev, calcm = :lint, partials = [(1, 7)])
dsnca[:, :AUC_1_7]
```


## Print output

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Appendix 2: [Appendix2.1.pdf](./pdf/Appendix2.1.pdf), [Appendix2.2.pdf](./pdf/Ap

## Unitful

See [Unitful details](@id unitful_details).
See [Unitful details](@ref unitful_details).

## Contents

Expand Down
3 changes: 3 additions & 0 deletions src/import.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ function checkvalues(timevals_sp, concvals_sp; warn = true)
if !(eltype(concvals_sp) <: Union{Number, Missing})
warn && @warn "Some concentration values maybe not a number, try to fix."
concvals_sp_ = floatparse.(concvals_sp, warn)
elseif eltype(concvals_sp) <: Integer
warn && @warn "Concentration values transformed to float."
concvals_sp_ = float.(concvals_sp)
else
concvals_sp_ = identity.(concvals_sp)
end
Expand Down
26 changes: 19 additions & 7 deletions src/nca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,16 @@ end
Non-compartmental (NCA) analysis of PK/PD data.
"""
function nca!(data::DataSet{Subj}; adm = :ev, calcm = :lint, intpm = nothing, partials = nothing, verbose = 0, warn = true, io::IO = stdout, modify! = identity) where Subj <: AbstractSubject
function nca!(data::DataSet{Subj}; kwargs...) where Subj <: AbstractSubject
result = Vector{NCAResult{Subj}}(undef, length(data))
for i = 1:length(data)
result[i] = nca!(data[i]; adm = adm, calcm = calcm, intpm = intpm, partials = partials, verbose = verbose, warn = warn, io = io, modify! = modify!)
result[i] = nca!(data[i]; kwargs...)
end
DataSet(result)
end

"""
nca!(data::PKSubject{T,O}; adm = :ev, calcm = :lint, intpm = nothing, partials = nothing, verbose = 0, warn = true, io::IO = stdout, modify! = nothing) where T where O
nca!(data::PKSubject{T,O}; adm = :ev, calcm = :lint, intpm = nothing, partials = nothing, prtext = :err, verbose = 0, warn = true, io::IO = stdout, modify! = nothing) where T where O
* `adm` - administration:
- `:ev` - extra vascular;
Expand All @@ -434,7 +434,8 @@ end
- `:luld` - linear up log down;
- `:luldt` - linear up log down after Tmax;
- `:logt` - log-trapezoidal after Tmax;
* `partials` - calculate partial AUC vor vector of time intervals;
* `partials` - calculate partial AUC vor vector of time intervals (`:err` (default) - throw error if end time > last oservation time; `:last` - no extrapolation; `:extr` - if `Kel` calculated used extrapolation or `NaN` if no `Kel`);
* `prtext` - extrapolation rule for partials AUC;
* `verbose` - print to `io`, 1: partial areas table, 2: 1, and results;
* `warn` - show warnings;
* `io` - output stream;
Expand Down Expand Up @@ -488,8 +489,9 @@ Steady-state parameters (tau used):
* Vztau
`partials` is a vector of vectors, tuples or pairs. Example: `partials = [(1,2), (3,4)]`, `partials = [[1,2], (3,4)]`
"""
function nca!(data::PKSubject{T, O}; adm = :ev, calcm = :lint, intpm = nothing, partials = nothing, verbose = 0, warn = true, io::IO = stdout, modify! = identity) where T where O
function nca!(data::PKSubject{T, O}; adm = :ev, calcm = :lint, intpm = nothing, partials = nothing, prtext = :err, verbose = 0, warn = true, io::IO = stdout, modify! = identity) where T where O

ptype = promote_type(Float64, T, O)

Expand Down Expand Up @@ -706,7 +708,7 @@ function nca!(data::PKSubject{T, O}; adm = :ev, calcm = :lint, intpm = nothing,
suffix = "_"*string(stime)*"_"*string(etime)
stime = stime - data.dosetime.time
etime = etime - data.dosetime.time
if etime > last(time_cp) error("End time can't be greater than last time point!") end
if etime > last(time_cp) && prtext == :err error("End time can't be greater than last time point ($(last(time_cp)))! Use keyword `prtext=:last` or `prtext=:extr`...") end
#first point
firstp = findfirst(x -> x >= stime, time_cp)
#last point
Expand All @@ -718,11 +720,21 @@ function nca!(data::PKSubject{T, O}; adm = :ev, calcm = :lint, intpm = nothing,
firstpart += aucpart(stime, time_cp[firstp], firstpartc, obs_cp[firstp], calcm, stime > result[:Tmax])
#println("firstpartc = $firstpartc , firstpart = $firstpart")
end
if etime > time_cp[lastp]
if etime > time_cp[lastp] && etime < last(time_cp) # if last time > etime -> interpolation
lastpartc = interpolate(time_cp[lastp], time_cp[lastp + 1], etime, obs_cp[lastp], obs_cp[lastp + 1], intpm, time_cp[lastp] > result[:Tmax])
lastpart += aucpart(time_cp[lastp], etime, obs_cp[lastp], lastpartc, calcm, time_cp[lastp] > result[:Tmax])
#println("lastpartc = $lastpartc , lastpart = $lastpart")
elseif etime > time_cp[lastp] && prtext == :last
lastpartc = zero(O)
elseif etime > time_cp[lastp] && prtext == :extr && !isnan(result[:Kel])
lastpartc = exp(result[:LZint] + result[:LZ] * etime)
lastpart += aucpart(time_cp[lastp], etime, obs_cp[end], lastpartc, calcm, time_cp[lastp] > result[:Tmax])
else
lastpartc = NaN
lastpart += lastpartc
end


aucpartial = zero(T)*zero(O)
if firstp != lastp
aucpartn = lastp - firstp
Expand Down
12 changes: 12 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,18 @@ end
772.3366199961695
1213.5372385701808
969.4541441511578] atol=1E-6

ds = MetidaNCA.pkimport(pkdata2, :Time, :Concentration, [:Subject, :Formulation]; dosetime = MetidaNCA.DoseTime(dose = 100, time = 0.0, tau = 100))
sort!(ds, :Subject)

@test_throws ErrorException dsnca = MetidaNCA.nca!(ds, adm = :ev, calcm = :luld, partials = [(0.25, 100)], prtext = :err)

dsnca = MetidaNCA.nca!(ds, adm = :ev, calcm = :luld, partials = [(0, 100)], prtext = :last)
@test dsnca[:, :AUClast] dsnca[:, :AUC_0_100] atol=1E-6

dsnca = MetidaNCA.nca!(ds, adm = :ev, calcm = :luld, partials = [(0, 100)], prtext = :extr)
@test dsnca[:, :AUCtau] dsnca[:, :AUC_0_100] atol=1E-6

end

@testset " set-get*! tests " begin
Expand Down

2 comments on commit e14950c

@PharmCat
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/87455

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.6 -m "<description of version>" e14950cce1fc96063944fcadc4a36ff908d8dbf7
git push origin v0.5.6

Please sign in to comment.