Skip to content
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

error import vcf to hierfstat #74

Closed
didier-aurelle opened this issue Nov 7, 2024 · 18 comments
Closed

error import vcf to hierfstat #74

didier-aurelle opened this issue Nov 7, 2024 · 18 comments

Comments

@didier-aurelle
Copy link

Hi,
I tried to import a vcf file to be analysed with hierfstat as follows:

read population definition file

popsEunicella <- read.csv("poplist_denovo_SNPfiltr.txt", sep = "", header = TRUE)

import vcf file

data <- read.vcf("RAD_spec_denovo_SNPfiltr.vcf")
data_genind <- loci2genind(data)
pop(data_genind) <- popsEunicella$POP
data_hierfstat <- genind2hierfstat(data_genind)

try to compute basic stats

bs_stats <- basic.stats(data_hierfstat, diploid = TRUE)

But when I try to compute some statistics, I get this error:

Erreur dans Class@package :
no applicable method for @ applied to an object of class "NULL"

Is there any mistake in my import?
Thanks
Didier

@jgx65
Copy link
Owner

jgx65 commented Nov 8, 2024

Dear Didier, could you check the structure of your data object (str(data))? hierfstat::read.VCFor gaston::read.vcf creates gaston bed object . If you use pegas perhaps the problem is from this side?

Also the results of str(data_hierfstat) would be useful

Cheers

@didier-aurelle
Copy link
Author

Hi Jérôme
thanks for your answer

So here are the results of the structure of the data (just the beginning in each case):

str(data)

Classes ‘loci’ and 'data.frame': 67 obs. of 10000 variables:
$ loc5_pos1 : Factor w/ 3 levels "C/C","./.","G/G": 1 1 1 1 2 1 1 1 1 1 ...
$ loc6_pos80 : Factor w/ 4 levels "A/A","G/A","G/G",..: 1 2 1 2 1 1 1 1 1 1 ...
$ loc7_pos69 : Factor w/ 5 levels "C/C","T/C","./.",..: 1 2 2 3 2 2 1 1 2 1 ...
$ loc8_pos8 : Factor w/ 3 levels "G/T","G/G","./.": 1 2 1 2 2 1 1 2 2 2 ...
$ loc10_pos5 : Factor w/ 5 levels "C/C","./.","T/C",..: 1 2 3 4 4 4 1 3 4 4 ...
$ loc12_pos0 : Factor w/ 3 levels "G/G","./.","G/A": 1 1 2 1 1 1 1 1 2 1 ...
$ loc14_pos122 : Factor w/ 5 levels "C/C","A/A","C/A",..: 1 2 2 2 2 2 2 3 1 2 ...
$ loc15_pos13 : Factor w/ 3 levels "T/T","./.","G/G": 1 2 1 2 1 2 1 1 1 1 ...
$ loc16_pos62 : Factor w/ 3 levels "T/T","./.","T/C": 1 2 1 2 1 1 1 1 1 1 ...
$ loc18_pos31 : Factor w/ 3 levels "G/G","./.","G/A": 1 2 1 1 1 1 1 1 1 1 ...
$ loc21_pos6 : Factor w/ 3 levels "T/T","T/C","C/C": 1 1 1 1 1 1 1 1 1 1 ...
$ loc23_pos62 : Factor w/ 5 levels "G/G","./.","G/A",..: 1 2 3 4 3 5 5 3 2 2 ...
$ loc25_pos14 : Factor w/ 5 levels "T/T","T/C","./.",..: 1 2 1 1 2 2 1 3 1 1 ...
$ loc27_pos27 : Factor w/ 3 levels "T/T","./.","T/C": 1 2 1 1 1 1 1 1 1 1 ...
$ loc28_pos21 : Factor w/ 5 levels "G/G","./.","G/T",..: 1 1 1 2 1 1 1 1 1 1 ...
$ loc34_pos9 : Factor w/ 4 levels "A/A","./.","G/A",..: 1 2 1 1 1 1 1 3 1 2 ...
$ loc35_pos96 : Factor w/ 5 levels "T/T","T/C","C/C",..: 1 1 2 1 1 2 1 1 2 1 ...
$ loc36_pos41 : Factor w/ 4 levels "T/T","./.","C/C",..: 1 2 1 1 3 2 1 1 1 1 ...
$ loc38_pos2 : Factor w/ 4 levels "G/G","./.","G/T",..: 1 2 1 1 1 1 1 1 1 1 ...
$ loc43_pos37 : Factor w/ 2 levels "G/G","G/A": 1 1 1 1 1 1 1 1 1 1 ...

str(data_hierfstat)

