Skip to content

Commit

Permalink
Merge pull request #2 from yufongpeng/df.jl
Browse files Browse the repository at this point in the history
Release v0.1.0
  • Loading branch information
yufongpeng authored Apr 15, 2024
2 parents 9fd0cd5 + a147dfb commit a20ba35
Show file tree
Hide file tree
Showing 20 changed files with 1,763 additions and 867 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Manifest.toml
/test/result
16 changes: 10 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
name = "Validation"
name = "AnalyticalMethodValidation"
uuid = "b401a7b7-5953-49f1-86ca-9d186498acee"
authors = ["Yu-Fong Peng <[email protected]>"]
version = "0.2.1"
version = "0.1.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
ChemistryQuantitativeAnalysis = "3ed48883-6809-43ec-b77a-d23b0650d8c4"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataPipes = "02685ad9-2d12-40c3-9f73-c6aeda6a7ff5"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"

[compat]
CSV = "0.10"
Chain = "0.5"
ChemistryQuantitativeAnalysis = "0.7"
Dictionaries = "0.3"
DataFrames = "1.5.0"
DataPipes = "0.3"
SplitApplyCombine = "1"
TypedTables = "1"
julia = "1"

[extras]
Expand Down
66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,59 @@
# Validation
# AnalyticalMethodValidation

|CI status|Coverage|
|:-------:|:------:|
[![][ci-img]][ci-url]| [![][codecov-img]][codecov-url]|

[ci-img]: https://github.com/yufongpeng/Validation.jl/actions/workflows/CI.yml/badge.svg?branch=main
[ci-url]: https://github.com/yufongpeng/Validation.jl/actions/workflows/CI.yml?query=branch%3Amain
[codecov-img]: https://codecov.io/gh/yufongpeng/Validation.jl/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/yufongpeng/Validation.jl
[ci-img]: https://github.com/yufongpeng/AnalyticalMethodValidation.jl/actions/workflows/CI.yml/badge.svg?branch=main
[ci-url]: https://github.com/yufongpeng/AnalyticalMethodValidation.jl/actions/workflows/CI.yml?query=branch%3Amain
[codecov-img]: https://codecov.io/gh/yufongpeng/AnalyticalMethodValidation.jl/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/yufongpeng/AnalyticalMethodValidation.jl

A small package for analyzing method validation data. It only accepts csv data from Agilent MassHunter Quantitative analysis and the table needs to be flat.
A small package for analytical method validation, and sample analysis.

