Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #23

Merged
merged 20 commits into from
Jul 31, 2024
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 @@
* `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 @@
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 @@
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"))

Check warning on line 474 in src/plots.jl

View check run for this annotation

Codecov / codecov/patch

src/plots.jl#L472-L474

Added lines #L472 - L474 were not covered by tests
else
savefig(p[i], joinpath(savepath, namepref*"_$(i).png"))

Check warning on line 476 in src/plots.jl

View check run for this annotation

Codecov / codecov/patch

src/plots.jl#L476

Added line #L476 was not covered by tests
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
Loading