Skip to content

Commit

Permalink
Update to ChemistryQuantitativeAnalysis v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yufongpeng committed Dec 28, 2023
1 parent 451f702 commit d2d0c20
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 53 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ UnitfulMoles = "999f2bd7-36bf-5ba7-9bc1-c9473aa75374"
AnovaGLM = "0.2"
CSV = "0.10"
Clustering = "0.15"
ChemistryQuantitativeAnalysis = "0.3"
DataPipes = "0.3"
Dictionaries = "0.3"
MLStyle = "0.4"
Expand Down
68 changes: 56 additions & 12 deletions src/SphingolipidsID.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export SPDB, LIBRARY_POS, FRAGMENT_POS, ADDUCTCODE, CLASSDB,
nfrags, @cpdsc, @score, calc_score, apply_score!, calc_threshold, apply_threshold!, w_rank, w_nfrags, w_rank_log, w_rank_exp,
normalized_sig_diff, abs_sig_diff,
# Transition
analyte_map_mrm, transitiontable, concurrent_transition, write_transition,
analytetable_mrm, transitiontable, concurrent_transition, write_transition,
read_transition, union_transition!, union_transition, diff_transition!, diff_transition,
# Quantification
quantification_mrm, set_quantification_mrm!, set_qcdata_mrm!, qcdata_mrm, qcdata_mrm!,
Expand Down Expand Up @@ -221,11 +221,11 @@ struct AnalyteID <: AbstractAnalyteID
rt::Float64
end
"""
TransitionID <: AbstractAnalyteID
TransitionID
A type represents a transition of an analyte and whether it is a quantifier.
"""
struct TransitionID <: AbstractAnalyteID
struct TransitionID
compound::SPID
quantifier::Bool
end
Expand Down Expand Up @@ -290,7 +290,9 @@ Multiple reaction monitoring data.
* `area`: peak area.
* `FWHM`: Full width at half maximum.
* `symmetry`: peak symmetry.
* `error`: signal error.
* `error`: signal error, optinal.
* `raw_id`: `id` of original table, optional.
* `match_id`: `id` of matched transition from `project.quantification`.
* `mz2`: `Vector{Float64}`, m/z of fragments.
* `polarity`: `Bool`; `true` for positive ion mode; `false` for negative ion mode.
* `config`: `Dictionary` containing config information.
Expand All @@ -304,18 +306,24 @@ Multiple reaction monitoring data.
* `:other_fn`: `Dictionary`. Stores functions for calculating other signal information.
"""
struct MRM <: AbstractRawData
table::Table # id, mz1, mz2_id, height, area, collision_energy, FWHM, symmetry, error
table::Table
mz2::Vector{Float64}
polarity::Bool
config::Dictionary
end

"""
QuantData{T} <: AbstractQuantData{T}
Type containing raw data and tables related to quantification.
* `raw`: raw data.
* `table`: `AnalysisTable`, data for quantification (`table.area` or `table.height`), and quantification result (`table.estimated_concentration`).
* `config`: `Dictionary` containing config information.
"""
struct QuantData{T} <: AbstractQuantData{T}
raw::T
table::AnalysisTable # id, analyte, FWHM, symmetry, estimate, error, raw_id
table::AnalysisTable
config::Dictionary
end

Expand All @@ -330,6 +338,12 @@ propertynames(dt::QuantData) = Tuple(unique((:raw, :table, :config, propertyname

"""
QCData{T} <: AbstractQuantData{T}
Type for QC samples containing raw data and tables related to quantification.
* `raw`: raw data.
* `table`: `AnalysisTable`, data for quantification (`table.area` or `table.height`), and quantification result (`table.estimated_concentration`).
* `config`: `Dictionary` containing config information.
"""
struct QCData{T} <: AbstractQuantData{T}
raw::T
Expand All @@ -348,10 +362,16 @@ propertynames(qc::QCData) = Tuple(unique((:raw, :table, :config, propertynames(g
#QCData(raw::T, table::Table, config::Dictionary) where {T <: Data} = QCData{T}(raw, table, config)
"""
SerialDilution{T} <: AbstractQuantData{T}
Type for serial dilution samples containing raw data and calibration data.
* `raw`: raw data.
* `batch`: `Batch` containg analyte settings and calibration curves.
* `config`: `Dictionary` containing config information.
"""
struct SerialDilution{T} <: AbstractQuantData{T}
raw::T # id, mz1, mz2, height, area, collision_energy, FWHM, symmetry, level
batch::Batch # id, analyte, raw_id, r2, model, data_id
raw::T
batch::Batch
config::Dictionary
end

Expand All @@ -367,6 +387,11 @@ propertynames(sd::SerialDilution) = Tuple(unique((:raw, :batch, :config, propert

"""
Quantification
Type containg information of analyte settings, calibration data, qc data, serial dilution data, and sample data.
* `batch`: `Batch` containg analyte settings, calibration data, and sample data.
* `config`: `Dictionary` containing config information. `config[:qcdata]` stores a `QCData`, `config[:serialdilution]` stores a `SerialDilution`, and `config[:quantdata]` stores a `QuantData` (sample data).
"""
struct Quantification
batch::Batch
Expand All @@ -386,6 +411,14 @@ propertynames(quant::Quantification) = (:batch, :config, propertynames(getfield(

"""
RTCorrection
Type holding rt data and regression line for correcting rt from old batch (data for identification) to new batch (data for quantification).
* `data`: raw data from new batch.
* `table`: old transition table generated from `project.analye` and function `analytetable_mrm`.
* `fn`: `Dictionary` containg regression coefficents for each class.
This is a callable object taking a class and rt or vector of class and a vector of rt as input, and returning new rt or a vector of new rt. If the class is not in `fn`, it will return the original rt.
"""
struct RTCorrection
data::AbstractRawData
Expand Down Expand Up @@ -420,22 +453,33 @@ mutable struct Project <: AbstractProject
analyte::Vector{AnalyteSP}
data::Vector{AbstractData}
quantification::Quantification
#anion::Symbol
#cluster::Dictionary
#alignment::Int
appendix::Dictionary
end
"""
Project(; kwargs...)
Create an empty `Project`. All keyword arguments will be put into `project.appendix`. By default, `project.appendix[:anion]` will be `:acetate`; `project.appendix[:signal]` will be `:area`
Create an empty `Project`. All keyword arguments will be put into `project.appendix`. By default, `project.appendix[:anion]` will be `:acetate`; `project.appendix[:signal]` will be `:area`.
"""
function Project(; kwargs...)
appendix = Dictionary{Symbol, Any}(kwargs)
get!(appendix, :anion, :acetate)
get!(appendix, :signal, :area)
Project(AnalyteSP[], AbstractData[], Quantification(), appendix)
end
"""
Project(qt::Quantification; kwargs...)
Create a `Project` from `Quantification`. All keyword arguments will be put into `project.appendix`. By default, `project.appendix[:anion]` will be `:acetate`; `project.appendix[:signal]` will be `:area`.
"""
function Project(qt::Quantification; kwargs...)
appendix = Dictionary{Symbol, Any}(kwargs)
get!(appendix, :anion, get(qt.appendix, :anion, :acetate))
get!(appendix, :signal, get(qt.appendix, :signal, :area))
analyte = isa(qt.analyte, Vector{AnalyteSP}) ? qt.analyte : map(qt.analyte, qt.batch.analytetable.rt) do ana, rt
isa(ana, AnalyteSP) ? ana : AnalyteSP([CompoundSP(class(ana), chain(ana))], rt)
end
Project(analyte, AbstractData[], qt, appendix)
end
"""
AbstractQuery
Expand Down
13 changes: 12 additions & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,20 @@ end