For command line interfaces, see [`juliaquant`](https://github.com/yufongpeng/juliaquant).

## Function
1. `read_data`: read the data with some transformation.
2. `QCReport`: calculate accuracy and rsd of QC samples.
3. `APData`: calculate accuracy, repeatability and reproducibility.
4. `RecoveryData`: calculate recovery by prespiked/postspiked.
5. `MEData`: calculate matrix effect by with_matrix/std_solution.
6. `StabilityData`: calculate accuracy and rsd of QC samples in different tempearture and restoration days.
7. `SampleReport`: average each sample.
8. `Report`: flatten nested `Data` object for CSV output.

## Scripts
See "/scipt" for command line interfaces.
1. `read`: read csv file(s) into `AnalysisTable` (See [`ChemistryQuantitativeAnalysis.jl`](https://github.com/yufongpeng/ChemistryQuantitativeAnalysis.jl)). Currently, only data from MassHunter Software in wide format is supported.

### Report functions
These function accept `AnalysisTable` or `Batch`.
1. `qc_report`: calculate accuracy and rsd of QC samples.
2. `ap_report`: calculate accuracy, repeatability and reproducibility.
3. `recovery_report`: calculate recovery by prespiked/postspiked.
4. `me_report`: calculate matrix effect by with_matrix/std_solution.
5. `stability_report`: calculate accuracy and rsd of QC samples in different tempearture and restoration days.
6. `sample_report`: average each sample.

### Util functions
1. `pivot`: transform dataframe into wide format.
2. `unpivot`: transform dataframe into long format.
3. `selectby`: select values by specific column, and apply `select!` as if the values are columns. This function is useful to merge multiple statistical values into specific formats.
4. `mean_plus_minus_std`: round and merge mean values and standard deviations with "±".
5. `add_percentage`: add "%".
6. `normalize`: normalize dataframe by the given normalizer.
7. `qualify`: replace data out of acceptable range.
8. `qualify!`: replace data out of acceptable range.

## Computation
### Intra-day

$$\mu_{d} = \sum_{j=1}^{n_d} \dfrac{c_{d, j}}{n_d}$$
$$a_{d,j } = \dfrac{c_{d, j}}{conc.}$$

$$\mu_{d} = \sum_{j=1}^{n_d} \dfrac{a_{d, j}}{n_d}$$

$$s_{intra}^2 = \dfrac{1}{p}\sum_{i = 1}^{p}\sum_{j = 1}^{n_i} \dfrac{(c_{i, j} - \mu_i)^2}{n_i - 1}$$
$$s_{intra}^2 = \dfrac{1}{p}\sum_{i = 1}^{p}\sum_{j = 1}^{n_i} \dfrac{(a_{i, j} - \mu_i)^2}{n_i - 1}$$

$$accuracy_{intra, d} = \dfrac{\mu_{d}}{conc.}$$
$$accuracy_{intra, d} = \mu_{d}$$

$$rsd_{intra, d} = \dfrac{s_{intra}}{accuracy_{intra, d}}$$

$p$: number of days, $n_i$: number of repeats of $i$ th day, $c_{i, j}$: measured concentration of $i$ th day and $j$ th repeat, $conc.$: reference concentration
### Inter-day
$$\mu = \dfrac{1}{p}\sum_{i = 1}^{p}\sum_{j = 1}^{n_i} \dfrac{c_{i, j}}{n_i}$$

$$accuracy_{inter} = \sum_{i = 1}^{p} \dfrac{accuracy_{intra, i}}{p} = \dfrac{\mu}{conc.}$$
$$\mu = \dfrac{1}{p}\sum_{i = 1}^{p}\sum_{j = 1}^{n_i} \dfrac{a_{i, j}}{n_i}$$

$$accuracy_{inter} = \sum_{i = 1}^{p} \dfrac{accuracy_{intra, i}}{p} = \mu$$

$$repeatability = rsd_{intra} = \dfrac{s_{intra}}{accuracy_{inter}}$$

Expand All @@ -49,4 +63,10 @@ $$s_{inter}^2 = max\ \{0, s_{between}^2 - \dfrac{s_{intra}^2}{\hat{n}}\ \}$$

$$\hat{n}=\dfrac{p}{\sum_{i=1}^p\dfrac{1}{n_i}}$$

$$reproducibility = rsd_{total} = \dfrac{\sqrt{s_{inter}^2+s_{intra}^2}}{accuracy_{inter}}$$
$$reproducibility = rsd_{total} = \dfrac{\sqrt{s_{inter}^2+s_{intra}^2}}{accuracy_{inter}}$$

## Reference
[Guidelines and Recommendations of the GTFCh](https://www.gtfch.org/cms/index.php/en/guidelines)

[Appendix B - Requirements for the validation of analytical methods](https://www.gtfch.org/cms/images/stories/files/Appendix%20B%20GTFCh%2020090601.pdf)
p.21~p.22
78 changes: 0 additions & 78 deletions script/ap_main.jl

This file was deleted.

72 changes: 0 additions & 72 deletions script/me_main.jl

This file was deleted.

60 changes: 0 additions & 60 deletions script/qc_main.jl

This file was deleted.

Loading

2 comments on commit a20ba35

@yufongpeng
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/104913

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.1.0 -m "<description of version>" a20ba3566288473010655dab47837a30e575362d
git push origin v0.1.0

Please sign in to comment.