From 64e1267785dcf730f2652c986377b5fbe49f58ab Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:18:19 +0300 Subject: [PATCH 01/16] plot update (ldict) --- src/plots.jl | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/plots.jl b/src/plots.jl index 67d2f0f..9dd127e 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -115,12 +115,16 @@ end end # Text label from ID -function plotlabel(d) +function plotlabel(d, ld = nothing) title = "" if isnothing(d) return title end if length(d) > 0 for (k, v) in d - title *= "$(k) = $(v); " + kv = k + if !isnothing(ld) && haskey(ld, kv) + kv = ld[kv] + end + title *= "$(kv) = $(v); " end end return title @@ -309,7 +313,7 @@ function pageplot(data, id, ulist; kwargs...) kwargs = Dict{Symbol, Any}(kwargs) k = keys(kwargs) if !(:title in k) - kwargs[:title] = plotlabel(id) + kwargs[:title] = plotlabel(id, kwargs[:ldict]) end fst = true @@ -338,7 +342,7 @@ function pageplot(data, id, ulist; kwargs...) if num ∈ labvec kwargs[:label] = nothing else - kwargs[:label] = plotlabel(ulist[num]) + kwargs[:label] = plotlabel(ulist[num], kwargs[:ldict]) push!(labvec, num) end else @@ -370,7 +374,8 @@ PK plot for subject set. * `typesort` - sort on page by this id key; * `pagesort` - different pages by this id key; * `filter` - use only subjects if filter ⊆ subject id; -* `uylims` - same ylims for all dataset. +* `uylims` - same ylims for all dataset; +* `ldict` - Dict with labels for replace. Use `pagesort = MetidaNCA.NoPageSort()` to prevent page plotting. """ @@ -379,6 +384,7 @@ function pkplot(data::DataSet{T}; pagesort::Union{Nothing, Symbol, AbstractVector{Symbol}, NoPageSort} = nothing, filter::Union{Nothing, Dict{Symbol}} = nothing, uylims::Bool = false, + ldict = nothing, kwargs...) where T <: AbstractSubject kwargs = Dict{Symbol, Any}(kwargs) @@ -408,17 +414,16 @@ function pkplot(data::DataSet{T}; end for subj in data if printtitle - kwargs[:title] = plotlabel(subj.id) + kwargs[:title] = plotlabel(subj.id, ldict) end if !(:legend in k) kwargs[:legend] = false end - push!(p, pkplot(subj; kwargs...)) + push!(p, pkplot(subj; kwargs...)) end return p end - if !isnothing(typesort) if isa(typesort, Symbol) typesort = [typesort] end typelist = uniqueidlist(data, typesort) @@ -434,13 +439,13 @@ function pkplot(data::DataSet{T}; p = [] pagelist = uniqueidlist(data, pagesort) for id in pagelist - push!(p, pageplot(data, id, typelist; kwargs...)) + push!(p, pageplot(data, id, typelist; ldict, kwargs...)) end return p else if !(:title in k) && !isnothing(filter) kwargs[:title] = plotlabel(filter) end - return pageplot(data, nothing, typelist; kwargs...) + return pageplot(data, nothing, typelist; ldict, kwargs...) end end \ No newline at end of file From 476450a4261a3c192696e0d161c901571280404d Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:11:26 +0300 Subject: [PATCH 02/16] plotting --- Project.toml | 2 +- src/plots.jl | 24 ++++++++++++++++++++++++ test/tests.jl | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1decdfe..5e80938 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaNCA" uuid = "097c2839-c7bc-4c4b-a5f2-b4167c1b4e7c" authors = ["PharmCat "] -version = "0.5.8" +version = "0.5.9" [deps] diff --git a/src/plots.jl b/src/plots.jl index 9dd127e..e80c5b3 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -204,6 +204,10 @@ function pkplot(subj::AbstractSubject; ls = false, elim = false, xticksn = :auto end if !(:ylims in k) kwargs[:ylims] = (minimum(obs)*0.5, maximum(obs)*2.) + else + if kwargs[:ylims][1] <= 0 + kwargs[:ylims] = (minimum(obs)/b, kwargs[:ylims][2]) + end end end else @@ -288,6 +292,10 @@ function pkplot!(subj; ls = false, elim = false, xticksn = :auto, yticksn = :aut end if !(:ylims in k) kwargs[:ylims] = (minimum(obs)*0.5, maximum(obs)*2.) + else + if kwargs[:ylims][1] <= 0 + kwargs[:ylims] = (minimum(obs)/b, kwargs[:ylims][2]) + end end end else @@ -448,4 +456,20 @@ function pkplot(data::DataSet{T}; end return pageplot(data, nothing, typelist; ldict, kwargs...) end +end + + +""" + pkplot(data::DataSet{T}; kwargs...) where T <: NCAResult +""" +function pkplot(data::DataSet{T}; kwargs...) where T <: NCAResult + ds = map(x-> x.data, data) + pkplot(ds; kwargs...) +end + +""" + pkplot(data::NCAResult; kwargs...) +""" +function pkplot(data::NCAResult; kwargs...) + pkplot(data.data; kwargs...) end \ No newline at end of file diff --git a/test/tests.jl b/test/tests.jl index 44fa67f..de92056 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -84,6 +84,9 @@ include("refdicts.jl") @test_nowarn MetidaNCA.plotstyle(40) pl = MetidaNCA.pkplot(ds[2]) pl = MetidaNCA.pkplot!(ds[3]; yscale = :log10) + #Plot from NCA result DataSet + @test_nowarn MetidaNCA.pkplot(dsncafromds[1]; ylims = (0, 10), yscale = :log10, legend = false) + @test_nowarn MetidaNCA.pkplot(dsncafromds; typesort = :Subject, pagesort = :Formulation, elim = true, ls = true, title = "Plots") # Unknown typesort @test_nowarn pl = MetidaNCA.pkplot(ds; typesort = :unknown) From 92eec22801d19184d710fe15fbfd2c17c170b8e1 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Sun, 24 Mar 2024 19:07:29 +0300 Subject: [PATCH 03/16] docs pkg --- Project.toml | 2 +- docs/Project.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 5e80938..debeb3e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaNCA" uuid = "097c2839-c7bc-4c4b-a5f2-b4167c1b4e7c" authors = ["PharmCat "] -version = "0.5.9" +version = "0.5.10" [deps] diff --git a/docs/Project.toml b/docs/Project.toml index 8d27f9a..6e76203 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -10,11 +10,11 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" [compat] -Documenter = "≥0.25" +Documenter = "1" MetidaNCA = "0.5" CSV = "0.8, 0.9, 0.10" DataFrames = "1" PrettyTables = "1, 2" Weave = "0.9, 0.10" Plots = "1" -Latexify = "0.14, 0.15" +Latexify = "0.14, 0.15, 0.16" From 34488ed4317aca03d1a077f522f9bd92dcfc4a05 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:12:23 +0300 Subject: [PATCH 04/16] docs, minor fix --- docs/src/details.md | 10 ++++++++++ src/import.jl | 3 +++ src/nca.jl | 13 ++++++++----- src/plots.jl | 25 ++++++++++++------------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/docs/src/details.md b/docs/src/details.md index a2ef253..f468f29 100644 --- a/docs/src/details.md +++ b/docs/src/details.md @@ -1,5 +1,15 @@ # Details +## Using LimitRule + +```julia +ll = LimitRule(;lloq = 0.1, btmax = 0.0, atmax = NaN, nan = NaN, rm = true) + +``` + +It means that all values below `lloq` will be replaced by `btmax` before Tmax and replaced by `atmax` after Tmax; `NaN` values will be replaced by `nan`. If `rm` is `true`, all `NaN` values will be deleted. + + ## Calculation steps for PK NCA ### Step 1 diff --git a/src/import.jl b/src/import.jl index 1d116c7..dc7af1c 100644 --- a/src/import.jl +++ b/src/import.jl @@ -103,6 +103,8 @@ keywords: If time column have non-unique values - last pair time-concentration will be used. + +See also: [`ElimRange`](@ref), [`DoseTime`](@ref), [`LimitRule`](@ref). """ function pkimport(data, time, conc, sort; kelauto = true, elimrange = ElimRange(), dosetime = nothing, limitrule::Union{Nothing, LimitRule} = nothing, warn = true, kwargs...) if isa(sort, String) sort = [Symbol(sort)] end @@ -181,6 +183,7 @@ end kwargs...) Import PK data from time vector `time` and concentration vector `conc`. + """ function pkimport(time, conc; kelauto = true, elimrange = ElimRange(), dosetime = nothing, id = Dict{Symbol, Any}(), limitrule::Union{Nothing, LimitRule} = nothing, warn = true, kwargs...) timevals_sp, concvals_sp = checkvalues(time, conc, warn = warn) diff --git a/src/nca.jl b/src/nca.jl index 6d2695c..8136eaf 100644 --- a/src/nca.jl +++ b/src/nca.jl @@ -392,6 +392,8 @@ Import data and perform NCA analysis. Syntax simillar to [`pkimport`](@ref) Applicable `kwargs` see [`nca!`](@ref). + +See also: [`ElimRange`](@ref), [`DoseTime`](@ref), [`LimitRule`](@ref). """ function nca(args...; type::Symbol = :bps, bl = 0, th = 0, kelauto = true, elimrange = ElimRange(), dosetime = DoseTime(), limitrule::Union{Nothing, LimitRule} = nothing, kwargs...) if !(type in (:bps, :ur, :pd)) error("Unknown type") end @@ -411,11 +413,12 @@ end Non-compartmental (NCA) analysis of PK/PD data. """ 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]; kwargs...) - end - DataSet(result) + #result = Vector{NCAResult{Subj}}(undef, length(data)) + #for i = 1:length(data) + # result[i] = nca!(data[i]; kwargs...) + #end + #DataSet(result) + map(x -> nca!(x; kwargs...), data) end """ diff --git a/src/plots.jl b/src/plots.jl index e80c5b3..57532ca 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -393,6 +393,7 @@ function pkplot(data::DataSet{T}; filter::Union{Nothing, Dict{Symbol}} = nothing, uylims::Bool = false, ldict = nothing, + savepng = nothing, kwargs...) where T <: AbstractSubject kwargs = Dict{Symbol, Any}(kwargs) @@ -414,6 +415,16 @@ function pkplot(data::DataSet{T}; end if !isnothing(filter) data = subset(data, filter) end + if !isnothing(typesort) + if isa(typesort, Symbol) typesort = [typesort] end + typelist = uniqueidlist(data, typesort) + else + typelist = nothing + if !(:legend in k) + kwargs[:legend] = false + end + end + if isnothing(typesort) && isnothing(pagesort) p = [] printtitle = false @@ -430,19 +441,7 @@ function pkplot(data::DataSet{T}; push!(p, pkplot(subj; kwargs...)) end return p - end - - if !isnothing(typesort) - if isa(typesort, Symbol) typesort = [typesort] end - typelist = uniqueidlist(data, typesort) - else - typelist = nothing - if !(:legend in k) - kwargs[:legend] = false - end - end - - if !isnothing(pagesort) && !isa(pagesort, NoPageSort) + elseif !isnothing(pagesort) && !isa(pagesort, NoPageSort) if isa(pagesort, Symbol) pagesort = [pagesort] end p = [] pagelist = uniqueidlist(data, pagesort) From d550a921cbdbf2a7a178b1fef4f44777128f5cc4 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:02:15 +0300 Subject: [PATCH 05/16] docs --- docs/src/details.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/details.md b/docs/src/details.md index f468f29..971ef50 100644 --- a/docs/src/details.md +++ b/docs/src/details.md @@ -9,6 +9,8 @@ ll = LimitRule(;lloq = 0.1, btmax = 0.0, atmax = NaN, nan = NaN, rm = true) It means that all values below `lloq` will be replaced by `btmax` before Tmax and replaced by `atmax` after Tmax; `NaN` values will be replaced by `nan`. If `rm` is `true`, all `NaN` values will be deleted. +See also: [`applylimitrule!`](@ref). + ## Calculation steps for PK NCA From 9b9b3842f37413a07c8447afc3f4b217f9608a87 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:21:17 +0300 Subject: [PATCH 06/16] show ds --- src/show.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/show.jl b/src/show.jl index 5e1e529..041e95f 100644 --- a/src/show.jl +++ b/src/show.jl @@ -71,7 +71,8 @@ end function Base.show(io::IO, obj::DataSet{ST}) where ST <: AbstractSubject println(io, "DataSet: $(subject_type_str(ST))") println(io, "Length: $(length(obj))") - for i = 1:length(obj) + lo = min(length(obj), 20) + for i = 1:lo print(io, "Subject $(i): ") if length(obj[i].id) > 0 for (k, v) in obj[i].id @@ -82,6 +83,9 @@ function Base.show(io::IO, obj::DataSet{ST}) where ST <: AbstractSubject println(io, "-") end end + if lo < length(obj) + printstyled(io, "$(length(obj) - lo) subjects omitted... \n"; color = :blue) + end end function Base.show(io::IO, obj::T) where T <: NCAResult From 3eeb5786b6867a82f4874831bfc483e353c029fe Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:22:44 +0300 Subject: [PATCH 07/16] show res ds --- src/show.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/show.jl b/src/show.jl index 041e95f..76e1149 100644 --- a/src/show.jl +++ b/src/show.jl @@ -96,7 +96,8 @@ end function Base.show(io::IO, obj::DataSet{Res}) where Res <: NCAResult println(io, "DataSet: PK/PD NCA result") println(io, "Length: $(length(obj))") - for i = 1:length(obj) + lo = min(length(obj), 20) + for i = 1:lo print(io, "Subject $(i): ") if length(obj[i].data.id) > 0 for (k, v) in obj[i].data.id @@ -107,4 +108,7 @@ function Base.show(io::IO, obj::DataSet{Res}) where Res <: NCAResult println(io, "-") end end + if lo < length(obj) + printstyled(io, "$(length(obj) - lo) subjects omitted... \n"; color = :blue) + end end From b431c351d5aab087db2e9676f90c9b32d618ccb2 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:46:12 +0300 Subject: [PATCH 08/16] save plots --- src/MetidaNCA.jl | 8 ++++++++ src/plots.jl | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/MetidaNCA.jl b/src/MetidaNCA.jl index ac0be3b..c54cb43 100644 --- a/src/MetidaNCA.jl +++ b/src/MetidaNCA.jl @@ -22,6 +22,8 @@ uniqueidlist, indsdict!, subset +using MetidaBase.Requires + export pkimport, upkimport, pdimport, nca!, nca, DoseTime, ElimRange, LimitRule, NoPageSort, auc_sparse, setdosetime!, setkelauto!, setkelrange!, applylimitrule!, setbl!, setth!, @@ -29,6 +31,12 @@ pkplot, getkeldata, getkelauto, getkelrange, getdosetime, getbl, getth, subset metida_table +function __init__() + @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin + import Plots:savefig + end +end + const LOG2 = log(2) include("types.jl") diff --git a/src/plots.jl b/src/plots.jl index 57532ca..8bd09a8 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -375,6 +375,9 @@ end pagesort::Union{Nothing, Symbol, AbstractVector{Symbol}, NoPageSort} = nothing, filter::Union{Nothing, Dict{Symbol}} = nothing, uylims::Bool = false, + ldict = nothing, + savepath::Union{Nothing, AbstractString} = nothing, + namepref::Union{Nothing, AbstractString} = nothing, kwargs...) where T <: AbstractSubject PK plot for subject set. @@ -383,7 +386,9 @@ PK plot for subject set. * `pagesort` - different pages by this id key; * `filter` - use only subjects if filter ⊆ subject id; * `uylims` - same ylims for all dataset; -* `ldict` - Dict with labels for replace. +* `ldict` - Dict with labels for replace; +* `savepath` - path for plot saving; +* `namepref` - name prefix for saving files. Use `pagesort = MetidaNCA.NoPageSort()` to prevent page plotting. """ @@ -393,7 +398,8 @@ function pkplot(data::DataSet{T}; filter::Union{Nothing, Dict{Symbol}} = nothing, uylims::Bool = false, ldict = nothing, - savepng = nothing, + savepath::Union{Nothing, AbstractString} = nothing, + namepref::Union{Nothing, AbstractString} = nothing, kwargs...) where T <: AbstractSubject kwargs = Dict{Symbol, Any}(kwargs) @@ -424,9 +430,8 @@ function pkplot(data::DataSet{T}; kwargs[:legend] = false end end - + p = [] if isnothing(typesort) && isnothing(pagesort) - p = [] printtitle = false if !(:title in k) printtitle = true @@ -440,20 +445,38 @@ function pkplot(data::DataSet{T}; end push!(p, pkplot(subj; kwargs...)) end - return p elseif !isnothing(pagesort) && !isa(pagesort, NoPageSort) if isa(pagesort, Symbol) pagesort = [pagesort] end - p = [] pagelist = uniqueidlist(data, pagesort) for id in pagelist push!(p, pageplot(data, id, typelist; ldict, kwargs...)) end - return p else if !(:title in k) && !isnothing(filter) kwargs[:title] = plotlabel(filter) end - return pageplot(data, nothing, typelist; ldict, kwargs...) + push!(p,pageplot(data, nothing, typelist; ldict, kwargs...)) + end + + if !isnothing(savepath) + if @isdefined savefig + if isfile(savepath) + error("File found on this path...") + elseif !isdir(savepath) + mkpath(savepath) + end + if isnothing(namepref) namepref = "plot" end + for i = 1: length(p) + savefig(p[i], joinpath(savepath, namepref*"_$(i).png")) + end + else + @warn "savefig not defined, install Plots.jl for plot writing... plots NOT saved..." + end + end + if length(p) > 1 + return p + else + return p[1] end end From bab326ca70db8cdaea56085e4c144b3531194f62 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:49:07 +0300 Subject: [PATCH 09/16] version bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f19f97b..1793bae 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaNCA" uuid = "097c2839-c7bc-4c4b-a5f2-b4167c1b4e7c" authors = ["PharmCat "] -version = "0.5.10" +version = "0.5.11" From 4b907c5a54725d8a977e6835e7e3566c1c7abf0b Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:38:00 +0300 Subject: [PATCH 10/16] update --- .github/workflows/Documenter.yml | 2 +- .github/workflows/Tier1.yml | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index 316c92a..e02cfcd 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-22.04 timeout-minutes: 40 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Update run: sudo apt-get update - name: Install Pandoc diff --git a/.github/workflows/Tier1.yml b/.github/workflows/Tier1.yml index 34b583b..bc87bc7 100644 --- a/.github/workflows/Tier1.yml +++ b/.github/workflows/Tier1.yml @@ -36,15 +36,26 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v3 - - uses: julia-actions/setup-julia@v1 + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v1 + - uses: actions/cache@v4 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 + if: ${{ matrix.os == 'ubuntu-latest' && matrix.version == '1' && matrix.arch == 'x64' }} with: - files: lcov.info + file: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} From d193ccdb1b9a09f0f6b4841cc036e54d4f2dcd84 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:09:47 +0300 Subject: [PATCH 11/16] update --- .github/workflows/Tier1.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Tier1.yml b/.github/workflows/Tier1.yml index bc87bc7..ed70fa4 100644 --- a/.github/workflows/Tier1.yml +++ b/.github/workflows/Tier1.yml @@ -28,7 +28,7 @@ jobs: version: - '1.6' - '1.8' - - '1.9' + - '1' os: - ubuntu-latest - macOS-latest From bc1e5c3eb7dcdf75c5c24147b6626bae24479385 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:19:32 +0300 Subject: [PATCH 12/16] update --- Project.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Project.toml b/Project.toml index 1793bae..eb2fdca 100644 --- a/Project.toml +++ b/Project.toml @@ -9,11 +9,13 @@ version = "0.5.11" MetidaBase = "075456b7-4006-432f-9324-2f8453996c49" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" [compat] MetidaBase = "0.11.2, 0.11.3, 0.12" RecipesBase = "1" +Requires = "1" julia = "1" [extras] From 7128452ed612445da55592de0ea2780711ebf3a7 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:01:29 +0300 Subject: [PATCH 13/16] docs, plot output --- Project.toml | 2 +- docs/src/api.md | 13 +++++++++++++ docs/src/details.md | 24 ++++++++++++++++++++++++ docs/src/examples.md | 18 +++++++++++++++++- src/nca.jl | 2 +- src/plots.jl | 2 +- src/types.jl | 28 ++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 4 deletions(-) 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..cf2574e 100644 --- a/docs/src/details.md +++ b/docs/src/details.md @@ -12,6 +12,30 @@ 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..b4fab8b 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 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..a107418 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -450,7 +450,7 @@ 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) 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 From c37bfbb696ca6b0685ba0a52947060e8a34a859f Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:18:23 +0300 Subject: [PATCH 14/16] fix plots --- src/MetidaNCA.jl | 2 +- src/plots.jl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MetidaNCA.jl b/src/MetidaNCA.jl index c54cb43..aad1d75 100644 --- a/src/MetidaNCA.jl +++ b/src/MetidaNCA.jl @@ -33,7 +33,7 @@ metida_table function __init__() @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin - import Plots:savefig + savefig = Plots.savefig end end diff --git a/src/plots.jl b/src/plots.jl index a107418..f940e92 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -456,7 +456,7 @@ function pkplot(data::DataSet{T}; 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 +467,8 @@ 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) + savefig(p[i][2], joinpath(savepath, namepref*"_$(i).png")) end else @warn "savefig not defined, install Plots.jl for plot writing... plots NOT saved..." From c5951ad4560fb4d83dc744c96e208677fcafc4b7 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:50:34 +0300 Subject: [PATCH 15/16] export, fix docs --- docs/src/examples.md | 4 ++-- src/MetidaNCA.jl | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/src/examples.md b/docs/src/examples.md index b4fab8b..c147bdc 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -76,11 +76,11 @@ png(p, "plot2.png") p = pkplot(ds; elim = true, ls = true) -png(p[1], "plot3.png") +png(p[1][2], "plot3.png") 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 aad1d75..f46db2a 100644 --- a/src/MetidaNCA.jl +++ b/src/MetidaNCA.jl @@ -28,8 +28,9 @@ 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 From 47a06b14b09010bae435dfceec3891bc4b2dd909 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Wed, 31 Jul 2024 20:20:09 +0300 Subject: [PATCH 16/16] fix plots --- docs/src/examples.md | 4 +++- src/plots.jl | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/src/examples.md b/docs/src/examples.md index c147bdc..cbc5c73 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -76,7 +76,9 @@ png(p, "plot2.png") p = pkplot(ds; elim = true, ls = true) -png(p[1][2], "plot3.png") +png(p[1], "plot3.png") + +# If pagesort used - return pairs with `Page ID` => `Plot` p = pkplot(ds; typesort = :Subject, pagesort = :Formulation) diff --git a/src/plots.jl b/src/plots.jl index f940e92..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, @@ -468,7 +470,11 @@ function pkplot(data::DataSet{T}; end if isnothing(namepref) namepref = "plot" end for i = 1:length(p) - savefig(p[i][2], joinpath(savepath, namepref*"_$(i).png")) + 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..."