getproperty(reusable::ReusableQuery, sym::Symbol) = sym :query ? getfield(reusable, :query) : getfield(getfield(reusable, :query), sym)

convert(::Type{CompoundSP}, cpd::CompoundSP) = cpd
convert(::Type{CompoundSPVanilla}, cpd::CompoundSPVanilla) = cpd
convert(::Type{SPID}, cpd::SPID) = cpd
convert(::Type{CompoundSPVanilla}, cpd::CompoundSP) = CompoundSPVanilla(cpd.class, cpd.chain, cpd.fragment)
convert(::Type{CompoundSP}, cpd::CompoundSPVanilla) = CompoundSP(cpd.class, cpd.chain, cpd.fragment)
convert(::Type{SPID}, cpd::SPID) = cpd
convert(::Type{SPID}, cpd::CompoundSP) = SPID(cpd.calss, cpd.chain)
convert(::Type{CompoundSP}, cpd::SPID) = CompoundSP(cpd.calss, cpd.chain)
convert(::Type{SPID}, cpd::CompoundSPVanilla) = SPID(cpd.calss, cpd.chain)
convert(::Type{CompoundSPVanilla}, cpd::SPID) = CompoundSPVanilla(cpd.calss, cpd.chain)
convert(::Type{AnalyteSP}, analyte::AnalyteSP) = analyte
convert(::Type{AnalyteID}, analyte::AnalyteID) = analyte
convert(::Type{TransitionID}, analyte::TransitionID) = analyte
convert(::Type{AnalyteSP}, analyte::AnalyteID) = AnalyteSP(analyte.compound, analyte.rt)
convert(::Type{AnalyteID}, analyte::AnalyteSP) = AnalyteID(analyte.compound, analyte.rt)

# variant of interface
# iscomponent: whether ion is a component of cpd
Expand Down
Loading

0 comments on commit d2d0c20

Please sign in to comment.