Skip to content

Commit

Permalink
Properly display missing values for SnpLinAlg when impute=true (#88)
Browse files Browse the repository at this point in the history
* Drop dependency on GeneticVariation.jl in favor of VariantCallFormat

* proper display of getindex for missing data in SnpLinAlg

* added some tests for missing data in snplinalg
  • Loading branch information
biona001 committed Jun 1, 2021
1 parent 2a7976e commit 68a99b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/linalg_direct.jl
Expand Up @@ -94,6 +94,7 @@ eltype(bm::SnpLinAlg) = eltype(bm.μ)

function Base.getindex(s::SnpLinAlg{T}, i::Int, j::Int) where T
x = SnpArrays.convert(T, getindex(s.s, i, j), s.model)
s.impute && isnan(x) && return s.μ[j]
s.center && (x -= s.μ[j])
s.scale && (x *= s.σinv[j])
return x
Expand Down
10 changes: 8 additions & 2 deletions test/runtests.jl
Expand Up @@ -294,9 +294,15 @@ end

@testset "copyto SnpLinAlg" begin
for model in [ADDITIVE_MODEL, DOMINANT_MODEL, RECESSIVE_MODEL], t in [Float32, Float64]
mousela = SnpLinAlg{t}(mouse, model=ADDITIVE_MODEL, center=true, scale=true)
v = copyto!(zeros(1), @view(mousela[702]))
# imputing missing data
mousela = SnpLinAlg{t}(mouse, model=ADDITIVE_MODEL, center=true, scale=true, impute=true)
v = copyto!(zeros(1), @view(mousela[702])) # missing entry
@test isapprox(v[1], 1.113003134727478, atol=1e-6)
# not imputing missing data
mousela = SnpLinAlg{t}(mouse, model=ADDITIVE_MODEL, center=true, scale=true, impute=false)
v = copyto!(zeros(1), @view(mousela[702])) # missing entry
@test isnan(v[1])
# no missing data
EURla = SnpLinAlg{t}(EUR, model=model, center=true, scale=true)
EURtrue = convert(Matrix{t}, EUR, model=model, center=true, scale=true)
EURtest = copyto!(zeros(t, size(EUR)), EURla)
Expand Down

0 comments on commit 68a99b8

Please sign in to comment.