Skip to content

Commit fbcff2b

Browse files
authored
Merge pull request #6 from yufongpeng/v0.9
Bug fix for batch read
2 parents a8858b0 + 7e199e5 commit fbcff2b

File tree

9 files changed

+131
-123
lines changed

9 files changed

+131
-123
lines changed

src/calibration.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ function calibrate(method::AnalysisMethod{A}, analyte::B) where {A, B <: A}
367367
table = Table(;
368368
id = id[ord],
369369
level = level,
370+
y = convert(Vector{numbertype}, y),
370371
x = map(level) do l
371372
convert(numbertype, conc[findsample(method.conctable, Symbol(l))])
372373
end,
373-
y = convert(Vector{numbertype}, y),
374374
= zeros(numbertype, length(id)),
375375
accuracy = zeros(numbertype, length(id)),
376-
include = level .> 0
376+
include = collect(level .> 0)
377377
)
378378
calmodel = method.analytetable.model[getanalyteid(method, analyte)]
379379
isnothing(calmodel) && throw(ArgumentError(""))

src/input.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ Additionally, `tryparse` have to be extended for `CSV` parsing:
2525
2626
See README.md for the structure of ".batch" file.
2727
"""
28-
function read(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, delim = '\t', kwargs...)
28+
function read(file::String, T; analytetype = String, sampletype = String, numbertype = Float64, modeltype = CalibrationModel, delim = '\t', kwargs...)
2929
if endswith(file, ".batch")
30-
read_batch(file, T; analytetype, sampletype, numbertype, delim, kwargs...)
30+
read_batch(file, T; analytetype, sampletype, numbertype, modeltype, delim, kwargs...)
3131
elseif endswith(file, ".ical") || endswith(file, ".ecal")
3232
read_calibrator(file; analytetype, numbertype, delim, kwargs...)
3333
elseif endswith(file, ".at")
3434
read_analysistable(file, T; analytetype, sampletype, numbertype, delim, kwargs...)
3535
elseif endswith(file, ".am")
36-
read_method(file, T; analytetype, sampletype, numbertype, delim, kwargs...)
36+
read_method(file, T; analytetype, sampletype, numbertype, delim, modeltype, kwargs...)
3737
elseif endswith(file, ".sdt") || endswith(file, ".adt")
3838
read_datatable(file, T; analytetype, sampletype, numbertype, delim, kwargs...)
3939
end
@@ -93,7 +93,7 @@ function read_calibrator(file::String; analytetype = String, numbertype = Float6
9393
if endswith(file, ".ical")
9494
return InternalCalibrator(analytetype(config[:analyte]), parse(numbertype, config[:conc]))
9595
end
96-
tbl = CSV.read(joinpath(file, "table.txt"), Table; delim = get(config, :delim, delim), typemap = Dict(Int => numbertype, Float64 => numbertype), types = Dict(:level => Int))
96+
tbl = CSV.read(joinpath(file, "table.txt"), Table; delim = get(config, :delim, delim), typemap = Dict(Int => numbertype, Float64 => numbertype), types = Dict(:level => Int), stringtype = String)
9797
model = cqaconvert(modeltype, config[:model])
9898
externalcalibrate(cqaconvert(analytetype, config[:analyte]), config[:isd] == "nothing" ? nothing : cqaconvert(analytetype, config[:isd]), tbl, model; decode_config(modeltype, config)...)
9999
end
@@ -146,7 +146,7 @@ function read_sampledatatable(file::String, T; analytetype = String, sampletype
146146
config = read_config(joinpath(file, "config.txt"))
147147
delim = get(config, :delim, delim)
148148
sample_name = Symbol(first(split(config[:Sample], "\t")))
149-
tbl = CSV.read(joinpath(file, "table.txt"), T; delim, typemap = Dict(Int => numbertype), types = Dict(sample_name => sampletype, levelname => Int), validate = false)
149+
tbl = CSV.read(joinpath(file, "table.txt"), T; delim, typemap = Dict(Int => numbertype), types = Dict(sample_name => sampletype, levelname => Int), stringtype = String, validate = false)
150150
analyte_name = String.(filter!(!isempty, vectorize(config[:Analyte])))
151151
for i in Symbol.(analyte_name)
152152
replace!(getproperty(tbl, i), missing => 0)
@@ -178,7 +178,7 @@ function read_analytedatatable(file::String, T; analytetype = String, sampletype
178178
delim = get(config, :delim, delim)
179179
analyte_name = Symbol(config[:Analyte])
180180
sample_name = String.(filter!(!isempty, vectorize(config[:Sample])))
181-
tbl = CSV.read(joinpath(file, "table.txt"), T; delim, typemap = Dict(Int => numbertype), types = Dict(analyte_name => analytetype), validate = false)
181+
tbl = CSV.read(joinpath(file, "table.txt"), T; delim, typemap = Dict(Int => numbertype), types = Dict(analyte_name => analytetype), stringtype = String, validate = false)
182182
for i in Symbol.(sample_name)
183183
replace!(getproperty(tbl, i), missing => 0)
184184
end
@@ -240,7 +240,7 @@ function read_method(file::String, T; analytetype = String, sampletype = String,
240240
est_conc = Symbol(get(config, :est_conc, :estimated_concentration))
241241
nom_conc = Symbol(get(config, :nom_conc, :nominal_concentration))
242242
acc = Symbol(get(config, :acc, :accuracy))
243-
analytetable = CSV.read(joinpath(file, "analytetable.txt"), Table)
243+
analytetable = CSV.read(joinpath(file, "analytetable.txt"), Table; stringtype = String)
244244
analyte = analytetype.(analytetable.analyte)
245245
isd = replace(analytetable.isd, missing => 0)
246246
model = :model in propertynames(analytetable) ? cqaconvert.(modeltype, analytetable.model) : [LinearCalibrator(ConstWeight()) for _ in eachindex(analytetable)]
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
id level x y x̂ accuracy include
2-
1_1 1 1.0 1.0621578000270309 1.161197621829877 1.161197621829877 true
3-
1_2 1 1.0 0.9862414414131686 1.0877700059565365 1.0877700059565365 true
4-
1_3 1 1.0 0.9967447066341556 1.0979289458496522 1.0979289458496522 true
5-
2_1 2 2.0 1.8344517114942918 1.908173658456888 0.954086829228444 true
6-
2_2 2 2.0 1.8797148500502492 1.951952949400141 0.9759764747000705 true
7-
2_3 2 2.0 1.680958270264759 1.7597121457148728 0.8798560728574364 true
8-
5_1 3 5.0 5.601021053959176 5.551264711408297 1.1102529422816594 true
9-
5_2 3 5.0 4.422628511081951 4.411503050466381 0.8823006100932762 true
10-
5_3 3 5.0 4.616118335932026 4.598649757630717 0.9197299515261435 true
11-
10_1 4 10.0 10.465248168225093 10.256029357506414 1.0256029357506413 true
12-
10_2 4 10.0 10.191627491477236 9.991378703627758 0.9991378703627758 true
13-
10_3 4 10.0 11.148721424668976 10.91709651944875 1.091709651944875 true
14-
20_1 5 20.0 20.26000891690823 19.729691463505425 0.9864845731752713 true
15-
20_2 5 20.0 18.545591346525715 18.07147711941587 0.9035738559707935 true
16-
20_3 5 20.0 21.930782534407193 21.345692621055992 1.0672846310527997 true
17-
50_1 6 50.0 51.18211970688538 49.63809216312383 0.9927618432624766 true
18-
50_2 6 50.0 50.7485659644231 49.21875148025609 0.9843750296051218 true
19-
50_3 6 50.0 52.904116978423225 51.303637725346476 1.0260727545069295 true
1+
id level y x x̂ accuracy include
2+
1_1 1 1.0621578000270309 1.0 1.161197621829877 1.161197621829877 true
3+
1_2 1 0.9862414414131686 1.0 1.0877700059565365 1.0877700059565365 true
4+
1_3 1 0.9967447066341556 1.0 1.0979289458496522 1.0979289458496522 true
5+
2_1 2 1.8344517114942918 2.0 1.908173658456888 0.954086829228444 true
6+
2_2 2 1.8797148500502492 2.0 1.951952949400141 0.9759764747000705 true
7+
2_3 2 1.680958270264759 2.0 1.7597121457148728 0.8798560728574364 true
8+
5_1 3 5.601021053959176 5.0 5.551264711408297 1.1102529422816594 true
9+
5_2 3 4.422628511081951 5.0 4.411503050466381 0.8823006100932762 true
10+
5_3 3 4.616118335932026 5.0 4.598649757630717 0.9197299515261435 true
11+
10_1 4 10.465248168225093 10.0 10.256029357506414 1.0256029357506413 true
12+
10_2 4 10.191627491477236 10.0 9.991378703627758 0.9991378703627758 true
13+
10_3 4 11.148721424668976 10.0 10.91709651944875 1.091709651944875 true
14+
20_1 5 20.26000891690823 20.0 19.729691463505425 0.9864845731752713 true
15+
20_2 5 18.545591346525715 20.0 18.07147711941587 0.9035738559707935 true
16+
20_3 5 21.930782534407193 20.0 21.345692621055992 1.0672846310527997 true
17+
50_1 6 51.18211970688538 50.0 49.63809216312383 0.9927618432624766 true
18+
50_2 6 50.7485659644231 50.0 49.21875148025609 0.9843750296051218 true
19+
50_3 6 52.904116978423225 50.0 51.303637725346476 1.0260727545069295 true
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
id level x y x̂ accuracy include
2-
1_1 1 1.0 9.614331813603554 1.3108251591854765 1.3108251591854765 true
3-
1_2 1 1.0 9.554086969909095 1.3034478179831355 1.3034478179831355 true
4-
1_3 1 1.0 9.619574896831605 1.3114672060654016 1.3114672060654016 true
5-
2_1 2 2.0 14.896238701094893 1.9576262282635806 0.9788131141317903 true
6-
2_2 2 2.0 15.209364999302275 1.9959704150792625 0.9979852075396313 true
7-
2_3 2 2.0 14.181034577438194 1.8700452084455783 0.9350226042227892 true
8-
5_1 3 5.0 44.90912558207436 5.6328836181108475 1.1265767236221695 true
9-
5_2 3 5.0 36.45463522160261 4.597580739785993 0.9195161479571986 true
10-
5_3 3 5.0 40.020179190846456 5.034202910580686 1.0068405821161373 true
11-
10_1 4 10.0 74.45081174235739 9.25043966327546 0.9250439663275459 true
12-
10_2 4 10.0 80.03624456079152 9.934409296814943 0.9934409296814943 true
13-
10_3 4 10.0 83.65005565258461 10.376942065265212 1.0376942065265211 true
14-
20_1 5 20.0 165.84679645094107 20.442424277573508 1.0221212138786755 true
15-
20_2 5 20.0 153.36587188216905 18.914060463875334 0.9457030231937666 true
16-
20_3 5 20.0 158.97493465483618 19.600923726550228 0.9800461863275114 true
17-
50_1 6 50.0 412.4692918382439 50.64282293529764 1.0128564587059528 true
18-
50_2 6 50.0 421.4972096714886 51.74834543512067 1.0349669087024134 true
19-
50_3 6 50.0 391.5046957238022 48.075582832727044 0.9615116566545409 true
1+
id level y x x̂ accuracy include
2+
1_1 1 9.614331813603554 1.0 1.3108251591854765 1.3108251591854765 true
3+
1_2 1 9.554086969909095 1.0 1.3034478179831355 1.3034478179831355 true
4+
1_3 1 9.619574896831605 1.0 1.3114672060654016 1.3114672060654016 true
5+
2_1 2 14.896238701094893 2.0 1.9576262282635806 0.9788131141317903 true
6+
2_2 2 15.209364999302275 2.0 1.9959704150792625 0.9979852075396313 true
7+
2_3 2 14.181034577438194 2.0 1.8700452084455783 0.9350226042227892 true
8+
5_1 3 44.90912558207436 5.0 5.6328836181108475 1.1265767236221695 true
9+
5_2 3 36.45463522160261 5.0 4.597580739785993 0.9195161479571986 true
10+
5_3 3 40.020179190846456 5.0 5.034202910580686 1.0068405821161373 true
11+
10_1 4 74.45081174235739 10.0 9.25043966327546 0.9250439663275459 true
12+
10_2 4 80.03624456079152 10.0 9.934409296814943 0.9934409296814943 true
13+
10_3 4 83.65005565258461 10.0 10.376942065265212 1.0376942065265211 true
14+
20_1 5 165.84679645094107 20.0 20.442424277573508 1.0221212138786755 true
15+
20_2 5 153.36587188216905 20.0 18.914060463875334 0.9457030231937666 true
16+
20_3 5 158.97493465483618 20.0 19.600923726550228 0.9800461863275114 true
17+
50_1 6 412.4692918382439 50.0 50.64282293529764 1.0128564587059528 true
18+
50_2 6 421.4972096714886 50.0 51.74834543512067 1.0349669087024134 true
19+
50_3 6 391.5046957238022 50.0 48.075582832727044 0.9615116566545409 true
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
id level x y x̂ accuracy include
2-
1_1 1 1.0 152.3809399 1.1479626911564438 1.1479626911564438 true
3-
1_2 1 1.0 156.5128989 1.1767600633961386 1.1767600633961386 true
4-
1_3 1 1.0 150.577609 1.1353945143670217 1.1353945143670217 true
5-
2_1 2 2.0 279.3593859 2.032929259285507 1.0164646296427535 true
6-
2_2 2 2.0 273.4204046 1.9915379833264069 0.9957689916632034 true
7-
2_3 2 2.0 261.389156 1.9076871163544677 0.9538435581772339 true
8-
5_1 3 5.0 758.3638326 5.371314116465597 1.0742628232931195 true
9-
5_2 3 5.0 662.5070483 4.703247589380687 0.9406495178761374 true
10-
5_3 3 5.0 684.2497913 4.8547819738416695 0.970956394768334 true
11-
10_1 4 10.0 1344.238317 9.45452152801206 0.9454521528012061 true
12-
10_2 4 10.0 1406.082423 9.885539294963076 0.9885539294963076 true
13-
10_3 4 10.0 1486.806282 10.448138056530565 1.0448138056530565 true
14-
20_1 5 20.0 2935.471746 20.544501214441453 1.0272250607220728 true
15-
20_2 5 20.0 2727.256898 19.09336375550551 0.9546681877752755 true
16-
20_3 5 20.0 2872.776165 20.107549157598452 1.0053774578799226 true
17-
50_1 6 50.0 7115.878054 49.67952326200886 0.9935904652401771 true
18-
50_2 6 50.0 7184.179874 50.15554757279913 1.0031109514559826 true
19-
50_3 6 50.0 7206.298386 50.30970085056693 1.0061940170113386 true
1+
id level y x x̂ accuracy include
2+
1_1 1 152.3809399 1.0 1.1479626911564438 1.1479626911564438 true
3+
1_2 1 156.5128989 1.0 1.1767600633961386 1.1767600633961386 true
4+
1_3 1 150.577609 1.0 1.1353945143670217 1.1353945143670217 true
5+
2_1 2 279.3593859 2.0 2.032929259285507 1.0164646296427535 true
6+
2_2 2 273.4204046 2.0 1.9915379833264069 0.9957689916632034 true
7+
2_3 2 261.389156 2.0 1.9076871163544677 0.9538435581772339 true
8+
5_1 3 758.3638326 5.0 5.371314116465597 1.0742628232931195 true
9+
5_2 3 662.5070483 5.0 4.703247589380687 0.9406495178761374 true
10+
5_3 3 684.2497913 5.0 4.8547819738416695 0.970956394768334 true
11+
10_1 4 1344.238317 10.0 9.45452152801206 0.9454521528012061 true
12+
10_2 4 1406.082423 10.0 9.885539294963076 0.9885539294963076 true
13+
10_3 4 1486.806282 10.0 10.448138056530565 1.0448138056530565 true
14+
20_1 5 2935.471746 20.0 20.544501214441453 1.0272250607220728 true
15+
20_2 5 2727.256898 20.0 19.09336375550551 0.9546681877752755 true
16+
20_3 5 2872.776165 20.0 20.107549157598452 1.0053774578799226 true
17+
50_1 6 7115.878054 50.0 49.67952326200886 0.9935904652401771 true
18+
50_2 6 7184.179874 50.0 50.15554757279913 1.0031109514559826 true
19+
50_3 6 7206.298386 50.0 50.30970085056693 1.0061940170113386 true
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
id level x y x̂ accuracy include
2-
1_1 1 1.0 1.0621578000270309 1.161197621829877 1.161197621829877 true
3-
1_2 1 1.0 0.9862414414131686 1.0877700059565365 1.0877700059565365 true
4-
1_3 1 1.0 0.9967447066341556 1.0979289458496522 1.0979289458496522 true
5-
2_1 2 2.0 1.8344517114942918 1.908173658456888 0.954086829228444 true
6-
2_2 2 2.0 1.8797148500502492 1.951952949400141 0.9759764747000705 true
7-
2_3 2 2.0 1.680958270264759 1.7597121457148728 0.8798560728574364 true
8-
5_1 3 5.0 5.601021053959176 5.551264711408297 1.1102529422816594 true
9-
5_2 3 5.0 4.422628511081951 4.411503050466381 0.8823006100932762 true
10-
5_3 3 5.0 4.616118335932026 4.598649757630717 0.9197299515261435 true
11-
10_1 4 10.0 10.465248168225093 10.256029357506414 1.0256029357506413 true
12-
10_2 4 10.0 10.191627491477236 9.991378703627758 0.9991378703627758 true
13-
10_3 4 10.0 11.148721424668976 10.91709651944875 1.091709651944875 true
14-
20_1 5 20.0 20.26000891690823 19.729691463505425 0.9864845731752713 true
15-
20_2 5 20.0 18.545591346525715 18.07147711941587 0.9035738559707935 true
16-
20_3 5 20.0 21.930782534407193 21.345692621055992 1.0672846310527997 true
17-
50_1 6 50.0 51.18211970688538 49.63809216312383 0.9927618432624766 true
18-
50_2 6 50.0 50.7485659644231 49.21875148025609 0.9843750296051218 true
19-
50_3 6 50.0 52.904116978423225 51.303637725346476 1.0260727545069295 true
1+
id level y x x̂ accuracy include
2+
1_1 1 1.0621578000270309 1.0 1.161197621829877 1.161197621829877 true
3+
1_2 1 0.9862414414131686 1.0 1.0877700059565365 1.0877700059565365 true
4+
1_3 1 0.9967447066341556 1.0 1.0979289458496522 1.0979289458496522 true
5+
2_1 2 1.8344517114942918 2.0 1.908173658456888 0.954086829228444 true
6+
2_2 2 1.8797148500502492 2.0 1.951952949400141 0.9759764747000705 true
7+
2_3 2 1.680958270264759 2.0 1.7597121457148728 0.8798560728574364 true
8+
5_1 3 5.601021053959176 5.0 5.551264711408297 1.1102529422816594 true
9+
5_2 3 4.422628511081951 5.0 4.411503050466381 0.8823006100932762 true
10+
5_3 3 4.616118335932026 5.0 4.598649757630717 0.9197299515261435 true
11+
10_1 4 10.465248168225093 10.0 10.256029357506414 1.0256029357506413 true
12+
10_2 4 10.191627491477236 10.0 9.991378703627758 0.9991378703627758 true
13+
10_3 4 11.148721424668976 10.0 10.91709651944875 1.091709651944875 true
14+
20_1 5 20.26000891690823 20.0 19.729691463505425 0.9864845731752713 true
15+
20_2 5 18.545591346525715 20.0 18.07147711941587 0.9035738559707935 true
16+
20_3 5 21.930782534407193 20.0 21.345692621055992 1.0672846310527997 true
17+
50_1 6 51.18211970688538 50.0 49.63809216312383 0.9927618432624766 true
18+
50_2 6 50.7485659644231 50.0 49.21875148025609 0.9843750296051218 true
19+
50_3 6 52.904116978423225 50.0 51.303637725346476 1.0260727545069295 true
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
id level x y x̂ accuracy include
2-
1_1 1 1.0 9.614331813603554 1.3108251591854765 1.3108251591854765 true
3-
1_2 1 1.0 9.554086969909095 1.3034478179831355 1.3034478179831355 true
4-
1_3 1 1.0 9.619574896831605 1.3114672060654016 1.3114672060654016 true
5-
2_1 2 2.0 14.896238701094893 1.9576262282635806 0.9788131141317903 true
6-
2_2 2 2.0 15.209364999302275 1.9959704150792625 0.9979852075396313 true
7-
2_3 2 2.0 14.181034577438194 1.8700452084455783 0.9350226042227892 true
8-
5_1 3 5.0 44.90912558207436 5.6328836181108475 1.1265767236221695 true
9-
5_2 3 5.0 36.45463522160261 4.597580739785993 0.9195161479571986 true
10-
5_3 3 5.0 40.020179190846456 5.034202910580686 1.0068405821161373 true
11-
10_1 4 10.0 74.45081174235739 9.25043966327546 0.9250439663275459 true
12-
10_2 4 10.0 80.03624456079152 9.934409296814943 0.9934409296814943 true
13-
10_3 4 10.0 83.65005565258461 10.376942065265212 1.0376942065265211 true
14-
20_1 5 20.0 165.84679645094107 20.442424277573508 1.0221212138786755 true
15-
20_2 5 20.0 153.36587188216905 18.914060463875334 0.9457030231937666 true
16-
20_3 5 20.0 158.97493465483618 19.600923726550228 0.9800461863275114 true
17-
50_1 6 50.0 412.4692918382439 50.64282293529764 1.0128564587059528 true
18-
50_2 6 50.0 421.4972096714886 51.74834543512067 1.0349669087024134 true
19-
50_3 6 50.0 391.5046957238022 48.075582832727044 0.9615116566545409 true
1+
id level y x x̂ accuracy include
2+
1_1 1 9.614331813603554 1.0 1.3108251591854765 1.3108251591854765 true
3+
1_2 1 9.554086969909095 1.0 1.3034478179831355 1.3034478179831355 true
4+
1_3 1 9.619574896831605 1.0 1.3114672060654016 1.3114672060654016 true
5+
2_1 2 14.896238701094893 2.0 1.9576262282635806 0.9788131141317903 true
6+
2_2 2 15.209364999302275 2.0 1.9959704150792625 0.9979852075396313 true
7+
2_3 2 14.181034577438194 2.0 1.8700452084455783 0.9350226042227892 true
8+
5_1 3 44.90912558207436 5.0 5.6328836181108475 1.1265767236221695 true
9+
5_2 3 36.45463522160261 5.0 4.597580739785993 0.9195161479571986 true
10+
5_3 3 40.020179190846456 5.0 5.034202910580686 1.0068405821161373 true
11+
10_1 4 74.45081174235739 10.0 9.25043966327546 0.9250439663275459 true
12+
10_2 4 80.03624456079152 10.0 9.934409296814943 0.9934409296814943 true
13+
10_3 4 83.65005565258461 10.0 10.376942065265212 1.0376942065265211 true
14+
20_1 5 165.84679645094107 20.0 20.442424277573508 1.0221212138786755 true
15+
20_2 5 153.36587188216905 20.0 18.914060463875334 0.9457030231937666 true
16+
20_3 5 158.97493465483618 20.0 19.600923726550228 0.9800461863275114 true
17+
50_1 6 412.4692918382439 50.0 50.64282293529764 1.0128564587059528 true
18+
50_2 6 421.4972096714886 50.0 51.74834543512067 1.0349669087024134 true
19+
50_3 6 391.5046957238022 50.0 48.075582832727044 0.9615116566545409 true

0 commit comments

Comments
 (0)