thibautjombart / adegenet

adegenet: a R package for the multivariate analysis of genetic markers
165 stars 64 forks source link

NA.char other than "-9" lead to potential problems with Microsat data #348

Open grolshausen opened 1 year ago

grolshausen commented 1 year ago

Hello,

Quick question concerning the "read.structure" function:

I just found out that running the parameter NA.char=0 (or "0") will remove/ignore any sample with alleles that have a "0" anywhere (!)... meaning that e.g. alleles such as "120" or "90" (e.g. for Microsat data) will lead to complete exclusion of that sample, thus miscalculating allele-freqs etc.

Example data:

loc1a loc1b
ind1 1 126 132 ind2 1 118 120 ind3 1 126 128 ind4 1 0 0

genind.obj@loc.n.all (read in with NA.char="0") gives: L1.126 L1.132 L1.128 ind1 1 1 0 ind3 1 0 1

(correctly excluding ind4, but incorrectly excluding ind2 !)

genind.obj@loc.n.all (read in with NA.char="-9") gives:

genind.obj@tab L1.126 L1.132 L1.118 L1.120 L1.128 L1.0 ind1 1 1 0 0 0 0 ind2 0 0 1 1 0 0 ind3 1 0 0 0 1 0 ind4 0 0 0 0 0 2

(now of course listing "0" as an allele, but correctly not ignoring the "120" allele of ind2)

Could this be a bug? I know that the help file gives the note that "... in any case, series of zero (like "000") are interpreted as NA too". But that does not really cover those cases where alleles themselves are coded with 0s as part of their length, as in Microsats with length 120.

I guess the best workaround is to always use "-9" as NA-character in input files. Any thoughts/comments ?

I also want to say Thanks for the great work on this package! It's really awesome what has been put together here by Thibaut.

Best, gregor rolshausen