diff --git a/Project.toml b/Project.toml index eb2fdca..8824855 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaNCA" uuid = "097c2839-c7bc-4c4b-a5f2-b4167c1b4e7c" authors = ["PharmCat "] -version = "0.5.11" +version = "0.5.12" diff --git a/docs/src/api.md b/docs/src/api.md index 0753958..f461331 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -52,6 +52,19 @@ MetidaNCA.ElimRange MetidaNCA.LimitRule ``` +### MetidaNCA.PKSubject + +```@docs +MetidaNCA.PKSubject +``` + +### MetidaNCA.NCAResult + +```@docs +MetidaNCA.NCAResult +``` + + ## Functions ### applylimitrule! diff --git a/docs/src/details.md b/docs/src/details.md index d44b223..36efb9d 100644 --- a/docs/src/details.md +++ b/docs/src/details.md @@ -12,6 +12,31 @@ It means that all values below `lloq` will be replaced by `btmax` before Tmax an See also: [`applylimitrule!`](@ref). +## Using DoseTime + +```julia + +dt = DoseTime(dose = 200.0, time = 0.0) + +``` + +DoseTime can be appliet to each subject or dataset and can be used with [`pkimport`](@ref). + + +```julia + +ds = pkimport(pkdata2, :Time, :Concentration, [:Subject, :Formulation]; dosetime = dt) + +``` + +DoseTime for staedy-state PK: + +```julia +dt = DoseTime(dose = 100.0, time = 0.25, tau = 9.0) +``` + +See also: [`setdosetime!`](@ref). + ## Calculation steps for PK NCA diff --git a/docs/src/examples.md b/docs/src/examples.md index 77a1acd..cbc5c73 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -29,7 +29,7 @@ dsnca = nca!(ds, adm = :ev, calcm = :lint) dsnca[:, :AUClast] ``` -# Partial AUC +## Partial AUC ```@example ncaexample dsnca = nca!(ds, adm = :ev, calcm = :lint, partials = [(1, 7)]) @@ -37,6 +37,22 @@ dsnca = nca!(ds, adm = :ev, calcm = :lint, partials = [(1, 7)]) dsnca[:, :AUC_1_7] ``` +## Result modification or custom parameter function + +```@example ncaexample + +# Define modify! function for new parameter +function newparam(data) + data.result[:AUChalf] = data.result[:AUClast] / 2 +end + +dsncanp = nca!(ds, modify! = newparam) + +dsncanp[1][:AUChalf] +``` + +Function `newparam` applyed to [`NCAResult`](@ref). + ## Print output @@ -62,9 +78,11 @@ p = pkplot(ds; elim = true, ls = true) png(p[1], "plot3.png") +# If pagesort used - return pairs with `Page ID` => `Plot` + p = pkplot(ds; typesort = :Subject, pagesort = :Formulation) -png(p[1], "plot4.png") +png(p[1][2], "plot4.png") ``` #### Plot 1 diff --git a/src/MetidaNCA.jl b/src/MetidaNCA.jl index c54cb43..f46db2a 100644 --- a/src/MetidaNCA.jl +++ b/src/MetidaNCA.jl @@ -28,12 +28,13 @@ export pkimport, upkimport, pdimport, nca!, nca, DoseTime, ElimRange, LimitRule, auc_sparse, setdosetime!, setkelauto!, setkelrange!, applylimitrule!, setbl!, setth!, pkplot, -getkeldata, getkelauto, getkelrange, getdosetime, getbl, getth, subset -metida_table +getkeldata, getkelauto, getkelrange, getdosetime, getbl, getth, subset, +metida_table, +PKSubject, UPKSubject, PDSubject, NCAResult function __init__() @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin - import Plots:savefig + savefig = Plots.savefig end end diff --git a/src/nca.jl b/src/nca.jl index 8136eaf..6db3652 100644 --- a/src/nca.jl +++ b/src/nca.jl @@ -442,7 +442,7 @@ end * `verbose` - print to `io`, 1: partial areas table, 2: 1, and results; * `warn` - show warnings; * `io` - output stream; -* `modify!` - function to modify output paramaters, call `modify!(data, result)` if difined. +* `modify!` - function to modify output paramaters, call `modify!(ncaresult)` if difined. Results: diff --git a/src/plots.jl b/src/plots.jl index 9106efa..a262582 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -391,6 +391,8 @@ PK plot for subject set. * `namepref` - name prefix for saving files. Use `pagesort = MetidaNCA.NoPageSort()` to prevent page plotting. + +If pagesort used - return vector of pairs: `Page ID` => `Plot` """ function pkplot(data::DataSet{T}; typesort::Union{Nothing, Symbol, AbstractVector{Symbol}} = nothing, @@ -450,13 +452,13 @@ function pkplot(data::DataSet{T}; if isa(pagesort, Symbol) pagesort = [pagesort] end pagelist = uniqueidlist(data, pagesort) for id in pagelist - push!(p, pageplot(data, id, typelist; ldict, kwargs...)) + push!(p, id => pageplot(data, id, typelist; ldict, kwargs...)) end else if !(:title in k) && !isnothing(filter) kwargs[:title] = plotlabel(filter) end - push!(p,pageplot(data, nothing, typelist; ldict, kwargs...)) + push!(p, pageplot(data, nothing, typelist; ldict, kwargs...)) end if !isnothing(savepath) @@ -467,8 +469,12 @@ function pkplot(data::DataSet{T}; mkpath(savepath) end if isnothing(namepref) namepref = "plot" end - for i = 1: length(p) - savefig(p[i], joinpath(savepath, namepref*"_$(i).png")) + for i = 1:length(p) + if isa(p[i], Pair) + savefig(p[i][2], joinpath(savepath, namepref*"_$(i).png")) + else + savefig(p[i], joinpath(savepath, namepref*"_$(i).png")) + end end else @warn "savefig not defined, install Plots.jl for plot writing... plots NOT saved..." diff --git a/src/types.jl b/src/types.jl index 2732f33..32c02ea 100644 --- a/src/types.jl +++ b/src/types.jl @@ -105,6 +105,22 @@ struct DoseTime{D <: Number, T <: Number, TAU <: Number} end # PK subject +""" + PKSubject(time::Vector{T}, conc::Vector{O}, kelauto::Bool, kelrange::ElimRange, dosetime::DoseTime, keldata::KelData, sort::Dict{Symbol, V} = Dict{Symbol, Any}()) where T <: Number where O <: Union{Number, Missing} where V + +Pharmacokinetic subject. + +Fields: + +* time::Vector{T} - time values; +* obs::Vector{O} - observations; +* kelauto::Bool +* kelrange::ElimRange +* dosetime::DoseTime +* keldata::KelData +* id::Dict{Symbol, V} + +""" mutable struct PKSubject{T <: Number, O <: Union{Number, Missing}, V <: Any} <: AbstractSubject time::Vector{T} obs::Vector{O} @@ -136,7 +152,17 @@ function Base.length(obj::T) where T <: AbstractSubject length(obj.time) end +""" + NCAResult(subject::T, options, result::Dict{Symbol, U}) where T <: AbstractSubject where U + +NCA resulst. + +Fields: +* data::T +* options::Dict{Symbol} +* result::Dict{Symbol, U} +""" struct NCAResult{T, U} <: AbstractSubjectResult{T} data::T options::Dict{Symbol} @@ -167,6 +193,8 @@ Rule for PK subject. * STEP 1 (NaN step): replace all `NaN` and `missing` values with nan keyword value (if `nan` not NaN); * STEP 2 (LLOQ step): replace values below `lloq` with `btmax` value if this value befor Tmax or with atmax if this value after Tmax (if `lloq` not NaN); * STEP 3 (remove NaN): `rm` == true, then remove all `NaN` and `missing` values. + +See also: [`applylimitrule!`](@ref) """ struct LimitRule{T<:Real} lloq::T