-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert SnpArray into matrix{Int} doesn't obey conversion convention #79
Comments
The encoding also messes up if I try to convert a using SnpArrays
const mouse = SnpArray(SnpArrays.datadir("mouse.bed"))
convert(Matrix{Union{Float64, Missing}}, mouse)[1:10] 10-element Array{Union{Missing, Float64},1}:
2.0
2.0
3.0
2.0
3.0
2.0
2.0
2.0
2.0
3.0 |
The function from https://github.com/OpenMendel/SnpArrays.jl/blob/master/src/snparray.jl#L290: @inline function convert(::Type{T}, x::UInt8, ::Val{1}) where T <: AbstractFloat
iszero(x) ? zero(T) : isone(x) ? T(NaN) : T(x - 1)
end
@inline function convert(::Type{T}, x::UInt8, ::Val{2}) where T <: AbstractFloat
iszero(x) ? zero(T) : isone(x) ? T(NaN) : one(T)
end
@inline function convert(::Type{T}, x::UInt8, ::Val{3}) where T <: AbstractFloat
(iszero(x) || x == 2) ? zero(T) : isone(x) ? T(NaN) : one(T)
end If I think it would be straightforward to define However, I'm not sure if converting @Hua-Zhou What do you think? +) Also, there is no |
I had to convert a Probably the easiest thing to do is make SnpArrays throw errors for these case instead of converting incorrectly |
Changing Array{T,N}(s::AbstractSnpArray; kwargs...) where {T,N} =
copyto!(Array{T,N}(undef, size(s)), s; kwargs...) on https://github.com/OpenMendel/SnpArrays.jl/blob/master/src/snparray.jl#L370 Array{T,N}(s::AbstractSnpArray; kwargs...) where {T,N} =
throw(ArgumentError("Cannot convert $(typeof(s)) to Array{$T,$N}"))
Array{T,N}(s::AbstractSnpArray; kwargs...) where {T <: AbstractFloat,N} =
copyto!(Array{T,N}(undef, size(s)), s; kwargs...) sounds reasonable to me. |
In Plink 2's fixed-width format, 0x00 encodes 0, 0x01 encodes 1, 0x02 encodes 2, and 0x03 encodes missing. This might be a good Int-representation for a SnpArray. |
According to documentation, 0x01 encodes missing (NaN),
0x02
encode 1,0x03
encodes 2. But if we convert a SnpArray into matrix of subtype Int,0x01
will become 1,0x02
= 2, and0x03
= 3.Is this by design or a bug?
The text was updated successfully, but these errors were encountered: