Skip to content

Commit

Permalink
Dev (#23)
Browse files Browse the repository at this point in the history
* plot update (ldict)

* plotting

* docs pkg

* docs, minor fix

* docs

* show ds

* show res ds

* save plots

* version bump

* update

* update

* update

* docs, plot output

* fix plots

* export, fix docs

* fix plots
  • Loading branch information
PharmCat authored Jul 31, 2024
1 parent cefff3b commit 99f30ab
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 11 deletions.
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.11"
version = "0.5.12"



Expand Down
13 changes: 13 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ MetidaNCA.ElimRange
MetidaNCA.LimitRule
```

### MetidaNCA.PKSubject

```@docs
MetidaNCA.PKSubject
```

### MetidaNCA.NCAResult

```@docs
MetidaNCA.NCAResult
```


## Functions

### applylimitrule!
Expand Down
25 changes: 25 additions & 0 deletions docs/src/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 20 additions & 2 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,30 @@ 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)])
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

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/MetidaNCA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/nca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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..."
Expand Down
28 changes: 28 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down

2 comments on commit 99f30ab

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

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.12 -m "<description of version>" 99f30abad5aeb4df2b46c7e2822fd749cd68e600
git push origin v0.5.12

Please sign in to comment.