Skip to content

Commit

Permalink
bugfix AUCtau whet dosetime != 0
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jun 29, 2021
1 parent 43ece0d commit c4864e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions change.log
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
v0.6.1
- bugfix in AUMCtau when dosetime != 0
- fix ⊆ for Dict
- fix setelimrange!(data::DataSet{PKSubject}, range::ElimRange, sort::Dict)
- fix start kel value in output
- dropbeforedosetime - drop NanN
- nca!(data::DataSet{PKSubject}) - sort keyword
- pk optimization
- pk output changes
- pkplots changes and fixes
- fix log-scale plots
- other minor fixes
Expand Down
27 changes: 16 additions & 11 deletions src/pk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,23 +447,23 @@ end
return auc, aumc
end
=#
function aucpart(t₁, t₂, c₁::T1, c₂::T2, calcm, aftertmax) where T1 where T2
function aucpart(t₁, t₂, c₁::T1, c₂::T2, calcm, aftertmax, dosetime) where T1 where T2

if calcm == :lint
auc = linauc(t₁, t₂, c₁, c₂)
aumc = linaumc(t₁, t₂, c₁, c₂)
aumc = linaumc(t₁ - dosetime, t₂ - dosetime, c₁, c₂)
elseif calcm == :logt && aftertmax && c₁ > zero(T1) && c₂ > zero(T2)
auc = logauc(t₁, t₂, c₁, c₂)
aumc = logaumc(t₁, t₂, c₁, c₂)
aumc = logaumc(t₁ - dosetime, t₂ - dosetime, c₁, c₂)
elseif calcm == :luldt && aftertmax && c₁ > c₂ > zero(T2)
auc = logauc(t₁, t₂, c₁, c₂)
aumc = logaumc(t₁, t₂, c₁, c₂)
aumc = logaumc(t₁ - dosetime, t₂ - dosetime, c₁, c₂)
elseif calcm == :luld && c₁ > c₂ > zero(T2)
auc = logauc(t₁, t₂, c₁, c₂)
aumc = logaumc(t₁, t₂, c₁, c₂)
aumc = logaumc(t₁ - dosetime, t₂ - dosetime, c₁, c₂)
else
auc = linauc(t₁, t₂, c₁, c₂)
aumc = linaumc(t₁, t₂, c₁, c₂)
aumc = linaumc(t₁ - dosetime, t₂ - dosetime, c₁, c₂)
end
return auc, aumc
end
Expand Down Expand Up @@ -562,7 +562,7 @@ function nca!(data::PKSubject; adm = :ev, calcm = :lint, intp = :lint, verbose =
aumcpartl = Array{Number, 1}(undef, result[:Obsnum] - 1)
#Calculate all UAC part based on data
for i = 1:(result[:Obsnum] - 1)
aucpartl[i], aumcpartl[i] = aucpart(time[i], time[i + 1], obs[i], obs[i + 1], calcm, i + 1 > result[:Tmaxn])
aucpartl[i], aumcpartl[i] = aucpart(time[i], time[i + 1], obs[i], obs[i + 1], calcm, i + 1 > result[:Tmaxn], data.dosetime.time)
end
#pmask = Array{Bool, 1}(undef, result[:Obsnum] - 1)
#pmask .= true
Expand Down Expand Up @@ -634,7 +634,7 @@ function nca!(data::PKSubject; adm = :ev, calcm = :lint, intp = :lint, verbose =
result[:Cdose] = 0
end
end
doseaucpart, doseaumcpart = aucpart(data.dosetime.time, time[1], result[:Cdose], obs[1], :lint, false) #always :lint?
doseaucpart, doseaumcpart = aucpart(data.dosetime.time, time[1], result[:Cdose], obs[1], :lint, false, data.dosetime.time) #always :lint?
else
error("Some concentration before dose time after filtering!!!")
end
Expand Down Expand Up @@ -700,13 +700,13 @@ function nca!(data::PKSubject; adm = :ev, calcm = :lint, intp = :lint, verbose =
if tautime < time[end]
if tautime > result[:Tmax] aftertmax = true else aftertmax = false end
result[:Ctau] = cpredict(time[ncae], time[ncae + 1], tautime, obs[ncae], obs[ncae + 1], intp)
eaucpartl, eaumcpartl = aucpart(time[ncae], tautime, obs[ncae], result[:Ctau], calcm, aftertmax)
eaucpartl, eaumcpartl = aucpart(time[ncae], tautime, obs[ncae], result[:Ctau], calcm, aftertmax, data.dosetime.time)
#remoove part after tau
if ncae < result[:Obsnum] - 1 pmask[ncae:end] .= false end
elseif tautime > time[end] && result[:LZint] !== NaN
#extrapolation
result[:Ctau] = exp(result[:LZint] + result[:LZ] * tautime)
eaucpartl, eaumcpartl = aucpart(time[ncae], tautime, obs[ncae], result[:Ctau], calcm, true)
eaucpartl, eaumcpartl = aucpart(time[ncae], tautime, obs[ncae], result[:Ctau], calcm, true, data.dosetime.time)
else
result[:Ctau] = obs[end]
end
Expand Down Expand Up @@ -748,7 +748,12 @@ function nca!(data::PKSubject; adm = :ev, calcm = :lint, intp = :lint, verbose =
for i = 1:length(pmask)
if pmask[i] astx[i+1] = "Yes" else astx[i+1] = "No" end
end
mx = hcat(time, obs, round.(vcat([0], aucpartl), digits = 3), round.(vcat([0], aucpartlsum), digits = 3), round.(vcat([0], aumcpartl), digits = 3), round.(vcat([0], aumcpartlsum), digits = 3), astx)

aucpartlsum .+= doseaucpart

aumcpartlsum .+= doseaumcpart
if doseaucpart > 0 || doseaumcpart > 0 astx[1] = "D" end
mx = hcat(time, obs, round.(vcat([doseaucpart], aucpartl), digits = 3), round.(vcat([doseaucpart], aucpartlsum), digits = 3), round.(vcat([doseaumcpart], aumcpartl), digits = 3), round.(vcat([doseaumcpart], aumcpartlsum), digits = 3), astx)
mx = vcat(permutedims(["Time", "Concentrtion", "AUC", "AUC (cumulate)", "AUMC", "AUMC (cumulate)", "Include"]), mx)
printmatrix(io, mx)
println(io, "")
Expand Down
11 changes: 11 additions & 0 deletions test/pktest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,17 @@ sort!(df, :Subject)
766.620245
1219.631864
970.3062692], sigdigits = 6)
# AUMCtau
@test round.(df[!, :AUMCtau], sigdigits = 6) == round.([5477.20423544297
8367.57088170951
3455.34643479800
6014.64604481587
6609.78830163090
5064.72384740413
4976.96365993911
2863.00517022791
5386.88322025614
4713.47970846693], sigdigits = 6)
#Ctau
@test round.(df[!, :Ctau], sigdigits = 6) == round.([137.721875
204.9625055
Expand Down

2 comments on commit c4864e0

@PharmCat
Copy link
Owner

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

v0.6.1

  • bugfix in AUMCtau when dosetime != 0
  • fix ⊆ for Dict
  • fix setelimrange!(data::DataSet{PKSubject}, range::ElimRange, sort::Dict)
  • fix start kel value in output
  • dropbeforedosetime - drop NanN
  • nca!(data::DataSet{PKSubject}) - sort keyword
  • pk optimization
  • pk output changes
  • pkplots changes and fixes
  • fix log-scale plots
  • other minor fixes

@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/39909

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.6.1 -m "<description of version>" c4864e0ebb190753e7751cbbb9e2108e250e4bbc
git push origin v0.6.1

Please sign in to comment.