Genetic differentiation in R, function genetic_diff()

96 Views Asked by At

I'm trying to run the function genetic_diff(): myDiff <- genetic_diff(vcf, pops = pop, method = 'nei')

But I get the following information " if(class(x) != "vcfR"){ stop(paste("Expecting an object of class vcfR, instead received", class(vcf)))"

What can I do?

1

There are 1 best solutions below

0
On BEST ANSWER

Presumably you have a vcfR file. Use the read.vcfR command to read it as a vcfR file, then you can successfully run the genetic_diff command. An example using the vcfR example file lumpy.vcf.

x=read.vcfR("filename.txt")
pop=as.factor(c("a", "a", "b"))
genetic_diff(x, pop, method="nei")

   CHROM      POS Hs_a Hs_b        Ht n_a n_b  Gst     Htmax    Gstmax Gprimest
1   chr1 93822813  0.5  0.0 0.4444444   4   2 0.25 0.6666667 0.5000000      0.5
2  chr12 71315481  0.5  NaN 0.5000000   4   0  NaN 0.5000000       NaN      NaN
3  chr12 71315764  0.5  NaN 0.5000000   4   0  NaN 0.5000000       NaN      NaN
4  chr12 71316537  0.5  NaN 0.5000000   4   0  NaN 0.5000000       NaN      NaN
5  chr12 71316539  0.5  NaN 0.5000000   4   0  NaN 0.5000000       NaN      NaN
6  chr13 33618456  0.5  0.5 0.5000000   2   2 0.00 0.7500000 0.3333333      0.0
7  chr15 70302685  0.5  NaN 0.5000000   4   0  NaN 0.5000000       NaN      NaN
8  chr16 25192730  0.5  0.5 0.5000000   4   2 0.00 0.7222222 0.3076923      0.0
9  chr16 25192895  0.5  0.5 0.5000000   4   2 0.00 0.7222222 0.3076923      0.0
10 chr16 25193026  0.5  0.5 0.5000000   4   2 0.00 0.7222222 0.3076923      0.0
11 chr16 25193261  0.5  0.5 0.5000000   4   2 0.00 0.7222222 0.3076923      0.0