'data.frame': 67 obs. of 10001 variables:
$ pop : Factor w/ 4 levels "hybrid","cavolini",..: 1 1 1 1 1 1 1 1 1 2 ...
$ loc5_pos1 : int 22 22 22 22 NA 22 22 22 22 22 ...
$ loc6_pos80 : int 11 13 11 13 11 11 11 11 11 11 ...
$ loc7_pos69 : int 22 24 24 NA 24 24 22 22 24 22 ...
$ loc8_pos8 : int 34 33 34 33 33 34 34 33 33 33 ...
$ loc10_pos5 : int 22 NA 24 44 44 44 22 24 44 44 ...
$ loc12_pos0 : int 33 33 NA 33 33 33 33 33 NA 33 ...
$ loc14_pos122 : int 22 11 11 11 11 11 11 21 22 11 ...
$ loc15_pos13 : int 44 NA 44 NA 44 NA 44 44 44 44 ...
$ loc16_pos62 : int 44 NA 44 NA 44 44 44 44 44 44 ...
$ loc18_pos31 : int 33 NA 33 33 33 33 33 33 33 33 ...
$ loc21_pos6 : int 44 44 44 44 44 44 44 44 44 44 ...
$ loc23_pos62 : int 33 NA 31 NA 31 11 11 31 NA NA ...
$ loc25_pos14 : int 44 42 44 44 42 42 44 NA 44 44 ...
$ loc27_pos27 : int 44 NA 44 44 44 44 44 44 44 44 ...
$ loc28_pos21 : int 33 33 33 NA 33 33 33 33 33 33 ...
$ loc34_pos9 : int 11 NA 11 11 11 11 11 13 11 NA ...
$ loc35_pos96 : int 44 44 42 44 44 42 44 44 42 44 ...
$ loc36_pos41 : int 44 NA 44 44 22 NA 44 44 44 44 ...
$ loc38_pos2 : int 33 NA 33 33 33 33 33 33 33 33 ...
$ loc43_pos37 : int 33 33 33 33 33 33 33 33 33 33 ...
$ loc44_pos51 : int 42 44 44 44 44 44 44 44 44 44 ...

I tried with gaston as follows:

data2 <- read.VCF("RAD_spec_denovo_SNPfiltr.vcf", convert.chr = FALSE)

I got this file, but how can I use it with hierfstat now?

str(data2)

