-
Notifications
You must be signed in to change notification settings - Fork 63
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
Potential Bug: Change NAs in genlight objects when subsetting to zeros #83
Comments
This is indeed a bug. Here's a minimum example that I will use: x <- "
X13049 X13050 X13051 X13052 X13053
AA36881 2 NA 2 2 2
AA36883 2 2 2 2 2
AA36884 2 2 2 2 2
AA36802 NA 2 2 2 2
AA36803 2 2 2 2 2
AA36804 2 NA 2 2 2
AA36181 2 NA 2 2 2
AA36183 2 2 2 2 2"
xxdf <- read.table(text = x)
library("adegenet")
xx <- new("genlight", xxdf)
NA.posi(xx)
# $AA36881
# [1] 2
#
# $AA36883
# integer(0)
#
# $AA36884
# integer(0)
#
# $AA36802
# [1] 1
#
# $AA36803
# integer(0)
#
# $AA36804
# [1] 2
#
# $AA36181
# [1] 2
#
# $AA36183
# integer(0)
NA.posi(xx[])
# $AA36881
# integer(0)
#
# $AA36883
# integer(0)
#
# $AA36884
# integer(0)
#
# $AA36802
# [1] 1 1 1 1 1
#
# $AA36803
# integer(0)
#
# $AA36804
# integer(0)
#
# $AA36181
# integer(0)
#
# $AA36183
# integer(0) The issue is in the fact that logicals and negative subscripts are not being treated correctly in the internal subsetter for SNPbin objects. The problem code lies in lines 23 - 32 of glHandle.R. I will fix this in the morning. Thanks for the report. |
Until this is fixed, a workaround is to always specify the loci you want to keep: For example, this should work in the current situation. (myloci <- seq(nLoc(xx)))
# [1] 1 2 3 4 5
xxx <- xx[xx@pop=="A", myloci] |
Thanks for spotting this. @zkamvar thanks for fixing it! |
Hi,
I tried to contact Thibaut directly, but maybe this is the better way.
When working together with my colleague on a script using genlight object within adegenet 2 he came across this strange behaviour that when you subset a genlight object all NAs in the SNPs except for the first are converted to zeros.
Can you please advise if this is a bug or if we are doing something wrong. I attach a small working example together with an r script that shows it.
Cheers, Bernd
RSCRIPT
error when subsetting creating 0's for NA's (not in the first column)
Console Output:
Please advise
The text was updated successfully, but these errors were encountered: