Skip to content

Commit aa44122

Browse files
Test for interactions with string-treatments and integer extra treatments
1 parent 911f473 commit aa44122

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/inputs_from_config.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ end
193193
"""
194194
function treatments_from_variant(variant::String, dataset::DataFrame)
195195
variant_levels = sort(levels(dataset[!, variant], skipmissing=true))
196-
return Dict{Symbol, Vector{String}}(Symbol(variant)=>variant_levels)
196+
if typeof(variant_levels) == Vector{String}
197+
return Dict{Symbol, Vector{String}}(Symbol(variant)=>variant_levels)
198+
elseif typeof(variant_levels) == Vector{Int}
199+
return Dict{Symbol, Vector{UInt8}}(Symbol(variant)=>variant_levels)
200+
else
201+
throw(ArgumentError("Unknown type for treatment levels (must be of type String or Int)"))
202+
end
197203
end
198204

199205
function estimands_from_gwas(dataset, variants, outcomes, confounders;

test/inputs_from_gweis_config.jl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function get_summary_stats(estimands)
2020
return sort(combine(groupby(results, :OUTCOME), nrow), :OUTCOME)
2121
end
2222

23-
function check_estimands_levels_interactions(estimands)
23+
function check_estimands_levels_interactions(estimands, snp_info)
2424
extra_treatments = YAML.load_file(joinpath(TESTDIR, "data", "config_gweis_first_order.yaml"))["extra_treatments"]
2525
for (i,x) in enumerate(extra_treatments)
2626
extra_treatments[i]=Symbol(x)
@@ -31,18 +31,27 @@ function check_estimands_levels_interactions(estimands)
3131
# The variant should always be the last key
3232
treatment_set = collect(keys.args[1].treatment_values))
3333
variant = setdiff(treatment_set, extra_treatments)[1]
34+
variant_info = filter(:snpid=>x->x==String(variant),snp_info)
35+
allele1, allele2 = variant_info.allele1[1], variant_info.allele2[1]
36+
# Here, we check if the order is sufficient to be able to compute non-linear effects any of these combinations will do
3437
if length.args) == 2
35-
@test Ψ.args[1].treatment_values[variant] == (control = 0x00, case = 0x01)
36-
@test Ψ.args[2].treatment_values[variant] == (control = 0x01, case = 0x02)
38+
@test.args[1].treatment_values[variant] == (control = allele1*allele1, case = allele1*allele2) &&
39+
Ψ.args[2].treatment_values[variant] == (control = allele1*allele2, case = allele2*allele2)) ||
40+
.args[1].treatment_values[variant] == (control = allele2*allele2, case = allele1*allele2) &&
41+
Ψ.args[2].treatment_values[variant] == (control = allele1*allele2, case = allele1*allele1))
3742
else
3843
# Otherwise we check they are one or the other
3944
arg = only.args)
40-
@test arg.treatment_values[variant]==(control = 0x00, case = 0x01) ||
41-
arg.treatment_values[variant]==( control = 0x01, case = 0x02)
45+
@test arg.treatment_values[variant] == (control = allele1*allele1, case = allele1*allele2) ||
46+
arg.treatment_values[variant] == (control = allele2*allele2, case = allele1*allele2) ||
47+
arg.treatment_values[variant] == (control = allele1*allele2, case = allele2*allele2) ||
48+
arg.treatment_values[variant] == (control = allele1*allele2, case = allele1*allele1)
49+
4250
end
4351
end
4452
end
4553

54+
4655
@testset "Test inputs_from_config gweis: no positivity constraint" begin
4756
tmpdir = mktempdir()
4857
copy!(ARGS, [
@@ -76,8 +85,11 @@ end
7685
OUTCOME = [:BINARY_1, :BINARY_2, :CONTINUOUS_1, :CONTINUOUS_2],
7786
nrow = repeat([2625], 4)
7887
)
79-
println(estimands[1])
80-
check_estimands_levels_interactions(estimands)
88+
# Define SNP information to check string allele defintions
89+
snpdata = read_bed_chromosome(joinpath(TESTDIR, "data", "ukbb", "genotypes" , "ukbb_1."))
90+
snp_info = select(DataFrame(snpdata.snp_info), [:snpid, :allele1, :allele2])
91+
92+
check_estimands_levels_interactions(estimands, snp_info)
8193
end
8294

8395

@@ -113,7 +125,11 @@ end
113125
nrow = repeat([430], 4)
114126
)
115127

116-
check_estimands_levels_interactions(estimands)
128+
# Define SNP information to check string allele defintions
129+
snpdata = read_bed_chromosome(joinpath(TESTDIR, "data", "ukbb", "genotypes" , "ukbb_1."))
130+
snp_info = select(DataFrame(snpdata.snp_info), [:snpid, :allele1, :allele2])
131+
132+
check_estimands_levels_interactions(estimands, snp_info)
117133
end
118134

119135

0 commit comments

Comments
 (0)