Formal class 'bed.matrix' [package "gaston"] with 8 slots
..@ ped :'data.frame': 67 obs. of 30 variables:
.. ..$ famid : chr [1:67] "EC-X-MFNB" "EC-X-MFNC" "EC-X-MFND" "EC-X-MFNE" ...
.. ..$ id : chr [1:67] "EC-X-MFNB" "EC-X-MFNC" "EC-X-MFND" "EC-X-MFNE" ...
.. ..$ father : num [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ mother : num [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ sex : num [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ pheno : logi [1:67] NA NA NA NA NA NA ...
.. ..$ N0 : int [1:67] 12622 7535 12816 11912 12045 12561 12749 12333 12432 11523 ...
.. ..$ N1 : int [1:67] 2223 1259 2075 2091 2091 1984 2097 2601 2655 1649 ...
.. ..$ N2 : int [1:67] 641 399 709 673 616 703 729 428 420 936 ...
.. ..$ NAs : int [1:67] 876 7169 762 1686 1610 1114 787 1000 855 2254 ...
.. ..$ N0.x : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N1.x : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N2.x : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ NAs.x : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N0.y : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N1.y : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N2.y : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ NAs.y : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N0.mt : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N1.mt : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ N2.mt : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ NAs.mt : int [1:67] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ callrate : num [1:67] -Inf -Inf -Inf -Inf -Inf ...
.. ..$ hz : num [1:67] -2.538 -0.176 -2.723 -1.24 -1.299 ...
.. ..$ callrate.x : num [1:67] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
.. ..$ hz.x : num [1:67] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
.. ..$ callrate.y : num [1:67] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
.. ..$ hz.y : num [1:67] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
.. ..$ callrate.mt: num [1:67] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
.. ..$ hz.mt : num [1:67] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
..@ snps :'data.frame': 16362 obs. of 19 variables:
.. ..$ chr : chr [1:16362] "RAD_5" "RAD_6" "RAD_7" "RAD_8" ...
.. ..$ id : chr [1:16362] "loc5_pos1" "loc6_pos80" "loc7_pos69" "loc8_pos8" ...
.. ..$ dist : num [1:16362] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ pos : int [1:16362] 2 81 70 9 6 1 123 14 63 32 ...
.. ..$ A1 : chr [1:16362] "C" "A" "C" "G" ...
.. ..$ A2 : chr [1:16362] "G" "G" "T" "T" ...
.. ..$ quality : num [1:16362] 13 13 13 13 13 13 13 13 13 13 ...
.. ..$ filter : Factor w/ 1 level "PASS": 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ N0 : int [1:16362] 54 51 23 55 24 56 52 48 58 58 ...
.. ..$ N1 : int [1:16362] 0 8 25 10 15 3 1 0 4 3 ...
.. ..$ N2 : int [1:16362] 4 3 15 0 23 0 4 7 0 0 ...
.. ..$ NAs : int [1:16362] 9 5 4 2 5 8 10 12 5 6 ...
.. ..$ N0.f : int [1:16362] NA NA NA NA NA NA NA NA NA NA ...
.. ..$ N1.f : int [1:16362] NA NA NA NA NA NA NA NA NA NA ...
.. ..$ N2.f : int [1:16362] NA NA NA NA NA NA NA NA NA NA ...
.. ..$ NAs.f : int [1:16362] NA NA NA NA NA NA NA NA NA NA ...
.. ..$ callrate: num [1:16362] 0.866 0.925 0.94 0.97 0.925 ...
.. ..$ maf : num [1:16362] 0.069 0.1129 0.4365 0.0769 0.4919 ...
.. ..$ hz : num [1:16362] 0 0.129 0.397 0.154 0.242 ...
..@ bed :
..@ p : num [1:16362] 0.069 0.1129 0.4365 0.0769 0.4919 ...
..@ mu : num [1:16362] 0.138 0.226 0.873 0.154 0.984 ...
..@ sigma : num [1:16362] 0.475 0.505 0.749 0.358 0.844 ...
..@ standardize_p : logi FALSE
..@ standardize_mu_sigma: logi FALSE

Didier

@jgx65
Copy link
Owner

jgx65 commented Nov 8, 2024

Thanks Didier.

So data_hierfstat has the correct structure for analyses with basic.stats. Where you able to obtain results from this function?

With data2, you can use fs.dosage(data2, pop=popsEunicella$POP) to obtain individuals and populations Fs

Best wishes

@didier-aurelle
Copy link
Author

Thanks, it works with the fs.dosage function after import with gaston.
I would like to compute some population heterozygosities as well if possible.
With the data_hierfstat (after import with read.vcf from pegas then), basic.stats gives the error:

Erreur dans Class@package :
no applicable method for @ applied to an object of class "NULL"

Thanks!
Didier

@jgx65
Copy link
Owner

jgx65 commented Nov 8, 2024

Could you send a toy example dataset reproducing the error please? perhaps something like basic.stats(data_hierfstat[,1:30])? Alternatively, you can get nucleotide diversity from dosage data (pi.dosage), and if you pass for the argument L the number of SNPs, you will obtain heterozygosities

Cheers

@didier-aurelle
Copy link
Author

yes, here is a subsampled dataset, which still gets the error
thanks
Didier

"" "pop" "loc5_pos1" "loc6_pos80" "loc7_pos69" "loc8_pos8" "loc10_pos5" "loc12_pos0" "loc14_pos122" "loc15_pos13" "loc16_pos62" "loc18_pos31" "loc21_pos6" "loc23_pos62" "loc25_pos14" "loc27_pos27" "loc28_pos21" "loc34_pos9" "loc35_pos96" "loc36_pos41" "loc38_pos2" "loc43_pos37" "loc44_pos51" "loc45_pos16" "loc46_pos7" "loc50_pos30" "loc53_pos31" "loc55_pos61" "loc57_pos12" "loc62_pos7" "loc65_pos1" "loc67_pos8"
"EC-X-MFNB" "hybrid" 22 11 22 34 22 33 22 44 44 33 44 33 44 44 33 11 44 44 33 33 42 33 22 22 11 33 22 22 44 22
"EC-X-MFNC" "hybrid" 22 13 24 33 NA 33 11 NA NA NA 44 NA 42 NA 33 NA 44 NA NA 33 44 NA 22 NA NA NA NA 22 44 22
"EC-X-MFND" "hybrid" 22 11 24 34 24 NA 11 44 44 33 44 31 44 44 33 11 42 44 33 33 44 33 22 23 NA 33 22 22 44 22
"EC-X-MFNE" "hybrid" 22 13 NA 33 44 33 11 NA NA 33 44 NA 44 44 NA 11 44 44 33 33 44 33 22 22 NA 33 22 NA 44 22
"EC-X-MFNF" "hybrid" NA 11 24 33 44 33 11 44 44 33 44 31 42 44 33 11 44 22 33 33 44 33 22 22 11 33 22 22 44 22
"EC-X-MFNG" "hybrid" 22 11 24 34 44 33 11 NA 44 33 44 11 42 44 33 11 42 NA 33 33 44 33 22 22 11 NA 22 22 44 22
"EC-X-MFNH" "hybrid" 22 11 22 34 22 33 11 44 44 33 44 11 44 44 33 11 44 44 33 33 44 33 22 23 11 33 22 22 44 22
"EC-X-MFNI" "hybrid" 22 11 22 33 24 33 21 44 44 33 44 31 NA 44 33 13 44 44 33 33 44 33 22 33 11 33 NA 22 44 22
"EC-X-MFNL" "hybrid" 22 11 24 33 44 NA 22 44 44 33 44 NA 44 44 33 11 42 44 33 33 44 33 22 23 11 33 22 22 44 21
"ECESC37" "cavolini" 22 11 22 33 44 33 11 44 44 33 44 NA 44 44 33 NA 44 44 33 33 44 33 22 22 NA 33 NA 22 44 22
"ECESC38" "cavolini" 22 11 22 33 44 33 11 44 44 33 44 11 44 44 33 NA 44 44 33 33 22 33 22 22 11 33 22 22 44 22
"ECESC39" "cavolini" 22 33 22 33 44 33 11 44 44 33 44 11 NA 44 33 11 44 44 33 33 44 33 NA 23 11 33 22 22 44 22
"ECMEL37" "cavolini" 22 NA 22 34 44 33 11 44 44 33 44 11 44 44 33 11 44 44 33 33 44 33 22 23 13 33 22 22 44 22
"ECPLD22" "cavolini" 22 11 22 33 44 33 11 44 44 33 44 11 44 44 33 11 44 44 33 33 44 33 22 22 11 33 22 22 44 22
"ECPLD23" "cavolini" NA 11 24 33 22 NA 11 44 44 33 44 31 44 44 33 11 44 44 33 33 44 33 22 22 11 33 22 22 44 22
"ECPLD24" "cavolini" 22 11 22 33 22 33 NA 44 44 33 44 11 44 44 33 13 44 44 33 33 44 33 22 23 11 33 22 22 44 22
"ECPLD25" "cavolini" 22 13 22 33 24 33 NA NA 44 33 44 11 44 44 33 33 44 44 33 33 44 NA 22 22 11 33 22 22 44 22
"ECPLD26" "cavolini" 22 13 24 33 24 NA 11 44 44 33 44 31 44 44 33 11 44 44 33 33 44 33 22 33 11 33 22 22 44 22
"ECPLD38" "cavolini" 22 11 44 33 44 33 11 44 44 33 44 11 44 44 33 11 44 44 33 33 44 33 22 33 11 33 22 22 44 22
"ECPLD39" "cavolini" 22 NA 22 33 24 33 11 44 NA 33 44 11 44 NA 33 13 44 44 33 31 44 33 22 23 11 33 22 NA 44 22
"ECRID13" "cavolini" NA 11 44 33 24 33 11 44 NA 33 44 11 44 44 33 11 44 22 33 33 44 33 22 23 11 33 22 22 44 22
"ECRID14" "cavolini" 22 13 NA 33 24 33 11 44 44 33 44 11 44 44 33 11 44 44 33 33 44 33 22 23 NA 33 22 22 44 22
"ECRID15" "cavolini" NA 11 24 33 44 33 11 44 44 33 44 31 44 44 33 11 44 44 33 33 44 33 22 22 11 33 22 22 44 22
"ECRID16" "cavolini" 22 33 24 33 44 33 11 44 44 33 44 11 44 NA 33 11 44 44 33 33 44 NA 22 33 13 33 22 22 NA 22
"ECRID17" "cavolini" 22 11 24 33 44 33 11 44 44 33 44 11 44 44 33 11 44 NA 33 33 44 33 22 23 13 33 22 22 44 22
"ECRID19" "cavolini" 22 13 24 33 24 33 11 44 44 NA 44 11 44 44 33 11 44 44 33 33 44 33 22 22 11 33 22 22 44 22
"ECRID20" "cavolini" NA 11 44 33 22 33 11 44 44 33 44 33 44 44 33 11 44 44 33 33 44 NA 22 NA 33 33 22 22 44 22
"ECRID21" "cavolini" 22 13 22 NA 22 NA 11 44 44 33 44 11 44 44 33 NA 44 42 33 33 42 33 22 33 11 33 22 22 44 22
"ECRID22" "cavolini" NA 11 24 33 NA 33 11 44 44 33 44 11 44 44 33 13 44 44 33 33 42 33 22 23 11 33 22 22 44 22
"ECRID23" "cavolini" 22 33 22 33 44 33 11 NA 44 33 44 11 44 44 33 11 44 44 33 33 42 33 22 33 NA 33 22 22 44 22
"ECRID25" "cavolini" 22 11 24 33 24 33 11 44 44 NA 44 11 44 44 33 11 44 44 33 33 42 33 22 33 13 33 22 22 44 22
"ECRID27" "cavolini" 22 11 44 33 24 33 11 44 44 33 44 11 44 44 33 11 44 NA 33 33 44 33 22 33 11 33 22 22 NA NA
"ECRID28" "cavolini" 22 11 24 33 24 33 11 44 44 33 44 11 44 44 33 11 44 NA 33 33 44 33 22 23 11 33 22 22 NA 22
"ECRID29" "cavolini" 22 11 24 33 44 33 11 44 44 33 44 31 44 44 33 11 44 42 33 33 44 33 22 33 11 33 22 22 44 22
"ES-X-MFNA" "hybrid" 22 11 24 34 24 33 11 NA 44 33 44 33 NA 44 33 11 44 44 33 33 44 33 22 23 13 33 22 22 44 22
"ES-X-MFNJ" "hybrid" 22 11 22 33 24 NA NA 44 44 33 44 31 44 44 33 13 42 44 33 31 42 NA 22 NA 11 33 22 22 44 21
"ES-X-MFNK" "hybrid" 22 11 44 34 22 NA NA 44 44 33 44 33 44 44 34 11 44 44 33 33 44 33 22 22 11 33 22 22 44 22
"ESFRO10" "singularis" 22 13 22 33 24 33 NA NA 44 33 44 33 42 44 33 11 42 42 33 33 44 33 22 33 11 NA 22 22 44 22
"ESFRO11" "singularis" 22 11 22 33 22 33 NA 44 44 33 44 33 44 44 33 11 42 42 33 33 44 33 22 22 11 33 NA 22 44 22
"ESFRO12" "singularis" NA 11 24 33 22 33 NA 44 44 33 44 33 44 44 33 11 42 44 33 33 44 33 22 22 11 33 22 22 44 22
"ESFRO13" "singularis" 22 11 44 33 22 33 11 NA 44 33 44 33 42 44 33 11 44 44 33 33 44 33 22 22 11 33 22 NA 44 22
"ESFRO14" "singularis" NA NA 24 33 22 33 11 44 44 33 44 31 42 44 34 11 22 22 33 33 44 31 22 22 11 33 22 22 44 22
"ESFRO15" "singularis" NA 11 24 33 22 33 11 44 44 33 44 33 NA 44 33 11 42 44 33 33 44 33 22 22 11 33 22 22 44 22
"ESFRO2" "singularis" 22 11 22 33 22 33 22 44 44 33 44 33 42 44 34 11 42 44 33 33 44 33 22 22 11 33 22 NA 44 22
"ESFRO3" "singularis" 22 11 22 33 22 33 11 NA NA 33 44 33 44 NA 33 11 42 44 33 33 44 33 22 22 NA 33 NA 22 44 22
"ESFRO5" "singularis" 22 11 44 33 22 33 22 44 44 33 44 33 NA 44 33 13 44 42 33 33 44 NA 22 23 11 33 NA 22 44 22
"ESFRO6" "singularis" 22 11 NA 33 24 33 11 NA 44 33 44 31 44 44 33 11 42 44 33 33 44 33 22 22 11 33 22 22 44 22
"ESFRO7" "singularis" 22 11 22 34 22 33 11 44 44 33 44 33 NA 44 33 11 NA 42 33 33 44 33 NA 22 11 33 22 22 44 22
"ESFRO8" "singularis" 22 11 22 33 22 31 11 NA 44 33 44 33 44 44 33 11 44 42 33 33 44 33 22 22 NA 33 22 22 44 21
"ESFRO9" "singularis" 22 11 24 NA 22 33 11 44 44 33 44 31 NA 44 33 11 44 42 33 33 44 33 22 22 11 33 22 22 44 22
"ESSFI1" "singularis" 22 11 24 33 NA 33 NA 44 44 33 44 33 44 44 33 11 22 44 33 31 44 33 22 22 11 NA 22 22 44 22
"ESSFI10" "singularis" 22 11 24 33 22 33 11 44 44 33 44 33 44 44 33 11 44 42 33 33 44 33 22 NA 11 33 22 NA 44 22
"ESSFI2" "singularis" 22 11 22 33 22 33 11 44 44 33 44 33 NA 44 33 11 44 44 33 33 44 33 22 NA 11 33 NA 22 44 22
"ESSFI3" "singularis" 22 11 44 33 22 33 11 44 44 31 44 33 44 44 33 11 44 42 33 33 44 NA 22 22 11 33 22 22 NA 22
"ESSFI4" "singularis" 22 11 44 33 NA NA 11 44 44 NA 44 33 NA 44 33 11 44 22 33 33 44 NA 22 NA 11 33 22 22 44 22
"ESSFI5" "singularis" 22 11 44 34 22 33 11 44 44 33 44 33 44 44 33 11 44 22 33 33 44 33 NA 22 11 33 22 22 44 NA
"ESSFI6" "singularis" 22 11 22 33 22 31 11 44 44 31 44 33 22 44 33 11 44 42 33 33 44 31 22 NA 11 NA 22 NA 44 22
"ESSFI7" "singularis" 22 11 24 34 44 31 11 44 44 31 44 33 42 44 33 11 42 42 33 33 44 NA 22 22 11 33 22 22 44 NA
"ESSFI8" "singularis" 22 NA 24 33 NA 33 NA NA 44 NA 44 33 42 44 NA 11 NA 44 33 33 44 31 22 NA NA 33 NA NA 44 22
"ESSFI9" "singularis" 22 11 24 33 22 33 NA 44 44 33 44 31 44 44 33 NA 44 44 33 31 44 33 22 22 NA 33 22 22 NA 22
"EVCSO2" "verrucosa" 33 NA 44 33 44 33 11 33 42 33 42 33 42 44 44 11 44 44 34 33 44 33 NA 33 11 11 NA NA 41 22
"EVCSO4" "verrucosa" 22 11 22 33 44 33 11 33 42 33 42 NA 44 42 44 NA 44 44 33 33 44 33 NA 33 11 11 24 33 41 22
"EVFRO1" "verrucosa" 33 11 44 33 44 33 11 33 42 33 44 33 44 44 44 11 44 44 33 33 44 33 21 33 11 11 44 33 44 22
"EVFRO2" "verrucosa" 33 11 44 33 44 33 11 33 44 NA 22 33 44 44 NA 11 44 44 33 33 44 33 21 NA 11 11 44 33 44 22
"EVFRO3" "verrucosa" 22 11 NA 33 44 33 11 33 42 33 22 33 44 44 44 11 44 44 33 33 44 33 22 33 11 11 NA 33 41 22
"EVFRO4" "verrucosa" 33 11 44 33 44 33 11 33 44 33 42 33 44 44 44 11 44 NA NA 33 44 33 21 33 11 11 44 33 41 22
"EVFRO5" "verrucosa" 22 11 44 33 44 33 11 33 44 33 44 NA 44 42 44 11 44 44 33 33 44 NA 21 33 11 11 44 NA NA 22

@jgx65
Copy link
Owner

jgx65 commented Nov 8, 2024

aurelle_toy.txt
It works for me:

> dat<-read.table("aurelle_toy.txt",header=TRUE)
> str(dat)
'data.frame':	67 obs. of  31 variables:
 $ pop         : chr  "hybrid" "hybrid" "hybrid" "hybrid" ...
 $ loc5_pos1   : int  22 22 22 22 NA 22 22 22 22 22 ...
 $ loc6_pos80  : int  11 13 11 13 11 11 11 11 11 11 ...
 $ loc7_pos69  : int  22 24 24 NA 24 24 22 22 24 22 ...
 $ loc8_pos8   : int  34 33 34 33 33 34 34 33 33 33 ...
 $ loc10_pos5  : int  22 NA 24 44 44 44 22 24 44 44 ...
 $ loc12_pos0  : int  33 33 NA 33 33 33 33 33 NA 33 ...
 $ loc14_pos122: int  22 11 11 11 11 11 11 21 22 11 ...
 $ loc15_pos13 : int  44 NA 44 NA 44 NA 44 44 44 44 ...
 $ loc16_pos62 : int  44 NA 44 NA 44 44 44 44 44 44 ...
 $ loc18_pos31 : int  33 NA 33 33 33 33 33 33 33 33 ...
 $ loc21_pos6  : int  44 44 44 44 44 44 44 44 44 44 ...
 $ loc23_pos62 : int  33 NA 31 NA 31 11 11 31 NA NA ...
 $ loc25_pos14 : int  44 42 44 44 42 42 44 NA 44 44 ...
 $ loc27_pos27 : int  44 NA 44 44 44 44 44 44 44 44 ...
 $ loc28_pos21 : int  33 33 33 NA 33 33 33 33 33 33 ...
 $ loc34_pos9  : int  11 NA 11 11 11 11 11 13 11 NA ...
 $ loc35_pos96 : int  44 44 42 44 44 42 44 44 42 44 ...
 $ loc36_pos41 : int  44 NA 44 44 22 NA 44 44 44 44 ...
 $ loc38_pos2  : int  33 NA 33 33 33 33 33 33 33 33 ...
 $ loc43_pos37 : int  33 33 33 33 33 33 33 33 33 33 ...
 $ loc44_pos51 : int  42 44 44 44 44 44 44 44 44 44 ...
 $ loc45_pos16 : int  33 NA 33 33 33 33 33 33 33 33 ...
 $ loc46_pos7  : int  22 22 22 22 22 22 22 22 22 22 ...
 $ loc50_pos30 : int  22 NA 23 22 22 22 23 33 23 22 ...
 $ loc53_pos31 : int  11 NA NA NA 11 11 11 11 11 NA ...
 $ loc55_pos61 : int  33 NA 33 33 33 NA 33 33 33 33 ...
 $ loc57_pos12 : int  22 NA 22 22 22 22 22 NA 22 NA ...
 $ loc62_pos7  : int  22 22 22 NA 22 22 22 22 22 22 ...
 $ loc65_pos1  : int  44 44 44 44 44 44 44 44 44 44 ...
 $ loc67_pos8  : int  22 22 22 22 22 22 22 22 21 22 ...
> bs<-basic.stats(dat)
> bs
$perloc
                 Ho     Hs     Ht     Dst    Htp    Dstp     Fst
loc5_pos1    0.0000 0.1336 0.2477  0.1141 0.2857  0.1521  0.4606
loc6_pos80   0.1079 0.1489 0.1602  0.0113 0.1639  0.0151  0.0705
loc7_pos69   0.3428 0.4489 0.5060  0.0571 0.5250  0.0761  0.1128
loc8_pos8    0.1695 0.1400 0.1562  0.0162 0.1616  0.0216  0.1035
loc10_pos5   0.2097 0.2991 0.4933  0.1942 0.5581  0.2589  0.3936
loc12_pos0   0.0341 0.0332 0.0339  0.0007 0.0341  0.0009  0.0194
loc14_pos122 0.0250 0.1582 0.1701  0.0118 0.1740  0.0158  0.0696
loc15_pos13  0.0000 0.0000 0.3750  0.3750 0.5000  0.5000  1.0000
loc16_pos62  0.1429 0.1048 0.1333  0.0285 0.1429  0.0380  0.2140
loc18_pos31  0.0357 0.0346 0.0354  0.0008 0.0357  0.0011  0.0231
loc21_pos6   0.1071 0.1310 0.2202  0.0893 0.2500  0.1190  0.4052
loc23_pos62  0.1963 0.2310 0.4592  0.2282 0.5353  0.3043  0.4970
loc25_pos14  0.1989 0.1951 0.2043  0.0093 0.2074  0.0123  0.0453
loc27_pos27  0.0714 0.0635 0.0694  0.0060 0.0714  0.0080  0.0860
loc28_pos21  0.0455 0.0453 0.3972  0.3519 0.5145  0.4691  0.8859
loc34_pos9   0.0909 0.1083 0.1085  0.0003 0.1086  0.0004  0.0026
loc35_pos96  0.1786 0.1785 0.2024  0.0239 0.2103  0.0318  0.1180
loc36_pos41  0.1314 0.2128 0.2364  0.0235 0.2442  0.0314  0.0996
loc38_pos2   0.0417 0.0398 0.0412  0.0014 0.0417  0.0019  0.0337
loc43_pos37  0.0526 0.0526 0.0517 -0.0009 0.0514 -0.0012 -0.0173
loc44_pos51  0.0817 0.0952 0.0976  0.0023 0.0983  0.0031  0.0241
loc45_pos16  0.0395 0.0380 0.0391  0.0011 0.0395  0.0014  0.0278
loc46_pos7   0.2000 0.1221 0.1805  0.0585 0.2000  0.0779  0.3238
loc50_pos30  0.2076 0.2844 0.5030  0.2186 0.5758  0.2914  0.4345
loc53_pos31  0.0732 0.0898 0.0925  0.0027 0.0934  0.0036  0.0295
loc55_pos61  0.0000 0.0000 0.3750  0.3750 0.5000  0.5000  1.0000
loc57_pos12  0.0500 0.0472 0.3493  0.3021 0.4500  0.4028  0.8649
loc62_pos7   0.0000 0.0000 0.3750  0.3750 0.5000  0.5000  1.0000
loc65_pos1   0.1667 0.1137 0.1534  0.0397 0.1667  0.0529  0.2588
loc67_pos8   0.0536 0.0518 0.0526  0.0008 0.0529  0.0011  0.0160
                Fstp     Fis    Dest
loc5_pos1     0.5324  1.0000  0.1756
loc6_pos80    0.0918  0.2751  0.0177
loc7_pos69    0.1449  0.2364  0.1380
loc8_pos8     0.1335 -0.2104  0.0251
loc10_pos5    0.4640  0.2991  0.3695
loc12_pos0    0.0256 -0.0263  0.0009
loc14_pos122  0.0907  0.8420  0.0188
loc15_pos13   1.0000     NaN  0.5000
loc16_pos62   0.2663 -0.3630  0.0425
loc18_pos31   0.0305 -0.0315  0.0011
loc21_pos6    0.4760  0.1821  0.1369
loc23_pos62   0.5685  0.1504  0.3957
loc25_pos14   0.0595 -0.0198  0.0153
loc27_pos27   0.1115 -0.1255  0.0085
loc28_pos21   0.9119 -0.0028  0.4914
loc34_pos9    0.0035  0.1603  0.0004
loc35_pos96   0.1514 -0.0005  0.0388
loc36_pos41   0.1285  0.3825  0.0399
loc38_pos2    0.0445 -0.0466  0.0019
loc43_pos37  -0.0233  0.0004 -0.0013
loc44_pos51   0.0318  0.1422  0.0035
loc45_pos16   0.0367 -0.0381  0.0015
loc46_pos7    0.3897 -0.6386  0.0888
loc50_pos30   0.5061  0.2699  0.4072
loc53_pos31   0.0389  0.1845  0.0040
loc55_pos61   1.0000     NaN  0.5000
loc57_pos12   0.8951 -0.0592  0.4228
loc62_pos7    1.0000     NaN  0.5000
loc65_pos1    0.3177 -0.4656  0.0597
loc67_pos8    0.0212 -0.0344  0.0012

$overall
    Ho     Hs     Ht    Dst    Htp   Dstp    Fst   Fstp    Fis 
0.1018 0.1201 0.2173 0.0973 0.2498 0.1297 0.4476 0.5193 0.1520 
  Dest 
0.1474 

@didier-aurelle
Copy link
Author

Very strange: I reinstalled the packages, downloaded your file (my toy file!), imported with read.table and it works!
but with the original file, I still get the error... I will try to workaround with the ped format
thanks
Didier

@jgx65
Copy link
Owner

jgx65 commented Nov 8, 2024

Perhaps try saving your file as text and reimport it?
Best

@didier-aurelle
Copy link
Author

Yes, I tried but it didn't work. Maybe this is link to the OS? I work on Linux
thanks

@jgx65
Copy link
Owner

jgx65 commented Nov 8, 2024

I don't think the OS matters. Perhaps the first column, containing names (e.g. "EC-X-MFNB") is misinterpreted. try removing it, or removing the "" with write.table(data_hierfstat,file="test.txt",quote=FALSE,row.names=FALSE,sep="\t")

@jgx65
Copy link
Owner

jgx65 commented Nov 12, 2024

Hi @didier-aurelle , did you manage to solve the issue? If so, can I close it? Thanks!

@didier-aurelle
Copy link
Author

Hi
I have just tried to export in text and then reimport as you proposed, without sample names then, and it doesn't work. Still the same error
Erreur dans Class@package :
no applicable method for @ applied to an object of class "NULL"
Didier

@didier-aurelle
Copy link
Author

an update: some functions work. For example allele.count, allelic.richness,
Does not work for example: genet.dist, pop.freq
Didier

@jgx65
Copy link
Owner

jgx65 commented Nov 12, 2024

Could you send me a toy example (file+commands) in order for me to replicate the error?
Thanks!

@didier-aurelle
Copy link
Author

toy_30SNPs.vcf.txt
poplist_denovo_SNPfiltr.txt

Yes, I attach the vcf file (renamed .txt to allow attachment) and the pop definition file, the script is below
thanks
Didier

library(adegenet)
library(hierfstat)
library(pegas)

setwd("~/Nextcloud2/Speciation_Eunicella/RAD_speciation_reference/denovo/")

popsEunicella <- read.table("poplist_denovo_SNPfiltr.txt", header = TRUE)
popsEunicella2 <- as.factor(popsEunicella$POP)
View(popsEunicella)

read vcf file

data <- read.vcf("toy_30SNPs.vcf")
data_genind <- loci2genind(data)
data_genind$pop <- popsEunicella2
pop(data_genind)
data_hierfstat <- genind2hierfstat(data_genind)

bs_stats <- basic.stats(data_hierfstat, diploid = TRUE)

@jgx65
Copy link
Owner

jgx65 commented Nov 12, 2024

OK, I think I found the problem, it was in function hierfstat::pop.freq . I've pushed a new version to github. Try reinstalling hierfstat from github, and re-running, things should work.

Many thanks for pointing the issue, if you're happy with the results, you can close it

@didier-aurelle
Copy link
Author

Yes, it works now!
merci!
Didier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants