NAME
tabulate-drug-concentration - Tabulate drug concentration over time, with one or more dosages of a drug of specified half-life
VERSION
This document describes version 0.001 of tabulate-drug-concentration (from Perl distribution App-DrugUtils), released on 2023-10-19.
SYNOPSIS
tabulate-drug-concentration --help (or -h, -?)
tabulate-drug-concentration --version (or -v)
tabulate-drug-concentration [(--dosages=str)+|--dosages-json=json|(-d=str)+] [--format=name|--json] [--half-life=ufloat|-H=ufloat] [--(no)naked-res] [--page-result[=program]|--view-result[=program]] [--period=uint|-p=uint] [--regular-dosage=str|-r=str]
See examples in the "EXAMPLES" section.
DESCRIPTION
Drug concentration over time is calculated using a simple equation:
D(t) = D(0) * exp(-t/T)
where T is a constant and can be calculated from half-life where D(t)/D(0) = 0.5:
0.5 = 1 * exp(-half_life / T)
log(0.5) = -half_life / T
T = half_life / log(0.5)
When given multiple dosages, each dosage's concentration will be added up.
By default, hourly concentration will be calculated for 10 half-lives.
OPTIONS
*
marks required options.
Main options
- --dosages-json=s, -d
-
Dosages, each of which in the form of d@t (amount followed by comma and time in hour) (JSON-encoded).
See
--dosages
. - --dosages=s@
-
Dosages, each of which in the form of d@t (amount followed by comma and time in hour).
Can be specified multiple times.
- --half-life=s*, -H
-
Drug half life, in hours.
- --period=s, -p
-
How many hours to tabulate.
If unspecified, defaults to 10 * half-life.
- --regular-dosage=s, -r
-
Regular dosage, in the form of d@t (amount followed by at sign and period in hour, meaning dosage given every t hours).
Output options
- --format=s
-
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is chosen depending on the application and/or whether output destination is interactive terminal (i.e. whether output is piped). This option specifically chooses an output format.
- --json
-
Set output format to json.
- --naked-res
-
When outputing as JSON, strip result envelope.
Default value:
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use
--naked-res
so you just get:[1,2,3]
- --page-result
-
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program is not specified, a suitable default e.g.
less
is chosen. - --view-result
-
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer program to view the temporary file. If a viewer program is not chosen, a suitable default, e.g. the browser, is chosen.
Other options
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C tabulate-drug-concentration tabulate-drug-concentration
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
tcsh
To activate tcsh completion for this script, put:
complete tabulate-drug-concentration 'p/*/`tabulate-drug-concentration`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
other shells
For fish and zsh, install shcompgen as described above.
EXAMPLES
Tabulate concentration of tadalafil (half-life 17.5h) over 1 week period if we give 2.5mg each day for a week
% tabulate-drug-concentration -H 17.5 -p 144 -d 2.5@0 -d2.5@24 -d2.5@48 -d2.5@72 -d2.5@96 -d2.5@120 -d 2.5@144
+------+---------------+
| time | concentration |
+------+---------------+
| 0 | 2.500 |
| 1 | 2.403 |
| 2 | 2.310 |
| 3 | 2.220 |
| 4 | 2.134 |
| 5 | 2.051 |
| 6 | 1.971 |
| 7 | 1.895 |
| 8 | 1.821 |
| 9 | 1.750 |
| 10 | 1.682 |
| 11 | 1.617 |
| 12 | 1.554 |
| 13 | 1.494 |
| 14 | 1.436 |
| 15 | 1.380 |
| 16 | 1.327 |
| 17 | 1.275 |
| 18 | 1.225 |
| 19 | 1.178 |
| 20 | 1.132 |
| 21 | 1.088 |
| 22 | 1.046 |
| 23 | 1.005 |
| 24 | 3.466 |
| 25 | 3.332 |
| 26 | 3.202 |
| 27 | 3.078 |
| 28 | 2.958 |
| 29 | 2.844 |
| 30 | 2.733 |
| 31 | 2.627 |
| 32 | 2.525 |
| 33 | 2.427 |
| 34 | 2.333 |
| 35 | 2.242 |
| 36 | 2.155 |
| 37 | 2.071 |
| 38 | 1.991 |
| 39 | 1.914 |
| 40 | 1.839 |
| 41 | 1.768 |
| 42 | 1.699 |
| 43 | 1.633 |
| 44 | 1.570 |
| 45 | 1.509 |
| 46 | 1.450 |
| 47 | 1.394 |
| 48 | 3.840 |
| 49 | 3.691 |
| 50 | 3.547 |
| 51 | 3.410 |
| 52 | 3.277 |
| 53 | 3.150 |
| 54 | 3.028 |
| 55 | 2.910 |
| 56 | 2.797 |
| 57 | 2.688 |
| 58 | 2.584 |
| 59 | 2.484 |
| 60 | 2.387 |
| 61 | 2.294 |
| 62 | 2.205 |
| 63 | 2.120 |
| 64 | 2.037 |
| 65 | 1.958 |
| 66 | 1.882 |
| 67 | 1.809 |
| 68 | 1.739 |
| 69 | 1.671 |
| 70 | 1.606 |
| 71 | 1.544 |
| 72 | 3.984 |
| 73 | 3.829 |
| 74 | 3.681 |
| 75 | 3.538 |
| 76 | 3.400 |
| 77 | 3.268 |
| 78 | 3.141 |
| 79 | 3.019 |
| 80 | 2.902 |
| 81 | 2.789 |
| 82 | 2.681 |
| 83 | 2.577 |
| 84 | 2.477 |
| 85 | 2.381 |
| 86 | 2.288 |
| 87 | 2.199 |
| 88 | 2.114 |
| 89 | 2.032 |
| 90 | 1.953 |
| 91 | 1.877 |
| 92 | 1.804 |
| 93 | 1.734 |
| 94 | 1.667 |
| 95 | 1.602 |
| 96 | 4.040 |
| 97 | 3.883 |
| 98 | 3.732 |
| 99 | 3.587 |
| 100 | 3.448 |
| 101 | 3.314 |
| 102 | 3.185 |
| 103 | 3.062 |
| 104 | 2.943 |
| 105 | 2.828 |
| 106 | 2.719 |
| 107 | 2.613 |
| 108 | 2.512 |
| 109 | 2.414 |
| 110 | 2.320 |
| 111 | 2.230 |
| 112 | 2.144 |
| 113 | 2.060 |
| 114 | 1.980 |
| 115 | 1.903 |
| 116 | 1.830 |
| 117 | 1.758 |
| 118 | 1.690 |
| 119 | 1.625 |
| 120 | 4.061 |
| 121 | 3.904 |
| 122 | 3.752 |
| 123 | 3.606 |
| 124 | 3.466 |
| 125 | 3.332 |
| 126 | 3.202 |
| 127 | 3.078 |
| 128 | 2.958 |
| 129 | 2.844 |
| 130 | 2.733 |
| 131 | 2.627 |
| 132 | 2.525 |
| 133 | 2.427 |
| 134 | 2.333 |
| 135 | 2.242 |
| 136 | 2.155 |
| 137 | 2.071 |
| 138 | 1.991 |
| 139 | 1.914 |
| 140 | 1.839 |
| 141 | 1.768 |
| 142 | 1.699 |
| 143 | 1.633 |
| 144 | 4.070 |
+------+---------------+
Same as previous example, but uses -r
% tabulate-drug-concentration -H 17.5 -p 144 -r2.5@24
Same as previous example, but plot it (requires xyplot)
% tabulate-drug-concentration -H 17.5 -p 144 -r2.5@24 | xyplot -
What if we dose 2.5mg every 12 hours?
% tabulate-drug-concentration -H 17.5 -p 144 -r2.5@12 | xyplot -
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-DrugUtils.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-DrugUtils.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2023 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-DrugUtils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.