emmanuelparadis / pegas

Population and Evolutionary Genetics Analysis System
GNU General Public License v2.0
27 stars 10 forks source link

LD2 fails #50

Closed stuartwillis closed 3 years ago

stuartwillis commented 4 years ago

I'm trying to calculate LD among ~250 SNPs in a large (6k) sample of individuals. The data are converted from a dataframe by df2genind and then to loci as genind2loci. However, when I run LD2 on the any two loci, I get

$Delta C T A NA NA G NA NA

$T2 T2 df P-val NA 1 NA

As far as I can tell the formatting is the same as the "jaguar" dataset (which runs ok),

head(myloci$Ots28_11023212) [1] A/A A/A A/A A/A A/A A/A Levels: A/A A/G G/G

And clearly the SNP states are being transferred correctly. Any ideas?

emmanuelparadis commented 4 years ago

What does summary(myloci) return? It shoud return the allele and genotype frequencies for all loci.

If your initial data are in a data frame (say DF), you can simply do myloci <- as.loci(DF) (no need to go through a genind object).

stuartwillis commented 4 years ago

It looks like what I would expect, e.g.

Locus Ots_IL8R_C8 : -- Genotype frequencies: C/C C/T T/T 4448 1167 737 -- Allele frequencies: C T 10063 2641

Locus Ots_unk3513_49 : -- Genotype frequencies: C/C C/T T/T 522 2341 3494 -- Allele frequencies: C T 3385 9329

Turns out 'as.loci' throws an error, but cycling through genind was successful, though that may have something to do with my problem

myloci2<-as.loci(for_linkage,allele.sep = ",") summary(myloci2) Error in tabulate(object[[i]], ng) : 'bin' must be numeric or a factor

head(for_linkage[,1:5]) Ots_myoD_364 Ots_u07_25_325 Ots_redd1_187 Ots_129458_451 Ots_crRAD21115_24 OtsBonn18-042618-2.06 G,G T,T A,A T,C C,C OtsBonn18-042718-1.02 G,G T,T A,A C,C C,C OtsBonn18-042718-1.04 G,G T,C A,A C,C C,C OtsBonn18-042718-2.03 G,G T,T A,A C,C C,C OtsBonn18-042718-2.04 T,G T,C A,G C,C C,C OtsBonn18-042718-2.06 G,G T,C A,A C,C C,T

emmanuelparadis commented 4 years ago

I copied the lines after head(for_linkage[,1:5]), pasted them into a text file (x.txt) and the followings worked well for me:

R> x <- read.loci("x.txt", allele.sep = ",")
R> x
Allelic data frame: 6 individuals
                    5 loci
R> str(x)
Classes ‘loci’ and 'data.frame':    6 obs. of  5 variables:
 $ Ots_myoD_364     : Factor w/ 2 levels "G/G","G/T": 1 1 1 1 2 1
 $ Ots_u07_25_325   : Factor w/ 2 levels "C/T","T/T": 2 2 1 2 1 1
 $ Ots_redd1_187    : Factor w/ 2 levels "A/A","A/G": 1 1 1 1 2 1
 $ Ots_129458_451   : Factor w/ 2 levels "C/C","C/T": 2 1 1 1 1 1
 $ Ots_crRAD21115_24: Factor w/ 2 levels "C/C","C/T": 1 1 1 1 1 2
 - attr(*, "locicol")= int [1:5] 1 2 3 4 5
R> summary(x)

Locus Ots_myoD_364:
-- Genotype frequencies:
G/G G/T 
  5   1 
-- Allele frequencies:
 G  T 
11  1 

Locus Ots_u07_25_325:
-- Genotype frequencies:
..................................................... etc.................