Skip to content

Commit

Permalink
Merge pull request #28 from PharmCat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
PharmCat authored Jan 17, 2025
2 parents fa39745 + 55736fc commit 70d86f7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
4 changes: 2 additions & 2 deletions 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.15"
version = "0.5.16"



Expand All @@ -13,7 +13,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]

MetidaBase = "0.11.2, 0.11.3, 0.12, 0.13, 0.14"
MetidaBase = "0.14"
RecipesBase = "1"
Requires = "1"
julia = "1"
Expand Down
41 changes: 35 additions & 6 deletions src/nca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ 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...)
function nca(args...; type::Symbol = :bps, bl = 0, th = 0, kelauto = true, elimrange = ElimRange(), dosetime = DoseTime(), limitrule::Union{Nothing, LimitRule} = nothing, io = stdout, wm = false, kwargs...)
if !(type in (:bps, :ur, :pd)) error("Unknown type") end
if type == :bps
pki = pkimport(args...; kelauto = kelauto, elimrange = elimrange, dosetime = dosetime, limitrule = limitrule, kwargs...)
Expand All @@ -404,21 +404,40 @@ function nca(args...; type::Symbol = :bps, bl = 0, th = 0, kelauto = true, elim
elseif type == :pd
pki = pdimport(args...; th = th, bl = bl, limitrule = limitrule, kwargs...)
end
nca!(pki; kwargs...)
nca!(pki; io = io, wm = wm, kwargs...)
end

"""
nca!(data::DataSet{Subj}; adm = :ev, calcm = :lint, intpm = nothing, verbose = 0, warn = true, io::IO = stdout, modify! = identity) where Subj <: AbstractSubject
nca!(data::DataSet{Subj}; adm = :ev, calcm = :lint, intpm = nothing, verbose = 0, warn = true, wm::Bool = false, io::IO = stdout, modify! = identity) where Subj <: AbstractSubject
* `wm` - write output to DataSet metadata (`:ncalog` index).
Non-compartmental (NCA) analysis of PK/PD data.
"""
function nca!(data::DataSet{Subj}; kwargs...) where Subj <: AbstractSubject
function nca!(data::DataSet{Subj}; wm::Bool = false, io = stdout, 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)
map(x -> nca!(x; kwargs...), data)
writetostdout = false
if wm
if io == stdout
io = IOBuffer()
writetostdout = true
end
end

ds = map(x -> nca!(x; io = io, kwargs...), data)

if wm
io2 = deepcopy(io)
ds.metadata[:ncalog] = String(take!(io2))
if writetostdout
write(stdout, String(take!(io)))
end
end
ds
end

"""
Expand Down Expand Up @@ -494,7 +513,17 @@ Steady-state parameters (tau used):
`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, prtext = :err, 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,
kwargs...) where T where O


ptype = promote_type(Float64, T, O)

Expand Down
5 changes: 4 additions & 1 deletion test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ end


@testset " Partials " begin

io = IOBuffer()
ds = MetidaNCA.pkimport(pkdata2, :Time, :Concentration, [:Subject, :Formulation]; dosetime = MetidaNCA.DoseTime(dose = 100, time = 0.25, tau = 9))
sort!(ds, :Subject)
dsnca = MetidaNCA.nca!(ds, adm = :ev, calcm = :luld, partials = [(0.25, 9.25)])
Expand Down Expand Up @@ -1758,6 +1758,9 @@ end
@test_nowarn show(io, pd_res)
@test_nowarn show(io, pd_rds)

io = IOBuffer();
pd_rds = MetidaNCA.nca!(pd; calcm = :luldt, verbose = 2, io = io, wm = true)
@test pd_rds.metadata[:ncalog] == String(take!(io))
end


Expand Down

2 comments on commit 70d86f7

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

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.16 -m "<description of version>" 70d86f7c4b5a7c088bb16b96829c659da9b76b22
git push origin v0.5.16

Please sign in to comment.