ChemistryQuantitativeAnalysis.AnalysisMethod
— TypeAnalysisMethod{A, M <: Table, C <: AbstractDataTable, D <: Union{AbstractDataTable, Nothing}}
A type containing analytes settings, and source calibration data. A
determines analyte type.
Fields
analytetable
:M
contaning three columns.analyte
:AbstractVector{A}
, analytes in user-defined types.isd
:AbstractVector{Int}
, index of internal standard.0
means no internal standard, and-1
means the analyte itself is a internal standard.calibration
: index of analyte for calibration curve.-1
means the analyte itself is a internal standard, so it will not be put into any calibration curve.
signal
:Symbol
, data type for quantification, e.g.:area
.pointlevel
:Vector{Int}
matching each point to level. It can be empty if there is only one level inconctable
.conctable
:C <: AbstractDataTable{<: A, Int}
containing concentration data for each level. Samples must integers. One level indicates usingSingleCalibration
.signaltable
:D <: AbstractDataTable{A}
containig signal for each point. It can benothing
if signal data is unecessary.
Properties
analyte
:AbstractVector{A}
, analytes in user-defined types, identical toanalytetable.analyte
.isd
:AbstractVector{A}
, analytes which are internal standards.nonisd
:AbstractVector{A}
, analytes which are not internal standards.point
:AbstractVector{S}
, calibration points, identical tosampleobj(signaltable)
. Ifsignaltable
isnothing
, this value isnothing
too.level
:AbstractVector{Int}
, calibration levels, identical tosampleobj(conctable)
.
ChemistryQuantitativeAnalysis.AnalysisMethod
— MethodAnalysisMethod(conctable::AbstractDataTable{A, Int}, signaltable::SampleDataTable, signal::Symbol, levelname::Symbol; kwargs...)
AnalysisMethod(conctable::AbstractDataTable{A, Int}, signaltable::Nothing, signal::Symbol; kwargs...)
AnalysisMethod(conctable::AbstractDataTable, signaltable::Union{AbstractDataTable, Nothing}, signal::Symbol, pointlevel::AbstractVector{Int}; kwargs...)
Convenient contructors for AnalysisMethod
which make constructing a Table
optional. kwargs
will be columns in analytetable
; when analyte
, isd
and calibration
are not provided, it will use analyte in conctable
.
levelname
is the column name for pointlevel
. See AnalysisMethod
for details of other arguments.
ChemistryQuantitativeAnalysis.AnalysisTable
— TypeAnalysisTable{A, S, T <: AbstractDataTable{A, S}}
Wrapper of multiple tables representing different types of values. A
determines analyte type, S
determines sample type, and T
determines datatable type. It is implemented as a Dictionary{Symbol, T <: AbstractDataTable{A, S}}
, but unlike dictionaries, each datatable can also be extracted using getproperty
.
Fields
analyte
:Vector{A}
, analytes in user-defined types. Useanalyteobj
to get this field.sample
:Vector{S}
, samples in user-defined types. Usesampleobj
to get this field.tables
:Dictionary{Symbol, T}
, a dictionary mapping data type to datatable. Usetables
to get this field.
Properties
All keys of tables
.
ChemistryQuantitativeAnalysis.AnalysisTable
— MethodAnalysisTable(keys::AbstractVector{Symbol}, tables::AbstractVector{<: AbstractDataTable{A, S}})
A Dictionary
-like constructor for AnalysisTable
from two iterable inputs keys
and tables
. The first value of keys
will be the index for the first value of tables
.
ChemistryQuantitativeAnalysis.AnalyteDataTable
— TypeAnalyteDataTable{A, S, N <: Real, T} <: AbstractDataTable{A, S, N, T}
Tabular data wrapper indicates part of columns represent analyte, and all rows reprsent samples. A
determines analyte type, S
determines sample type, N
determines numeric value type, and T
determines table type.
Fields
analyte
:Vector{A}
, analytes in user-defined types, i.e.,getproperty(table(dt), analytecol(dt))
. Useanalyteobj
to get this field.sample
:Vector{S}
, samples in user-defined types. Usesampleobj
to get this field.analytecol
:Symbol
, the column name that each element is analyte name. Useanalytecol
to get this field.table
: Tabular data of typeT
. Usetable
to get this field.
Properties
All properties of table
.
ChemistryQuantitativeAnalysis.AnalyteDataTable
— MethodAnalyteDataTable(analytecol::Symbol, samplename::AbstractVector, table)
AnalyteDataTable(table, analytecol::Symbol, samplename::AbstractVector)
An interface equivalent to AnalyteDataTable(getproperty(table, analytecol), samplename, analytecol, table)
.
ChemistryQuantitativeAnalysis.AnalyteDataTable
— MethodAnalyteDataTable(analytecol::Symbol, sampletype::TypeOrFn, table; samplename = setdiff(propertynames(table), [analytecol]))
AnalyteDataTable(table, analytecol::Symbol, sampletype::TypeOrFn; samplename = setdiff(propertynames(table), [analytecol]))
AnalyteDataTable(analytecol::Symbol, table; samplename = setdiff(propertynames(table), [analytecol]))
AnalyteDataTable(table, analytecol::Symbol; samplename = setdiff(propertynames(table), [analytecol]))
Higher level interfaces for AnalyteDataTable{A, S}
.
analytecol
:Symbol
, the column name that each element is analyte name.samplename
:AbstractVector
, the column names oftable
that are sample names. It will be converted toVector{String}
before conversion toAbstractVector{S}
(string.(samplename)
).sampletype
: typeS
or a function. After first conversion ofsampletype
, it convertssamplename
toAbstractVector{S}
usingcqamap(sampletype, sampletype)
. Seecqaconvert
for the requirement ofsampletype
.
ChemistryQuantitativeAnalysis.AnalyteDataTable
— MethodAnalyteDataTable(tbl::SampleDataTable{A, S, N, T}, analytecol::Symbol, tablesink::TypeOrFn = T)
AnalyteDataTable(analytecol::Symbol, tablesink::TypeOrFn, tbl::SampleDataTable)
AnalyteDataTable(analytecol::Symbol, tbl::SampleDataTable)
Convert SampleDataTable
to AnalyteDataTable
with analytecol
as the column name of analyte.
ChemistryQuantitativeAnalysis.Batch
— TypeBatch{A, M <: AnalysisMethod{A}, C <: AbstractVector{<: AbstractCalibration{<: A}}, D <: Union{AnalysisTable{<: A}, Nothing}}
A type representing a batch for quantitative analysis. A
determines analyte type, and T
determines table type.
Fields
method
:M
, method.calibration
:C
, calibration curves.data
:D
, data for analysis, .
Properties
analyte
:AbstractVector{A}
, analytes in user-defined types, identical tomethod.analyte
.isd
:AbstractVector{<: A}
, analytes which are internal standards, identical tomethod.isd
.nonisd
:AbstractVector{<: A}
, analytes which are not internal standards, identical tomethod.nonisd
.point
:AbstractVector
orNothing
, calibration points, identical tomethod.point
.level
:AbstractVector{Int}
, calibration levels, identical tomethod.level
.
Constructors
Batch(method, calibration, data = nothing)
ChemistryQuantitativeAnalysis.Batch
— MethodBatch(batch::Batch, at::AnalysisTable)
Construct a new batch from an old batch and a AnalysisTable
as new data.
ChemistryQuantitativeAnalysis.Batch
— MethodBatch(dt::AbstractDataTable;
signal::Symbol = :area,
calid = r"Cal_(\d)_(\d*-*\d*)",
order = "LR",
f2c = 1,
parse_decimal = x -> replace(x, "-" => "."))
Construct a batch from data. All analytes are considered as normal analytes, so calibration curves are not contructed immediately; call init_calibration!
after confirming isd and calibration settings in batch.method.analytetable
.
Arguments
dt
: data containing both calibration curves and samples.
Keyword Arguments
signal
:Symbol
, data type for quantification, e.g.:area
.calid
:Regex
, identifier for calibration data; level and concentration related factors (ratio of concentration or dilution factor) should be captured.
The former should be able to be parsed as integer directly; the latter should be able to be parsed as floating number after applying parse_decimal
.
order
:String
, represents the order and identity of captured string;L
is level,R
is ratio of concentration,D
is dilution factor (df).f2c
:Number
or vector of numbers; concentration equals to f2c * ratio or f2c / df. When a vector is provided, each element representsf2c
value of each analyte.parse_decimal
:Function
, converts a string into another string which can be parsed as floating number.
ChemistryQuantitativeAnalysis.Batch
— MethodBatch(method::AnalysisMethod, data = nothing; type = true, zero = false, weight = 0)
Construct a Batch
from method
, and optionally data
with specified calibration parameters. See "MultipleCalibration" for detail description of keyword arguments.
ChemistryQuantitativeAnalysis.MultipleCalibration
— TypeMultipleCalibration{A, N, T <: Table} <: AbstractCalibration{A, N}
A mutable type holding all data and settings for a calibration curve. A
determines analyte type, and N
determines numeric type. Only Float64
is supported because of issue of GLM
.
Fields
analyte
:Tuple{A, Any}
. First element is the analyte being quantified, and the second element is its internal standard for whichnothing
indicates no internal standard.type
:Bool
determines whether fitting a linear line (true
) or quadratic curve (false
).zero
:Bool
determines whether forcing the curve crossing (0, 0) (true
) or ignoring it (false
).weight
:Float64
represents the exponential applying to each element ofx
as a weighting vector.formula
:FormulaTerm
, the formula for fitting calibration curve.table
:TypedTable.Table
, the cleaned up calibration data, containing 7 columns.id
: Point namelevel
: The index of concentration level. The larger, the higher concentraion it represents.y
: Signal or relative signalx
: True concentraionx̂
: Predicted concentrationaccuracy
: Accuracy, i.e.x̂/x
.include
: Whether this point is included or not
model
:GLM
object.
ChemistryQuantitativeAnalysis.SampleDataTable
— TypeSampleDataTable{A, S, N <: Real, T} <: AbstractDataTable{A, S, N, T}
Tabular data wrapper indicates part of columns represent analytes, and all rows reprsent samples. A
determines analyte type, S
determines sample type, N
determines numeric value type, and T
determines table type.
Fields
analyte
:Vector{A}
, analytes in user-defined types. Useanalyteobj
to get this field.sample
:Vector{S}
, samples in user-defined types, i.e.,getproperty(table(dt), samplecol(dt))
. Usesampleobj
to get this field.samplecol
:Symbol
, the column name that each element is sample name. Usesamplecol
to get this field.table
: Tabular data of typeT
. Usetable
to get this field.
Properties
All properties of table
.
ChemistryQuantitativeAnalysis.SampleDataTable
— MethodSampleDataTable(analyte::AbstractVector, samplecol::Symbol, table)
SampleDataTable(table, analytename::AbstractVector, samplecol::Symbol)
An interface equivalent to SampleDataTable(analyte, getproperty(table, samplecol), samplecol, table)
.
ChemistryQuantitativeAnalysis.SampleDataTable
— MethodSampleDataTable(analytetype::TypeOrFn, samplecol::Symbol, table; analytename = setdiff(propertynames(table), [samplecol]))
SampleDataTable(table, analytetype::TypeOrFn, samplecol::Symbol; analytename = setdiff(propertynames(table), [samplecol]))
SampleDataTable(samplecol::Symbol, table; analytename = setdiff(propertynames(table), [samplecol]))
SampleDataTable(table, samplecol::Symbol; analytename = setdiff(propertynames(table), [samplecol]))
Higher level interfaces for SampleDataTable{A}
.
analytename
:AbstractVector
, the column names oftable
that are analyte names. It will be converted toAbstractVector{String}
before conversion toAbstractVector{A}
(string.(analytename)
).samplecol
:Symbol
, the column name that each element is sample name.analytetype
: typeA
or a function. After first conversion ofanalytename
, it convertanalytename
toAbstractVector{A}
usingcqamap(analytetype, analytename)
. Seecqaconvert
for the requirement ofanalytetype
.
ChemistryQuantitativeAnalysis.SampleDataTable
— MethodSampleDataTable(tbl::AnalyteDataTable{A, S, N, T}, samplecol::Symbol, tablesink::TypeOrFn = T)
SampleDataTable(samplecol::Symbol, tablesink::TypeOrFn, tbl::AnalyteDataTable)
SampleDataTable(samplecol::Symbol, tbl::AnalyteDataTable)
Convert AnalyteDataTable
to SampleDataTable
with samplecol
as the column name of sample.
ChemistryQuantitativeAnalysis.SingleCalibration
— TypeSingleCalibration{A, N} <: AbstractCalibration{A, N}
A mutable type holding all data for single point calibration.
Fields
analyte
:Tuple{A}
is the analyte with known concentration (internal standard).conc
:Float64
, concentration of analyte.
Base.write
— MethodChemistryQuantitativeAnalysis.write(file::String, object; delim = "\t")
Write object
into ".scal" for SingleCalibration
, ".mcal" for MultipleCalibration
, ".sdt" for SampleDataTable
, ".adt" for AnalyteDataTable
, ".at" for AnalysisTable
, ".am" for AnalysisMethod
, and ".batch" for Batch
.
delim
specifies delimiter for tabular data if config[:delim]
does not exist.
See README.md for the structure of all files.
ChemistryQuantitativeAnalysis.accuracy
— Methodaccuracy(at::AnalysisTable; true_conc = :true_concentration, est_conc = :estimated_concentration)
accuracy(dtp::AbstractDataTable, dtt::AbstractDataTable)
accuracy(cal::MultipleCalibration, tbl = cal.table)
accuracy(cal::SingleCalibration, tbl)
accuracy(x̂::AbstractVector, x::AbstractVector)
Calculate accuracy and return the values as AbstractDataTable
or Vector
. tbl
must contain two properties, y
and x
, as same as cal.table
.
ChemistryQuantitativeAnalysis.analysistable
— Methodanalysistable(iter)
A dictionary
-like function for constructing AnalysisTable
from an iterable iter of key-value Pair
s (or other iterables of two elements, such as a two-tuples). Keys should be Symbol
s, and values should be AbstractDataTable
s.
ChemistryQuantitativeAnalysis.analytecol
— Methodanalytecol(dt::SampleDataTable) -> Symbol
Equivalent to getfield(dt, :analytecol)
.
ChemistryQuantitativeAnalysis.analytename
— Methodanalytename(dt::AbstractDataTable) -> Vector{Symbol}
analytename(at::AnalysisTable) -> Vector{Symbol}
Equivalent to Symbol.(analyteobj(dt))
or Symbol.(analyteobj(at))
.
ChemistryQuantitativeAnalysis.analyteobj
— Methodanalyteobj(dt::AbstractDataTable{A}) -> Vector{A}
analyteobj(at::AnalysisTable{A}) -> Vector{A}
Equivalent to getfield(dt, :analyte)
or getfield(at, :analyte)
.
ChemistryQuantitativeAnalysis.calibrate!
— Methodcalibrate!(batch::Batch)
calibrate!(cal::Vector{<: AbstractCalibration})
calibrate!(cal::MultipleCalibration)
Fit a GLM
model based on provided formula
, type
, zero
and weight
or parameters from calibration curves.
Field model
will be mutated for mutating version. Calling calibrate!
on a Batch
will apply calibrate!
to all calibration curves.
It returns GLM
object input for mutating version.
ChemistryQuantitativeAnalysis.calibrate
— Methodcalibrate(tbl, formula, type, zero, weight)
calibrate(cal::MultipleCalibration)
Fit a GLM
model based on provided formula
, type
, zero
and weight
or parameters from calibration curves.
Field model
will be mutated for mutating version. Calling calibrate!
on a Batch
will apply calibrate!
to all calibration curves.
It returns GLM
object, and input object for mutating version.
ChemistryQuantitativeAnalysis.calibration
— Methodcalibration(anisd::Tuple, tbl::Table; analyte = 1, isd = 0, type = true, zero = false, weight = 0)
calibration(batch::Batch{A}, ana::B; id = sample(batch.method.signaltable), isd = isdof(batch.method, analyte),
type = true, zero = false, weight = 0) where {A, B <: A}
calibration(method::AnalysisMethod{A}, ana::B; id = sample(method.signaltable), isd = isdof(method, analyte),
type = true, zero = false, weight = 0) where {A, B <: A}
Create MultipleCalibration
.
anisd
:Tuple{B <: A, Any}
which will be stored asanalyte
. The first element is the analyte to be quantified, and the second element is its internal standard, whichnothing
means no internal standard.analyte
:B
which will be stored as first argument ofanalyte
.tbl
:TypedTable.Table
which will be stored astable
. It is clean-up calibration data for points selection.method
:AnalysisMethod
, calibration method and data.batch
:Batch
.
Keyword arguments
type
:Bool
determines whether fitting a linear line (true
) or quadratic curve (false
), which will be stored astype
.zero
:Bool
determines whether forcing the curve crossing (0, 0) (true
) or ignoring it (false
), which will be stored aszero
.weight
:Float64
represents the exponential applying to each element ofx
as a weighting vector, which will be stored asweight
.
ChemistryQuantitativeAnalysis.cqaconvert
— Methodcqaconvert(::Type{T}, x::S)
cqaconvert(fn::Function, x::S)
Call constructor, parse
, or fn
. Extend this function if defining T(x)
is not safe.
Return
parse(T, x)
ifT <: Number
andS <: Union{AbstractString, AbstractChar}
.fn(x)
iffn
is aFunction
.T(x)
otherwise.
Note that string(cqaconvert(T, x))
should equal x
for a valid string x
, i.e. string
and x -> cqaconvert(T, x)
are inverse functions.
ChemistryQuantitativeAnalysis.cqamap
— Methodcqamap(::Type{T}, x::AbstractVector{S})
cqamap(fn::Function, x::AbstractVector)
Convert x
to AbstractVector{T}
. If direct construction is not possible, i.e. neither T <: S
nor S <: T
, it applys cqaconvert
on every elements.
For a function, T
is inferred by cqatype(fn)
first and then cqatype(fn, v)
for the returned vector v
to avoid abstract element type.
ChemistryQuantitativeAnalysis.cqatype
— Methodcqatype(fn::Function)
cqatype(fn::Function, x::AbstractVector)
Default returned type of cqaconvert(fn, x)
. By default, the union of types of each element is used to avoid abstract element type. Extend this function if neccessary.
ChemistryQuantitativeAnalysis.dynamic_range
— Methoddynamic_range(cal::MultipleCalibration)
Return dynamic range as a Tuple
(lloq, uloq).
ChemistryQuantitativeAnalysis.eachanalyte
— Methodeachanalyte(dt::AbstractDataTable)
Create an iterator which gets data belonging to each analyte as a Vector
. For AnalyteDataTable
, new vectors are created; mutating these vector will not change the value in dt
.
ChemistryQuantitativeAnalysis.eachsample
— Methodeachsample(dt::AbstractDataTable)
Create an iterator which gets data belonging to each sample as a Vector
. For SampleDataTable
, new vectors are created; mutating these vector will not change the value in dt
.
ChemistryQuantitativeAnalysis.findanalyte
— Methodfindanalyte(dt::AbstractDataTable{A}, analyte::B) where {A, B <: A}
findanalyte(dt::AbstractDataTable, analyte::Symbol)
Return the index of the first element of analyteobj(dt)
or analytename(dt)
for which the element equals to analyte
.
ChemistryQuantitativeAnalysis.findsample
— Methodfindsample(dt::AbstractDataTable{A, S}, sample::T) where {A, S, T <: S}
findsample(dt::AbstractDataTable, sample::Symbol)
Return the index of the first element of sampleobj(dt)
or samplename(dt)
for which the element equals to sample
.
ChemistryQuantitativeAnalysis.format_number
— Methodformat_number(x; digits = nothing, sigdigits = 4)
Return string representation of number with specified digits
.
If digits
is nothing
, the function uses sigdigits
instead.
ChemistryQuantitativeAnalysis.formula_repr
— Methodformula_repr(cal::SingleCalibration; digits = nothing, sigdigits = 4)
formula_repr(cal::MultipleCalibration; digits = nothing, sigdigits = 4)
Return string representation of formula of cal
with specified digits
and sigdigits
. See format_number
.
ChemistryQuantitativeAnalysis.formula_repr_utf8
— Methodformula_repr_utf8(cal::AbstractCalibration)
Return string representation of formula of cal
for text file output.
ChemistryQuantitativeAnalysis.getanalyte
— Methodgetanalyte(dt::AnalyteDataTable, id::Int)
getanalyte(dt::SampleDataTable, id::Int)
getanalyte(dt::AnalyteDataTable, analyte)
getanalyte(dt::SampleDataTable, analyte)
Get data belonging to analyte
or analyteobj(dt)[id]
as a Vector
. For AnalyteDataTable
, a new vector is created; mutating this vector will not change the value in dt
.
ChemistryQuantitativeAnalysis.getformula
— Methodgetformula(cal::MultipleCalibration)
getformula(type::Bool, zero::Bool)
Get a FormulaTerm
based on type
and zero
or parameters from cal
.
See MultipleCalibration
for detail description of type
and zero
.
ChemistryQuantitativeAnalysis.getsample
— Methodgetsample(dt::AnalyteDataTable, id::Int)
getsample(dt::SampleDataTable, id::Int)
getsample(dt::AnalyteDataTable, sample)
getsample(dt::SampleDataTable, sample)
Get data belonging to sample
or sampleobj(dt)[id]
as a Vector
. For SampleDataTable
, a new vector is created; mutating this vector will not change the value in dt
.
ChemistryQuantitativeAnalysis.idcol
— Methodidcol(dt::AbstractDataTable) -> Symbol
Unified interface for identity column. Equivalent to samplecol(dt::SampleDataTable)
or analytecol(dt::SampleDataTable)
.
ChemistryQuantitativeAnalysis.init_calibration!
— Methodinit_calibration!(batch::Batch)
Initiate calibration for a batch with empty batch.calibration
.
ChemistryQuantitativeAnalysis.inv_predict
— Methodinv_predict(batch::Batch, at::AnalysisTable; rel_sig = :relative_signal)
inv_predict(batch::Batch, dt::AbstractDataTable)
Inversely predict concentration based on relative signal data, getproperty(at, rel_sig)
or dt
, and return the result as AbstractDataTable
.
ChemistryQuantitativeAnalysis.inv_predict
— Methodinv_predict(cal::AbstractCalibration, dt::AbstractDataTable; analyte = first(cal.analyte))
inv_predict(cal::SingleCalibration, y::AbstractArray)
inv_predict(cal::MultipleCalibration, y::AbstractArray)
inv_predict(cal::SingleCalibration)
inv_predict(cal::MultipleCalibration)
Inversely predict concentration of analyte
or analyte specified in cal
, and return the result as a vector using data in dt
, y
or cal.table.y
as inverse predictors.
ChemistryQuantitativeAnalysis.isdof
— Methodisdof(analyte::B, method::AnalysisMethod{A}) where {A, B <: A}
Return internal standard of analyte
based on method
.
ChemistryQuantitativeAnalysis.isisd
— Methodisisd(analyte::B, method::AnalysisMethod{A}) where {A, B <: A}
Return if analyte
is a internal standard based on method
.
ChemistryQuantitativeAnalysis.lloq
— Methodlloq(cal::MultipleCalibration)
Return lower limit of quantification.
ChemistryQuantitativeAnalysis.lod
— Methodlod(cal::MultipleCalibration)
Theoretical limit of quantification (LOQ); concentration of signal adding blank signal and 3.3 times standard deviation of LLOQ signal.
Blank signal is defined as the lowest signal such that the corresponding concentration is larger than 0.
ChemistryQuantitativeAnalysis.loq
— Methodloq(cal::MultipleCalibration)
Theoretical limit of quantification (LOQ); concentration of signal adding blank signal and 10 times standard deviation of LLOQ signal.
Blank signal is defined as the lowest signal such that the corresponding concentration is larger than 0.
ChemistryQuantitativeAnalysis.mkbatch
— Methodmkbatch(file::String;
delim = ' ',
data_table = SampleDataTable,
signal_table = SampleDataTable,
conc_table = SampleDataTable,
data_config = Dict{Symbol, Any}(),
signal_config = Dict{Symbol, Any}(),
conc_config = Dict{Symbol, Any}(),
method_config = Dict{Symbol, Any}()
)
Create a template directory of a batch. See "README.md" for available keys and values for config.
The default table wrapper is SampleDataTable
, whose default sample column name is "Sample", and default sample column name for levels is "Level". The default analyte column name for AnalyteDataTable
is "Analyte".
The priorities of default analytes are conc_config[:Analyte]
, signal_config[:Analyte]
, data_config[:Analyte]
, and lastly ["Analyte1", "Analyte2"]
. The default samples for data are ["S1", "S2"]
. The default calibration points are ["C1", "C2", "C3", "C4", "C5"]
. The default calibration levels are [1, 2, 3, 4, 5]
.
ChemistryQuantitativeAnalysis.quantification
— Methodquantification(batch::Batch, at::AnalysisTable; signal = batch.method.signal)
quantification(batch::Batch, dt::AbstractDataTable)
Quantify all analyes based on relative signal data, and return the result as AbstractDataTable
using getproperty(at, signal)
or dt
as signal data.
ChemistryQuantitativeAnalysis.quantification
— Methodquantification(cal::AbstractCalibration, dt::AbstractDataTable; analyte = cal.analyte)
Quantify analyte
using data in dt
as signals, and return the result as a vector.
ChemistryQuantitativeAnalysis.read
— MethodChemistryQuantitativeAnalysis.read(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t')
Read ".scal" as SingleCalibration
, ".mcal" as MultipleCalibration
, ".sdt" as SampleDataTable
, ".adt" as AnalyteDataTable
, ".at" as AnalysisTable
, ".am" as AnalysisMethod
, and ".batch" as Batch
.
T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist.
For analytetype
and sampletype
, string(cqaconvert(analytetype, x))
and string(cqaconvert(sampletype, x))
should equal x
if x
is a valid string. Additionally, tryparse
have to be extended for CSV
parsing:
tryparse(::Type{analytetype}, x::AbstractString)
is neccessary forAnalyteDataTable
.tryparse(::Type{sampletype}, x::AbstractString)
is neccessary forSampleDataTable
.
See README.md for the structure of ".batch" file.
ChemistryQuantitativeAnalysis.read_analysistable
— Methodread_analysistable(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t') -> AnalysisTable{analytetype, sampletype}
Read ".at" file into julia as AnalysisTable
. T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
in tables
do not exist.
See ChemistryQuantitativeAnalysis.read
for the requirements of analytetype
and sampletype
.
See README.md for the structure of ".at" file.
ChemistryQuantitativeAnalysis.read_analytedatatable
— Methodread_analytedatatable(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t') -> AnalyteDataTable{analytetype, sampletype, numbertype}
Read ".adt" file into julia as AnalyteDataTable
. T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist.
See ChemistryQuantitativeAnalysis.read
for the requirements of analytetype
and sampletype
.
See README.md for the structure of ".adt" file.
ChemistryQuantitativeAnalysis.read_batch
— Methodread_batch(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t') -> Batch{analytetype}
Read ".batch" file into julia as Batch
. T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist.
See ChemistryQuantitativeAnalysis.read
for the requirements of analytetype
and sampletype
.
See README.md for the structure of ".batch" file.
ChemistryQuantitativeAnalysis.read_calibration
— Methodread_calibration(file::String; analytetype = String, numbertype = Float64, delim = '\t') -> AbstractCalibration{analytetype, numbertype}
Read ".mcal" or ".scal" file into julia as MultipleCalibration
or SingleCalibration
. analytetype
is a concrete type for analyte
, , numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist.
numbertype
is forced to Float64
because of issue of GLM
.
See ChemistryQuantitativeAnalysis.read
for the requirement of analytetype
.
See README.md for the structure of ".mcal" and ".scal" file.
ChemistryQuantitativeAnalysis.read_datatable
— Methodread_datatable(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t', levelname = :level) -> AbstractDataTable{analytetype, sampletype, numbertype}
Read ".sdt" and ".adt" file into julia as SampleDataTable
and AnalyteDataTable
, respectively. T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist. level
is specifically used for AnalysisMethod, indicating the column representing calibration level; this column should be all integers.
See ChemistryQuantitativeAnalysis.read
for the requirements of analytetype
and sampletype
.
See README.md for the structure of ".sdt" and ".adt" file.
ChemistryQuantitativeAnalysis.read_method
— Methodread_method(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t') -> AnalysisMethod{analytetype, <: Table}
Read ".am" file into julia as AnalysisMethod
. T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist.
See ChemistryQuantitativeAnalysis.read
for the requirements of analytetype
and sampletype
.
See README.md for the structure of ".am" file.
ChemistryQuantitativeAnalysis.read_sampledatatable
— Methodread_sampledatatable(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t', levelname = :level) -> SampleDataTable{analytetype, sampletype, numbertype}
Read ".sdt" file into julia as SampleDataTable
. T
is the sink function for tabular data, analytetype
is a concrete type for analyte
, sampletype
is a concrete type for sample
, numbertype
is the type for numeric data, and delim
specifies delimiter for tabular data if config[:delim]
does not exist. level
is specifically used for AnalysisMethod, indicating the column representing calibration level; this column should be all integers.
See ChemistryQuantitativeAnalysis.read
for the requirements of analytetype
and sampletype
.
See README.md for the structure of ".sdt" file.
ChemistryQuantitativeAnalysis.relative_signal
— Methodrelative_signal(batch::Batch, at::AnalysisTable; signal = batch.method.signal)
relative_signal(method::AnalysisMethod, at::AnalysisTable; signal = method.signal)
relative_signal(batch::Batch, dt::AbstractDataTable)
relative_signal(method::AnalysisMethod, dt::AbstractDataTable)
Calculate relative signal using getproperty(at, signal)
or dt
as signal data, and return the result as AbstractDataTable
.
ChemistryQuantitativeAnalysis.replace_cal!
— Methodreplace_cal!(batch::Batch{A}, analyte::B, cal::C, isd::Union{D, Nothing} = isdof(cal, batch.method); type = true, zero = false, weight = 0) where {A, B <: A, C <: A, D <: A}
Delete calibration curve of analyte
and replace it with calibration curve of cal
. analyte
must have a calibration curve. If cal
has no caliration curve, a new calibration curve is fitted. The calibration curve use the new isd
. All analytes use the calibration curve of analyte
are affected.
ChemistryQuantitativeAnalysis.samplecol
— Methodsamplecol(dt::SampleDataTable) -> Symbol
Equivalent to getfield(dt, :samplecol)
.
ChemistryQuantitativeAnalysis.samplename
— Methodsamplename(dt::AbstractDataTable) -> Vector{Symbol}
samplename(at::AnalysisTable) -> Vector{Symbol}
Equivalent to Symbol.(sampleobj(dt))
or Symbol.(sampleobj(at))
.
ChemistryQuantitativeAnalysis.sampleobj
— Methodsampleobj(dt::AbstractDataTable{A, S}) -> Vector{S}
sampleobj(at::AnalysisTable{A, S, T}) -> Vector{S}
Equivalent to getfield(dt, :sample)
or getfield(at, :sample)
.
ChemistryQuantitativeAnalysis.set_accuracy!
— Methodset_accuracy!(at::AnalysisTable; true_conc = :true_concentration, est_conc = :estimated_concentration, acc = :accuracy)
Calculate accuracy, update or insert the values into at
at index acc
, and return the object using getproperty(at, true_conc)
as true concentration and getproperty(at, est_conc)
as estimated concentration.
ChemistryQuantitativeAnalysis.set_accuracy
— Methodset_accuracy(at::AnalysisTable; true_conc = :true_concentration, est_conc = :estimated_concentration, acc = :accuracy)
Calculate accuracy, update or insert the values into a copy of at
at index acc
, and return the copy. using getproperty(at, true_conc)
as true concentration and getproperty(at, est_conc)
as estimated concentration.
ChemistryQuantitativeAnalysis.set_cal!
— Methodset_cal!(batch::Batch{A}, analyte::B, cal::C, isd::Union{D, Nothing} = isdof(cal, batch.method); type = true, zero = false, weight = 0) where {A, B <: A, C <: A, D <: A}
Set calibration curve for analyte
to calibration curve of cal
. cal
must have a calibration curve. The calibration curve use the new isd
.
ChemistryQuantitativeAnalysis.set_inv_predict!
— Methodset_inv_predict!(at::AnalysisTable, batch::Batch; rel_sig = :relative_signal, est_conc = :estimated_concentration)
Inversely predict concantration using getproperty(at, rel_sig)
as relstive signal data, update or insert the value into at
at index est_conc
, and return at
.
ChemistryQuantitativeAnalysis.set_inv_predict
— Methodset_inv_predict(at::AnalysisTable, batch::Batch; rel_sig = :relative_signal, est_conc = :estimated_concentration)
Inversely predict concantration using getproperty(at, rel_sig)
as relstive signal data, update or insert the value into a copy of at
at index est_conc
, and return the copy.
ChemistryQuantitativeAnalysis.set_isd!
— Methodset_isd!(batch::Batch{A}, analyte::B, isd::C) where {A, B <: A, C <: A}
Set internal standard of analyte
to isd
. analyte
must have a calibration curve and all analytes use this curve will be affected.
ChemistryQuantitativeAnalysis.set_quantification!
— Methodset_quantification!(at::AnalysisTable, batch::Batch; signal = batch.method.signal, rel_sig = :relative_signal, est_conc = :estimated_concentration)
Quantify all analytes, update or insert the values into at
at index rel_sig
for relative signal and est_conc
for concentration, and return at
.
ChemistryQuantitativeAnalysis.set_quantification
— Methodset_quantification(at::AnalysisTable, batch::Batch; signal = batch.method.signal, rel_sig = :relative_signal, est_conc = :estimated_concentration)
Quantify all analytes using getproperty(at, signal)
as signal data., update or insert the values into a copy of at
at index rel_sig
for relative signal and est_conc
for concentration, and return the copy.
ChemistryQuantitativeAnalysis.set_relative_signal!
— Methodset_relative_signal!(at::AnalysisTable, batch::Batch; signal = batch.method.signal, rel_sig = :relative_signal)
set_relative_signal!(at::AnalysisTable, method::AnalysisMethod; signal = method.signal, rel_sig = :relative_signal)
Calculate relative signal using getproperty(at, signal)
as signal data, update and insert the value into at
at index rel_sig
, and return at
.
ChemistryQuantitativeAnalysis.set_relative_signal
— Methodset_relative_signal(at::AbstractDataTable, batch::Batch; signal = batch.method.signal, rel_sig = :relative_signal)
set_relative_signal(at::AnalysisTable, method::AnalysisMethod; signal = method.signal, rel_sig = :relative_signal)
Calculate relative signal using getproperty(at, signal)
as signal data, update or insert the value into a copy of at
at index rel_sig
, and return the copy.
ChemistryQuantitativeAnalysis.signal_lloq
— Methodsignal_lloq(cal::MultipleCalibration)
Return theoretical signal of lower limit of quantification.
ChemistryQuantitativeAnalysis.signal_range
— Methodsignal_range(cal::MultipleCalibration)
Return theoretical signal of dynamic range as a Tuple
(lloq, uloq).
ChemistryQuantitativeAnalysis.signal_uloq
— Methoduloq(cal::MultipleCalibration)
Return theoretical signal of upper limit of quantification.
ChemistryQuantitativeAnalysis.typedmap
— Methodtypedmap(::Type{T}, c...)
typedmap(f, ::Type{T}, c...)
Transform collection c
by applying f
to each element. For multiple collection arguments, apply f
elementwise, and stop when any of them is exhausted. The element type of returned collection will be forced to T
. In addtion, typedmap(T, c...)
is equivalent to typedmap(T, T, c...)
.
ChemistryQuantitativeAnalysis.uloq
— Methoduloq(cal::MultipleCalibration)
Return upper limit of quantification.
ChemistryQuantitativeAnalysis.update_accuracy!
— Methodupdate_accuracy!(batch::Batch; true_conc = :true_concentration, est_conc = :estimated_concentration, acc = :accuracy)
Calculate accuracy, and update or insert the values into batch.data
or a copy of batch.data
at index acc
, and returns the updated batch
. Use getproperty(batch.data, true_conc)
as true concentration and getproperty(batch.data, est_conc)
as estimated concentration. This function assigns at
to batch.data
ChemistryQuantitativeAnalysis.update_calibration!
— Methodupdate_calibration!(batch::Batch{A}, analyte::B) where {A, B <: A}
update_calibration!(batch::Batch, cal_id::Int)
update_calibration!(cal::MultipleCalibration, method::AnalysisMethod)
Update calibration obeject for analyte
, batch.calibration[cal_id]
or cal
after modifying any parameters in method or calibration object.
ChemistryQuantitativeAnalysis.update_inv_predict!
— Methodupdate_inv_predict!(batch::Batch; rel_sig = :relative_signal, est_conc = :estimated_concentration)
Inversely predict concentration using getproperty(batch.data, rel_sig)
or dt
as relstive signal data, update or insert the value into batch.data
at index est_conc
and returns the updated batch
.
ChemistryQuantitativeAnalysis.update_quantification!
— Methodupdate_quantification!(batch::Batch; signal = batch.method.signal, rel_sig = :relative_signal, est_conc = :estimated_concentration)
Quantify all analytes using getproperty(at, signal)
as signal data, update or insert the values into batch.data
at index rel_sig
for relative signal and est_conc
for concentration, and returns the updated batch
.
ChemistryQuantitativeAnalysis.update_relative_signal!
— Methodupdate_relative_signal!(batch::Batch; signal = batch.method.signal)
Calculate relative signal using getproperty(batch.data, signal)
as signal data, update and insert the value into batch.data
at index rel_sig
, and return the updated batch
.
ChemistryQuantitativeAnalysis.validate!
— Functionconst inv_predict_accuracy! = accuracy! ∘ inv_predict!
Apply inv_predict!
and accuracy!
subsequantly to Batch
or AbstractCalibration
.
ChemistryQuantitativeAnalysis.validate_accuracy!
— Methodvalidate_accuracy!(batch::Batch)
validate_accuracy!(cal::Vector{<: AbstractCalibration})
validate_accuracy!(cal::MultipleCalibration)
validate_accuracy!(cal::SingleCalibration)
Calculate accuracy for analyte specified by cal
, update each cal.table.x̂
with the result(s), and return cal
or batch
.
ChemistryQuantitativeAnalysis.validate_inv_predict!
— Methodvalidate_inv_predict!(batch::Batch)
validate_inv_predict!(cal::Vector{<: AbstractCalibration})
validate_inv_predict!(cal::SingleCalibration)
validate_inv_predict!(cal::MultipleCalibration)
Inverse predict concentration, update each cal.table.x̂
with the result(s) and returns cal
or batch
.
ChemistryQuantitativeAnalysis.weight_repr
— Methodweight_repr(cal::MultipleCalibration)
weight_repr(weight::Number)
Return string representation of cal.weight
or weight
.
"none" for 0, "1/√x" for -0.5, "1/x" for -1, "1/x²" for -2, "x^$weight
" for other positive weight
, and "1/x^$(abs(weight))
" for other negative weight
ChemistryQuantitativeAnalysis.weight_repr_utf8
— Methodweight_repr_utf8(cal::AbstractCalibration)
weight_repr_utf8(weight::Number)
Return string representation of cal.weight
or weight
for text file output.
ChemistryQuantitativeAnalysis.weight_value
— Methodweight_value(weight)
Return value of weight from string representation. See "weight_repr".