thibautjombart/adegenet

Error in glPca(gl.fish, nf = 3, parallel = TRUE) : NAs detected in the vector of means

OmidJa opened this issue · 9 comments

Hello,
Actually I am working on a vcf file generated from GBS data of some fish populations. So, in R the vcf file was converted to a genelight object through the function vcfR2genelight. Now I wan to perform a PCA using glpca but when I run my command it shows me the following error:

Error in glPca(gl.fish, nf = 3, parallel = TRUE) : NAs detected in the vector of means

So I will be grateful to direct me how to replace the NAs with like mean values so that the final file or object is still a genelight object. I am telling this because I tried another way using tab function but changes the type of object so that it is not genelight and can not be processed by glpca.
Here is the command that I used for replacing and the following error received after running again the glpca.

> gl.fish2= tab(gl.fish, NA.method="mean", freq=TRUE)
> fish.pca= glPca(gl.fish2, nf = 3, parallel=TRUE)
Error in glPca(gl.omid3, nf = 3, parallel = TRUE) :
  x is not a genlight object

Thank you very much in advance.

Regards,
Omid

Result of tab is a matrix whereas glPca requires a genlight object.

Result of tab is a matrix whereas glPca requires a genlight object.

So how should we get over the mentioned error?
(Error in glPca(gl.fish, nf = 3, parallel = TRUE) : NAs detected in the vector of means)

Try coercing the imputed gl.fish2 to a genlight object. See examples in the genlight-class.

gl.fish2

Thank you for your direction.

I have met the same problem with him ( Error in glPca(gl.rubi, nf = 3) : NAs detected in the vector of means), but my problem is more strange. I have seven different data, five of them are ok while other two are not and with this error, all of them are transform with gl.rubi <- vcfR2genlight(rubi.VCF). I also check the input file, not any clearly difference be found between them. how can i do to solve this problem?

I have met the same problem with him ( Error in glPca(gl.rubi, nf = 3) : NAs detected in the vector of means), but my problem is more strange. I have seven different data, five of them are ok while other two are not and with this error, all of them are transform with gl.rubi <- vcfR2genlight(rubi.VCF). I also check the input file, not any clearly difference be found between them. how can i do to solve this problem?

Hello dear,
The following procedure worked for me regarding the NA values. Hope it will be effective for you, too.

toRemove <- is.na(glMean(a, alleleAsUnit = FALSE)) # TRUE where NA
which(toRemove) # position of entirely non-typed loci
b <- a[, !toRemove]
glPca(b)

Cheers,

ok,it works. Thank you

Thank you for finding a solution @OmidJa. I think it's reasonable for the glPca() function to do this automatically. Would you like to see that feature?

Additionally, can this issue be closed?

I will be grateful dear @zkamvar if you can let me know. Sure, I think it should be closed.

Cheers,