jgx65 / hierfstat

the hierfstat package
24 stars 14 forks source link

pairwise.WCfst dim(X) must have a positive length #17

Closed pedrosenna closed 7 years ago

pedrosenna commented 8 years ago

Hi,

I have a dataset with 300 sequences from Dloop region (508pb) arranged in 17 populations. I'm trying to generate bootstrap matrices in order to use the Monmonier maximum difference algorithm. To do that i'm reading the file as fasta and then converting to genind, to keep only the polymorphic loci.

file <- read.dna("file.fasta", format = "fasta") file2 <- DNAbin2genind(file)

After that i set the populations using a factor:

pop <- factor(c(rep("pop1", number of individuals), ....)) file2@pop <- pop

And then i convert to hierfstat and use pairwise.WCfst:

file3 <- genind2hierfstat(file2) fst <- pairwise.WCfst(file3, diploid = "FALSE")

I'm having issues after generate those bootstrap matrices. I'm using genind2df in order to use the sample() function with replacement:

x <- as.matrix(fst) n.row <- nrow(x) n.col <- ncol(x)

btest <- c(1:100)

bt.reps = NULL

boot <- genind2df(file2) file2@pop <- NULL

for (i in btest){ boot2 <- boot[, sample(ncol(boot), replace = TRUE)] colnames(boot2) <- c(1:number of colums) #to avoid duplicate column names

boot3 <- df2genind(boot2, sep = " ", pop = pop) boot4 <- genind2hierfstat(boot3)

fst2 <- pairwise.WCfst(boot4, diploid = FALSE)

bt <- matrix(0, nrow = n.row, ncol = n.col) bt[] <- fst2 bt.reps <- rbind(bt.reps, bt) }

Sometimes when running this loop i get this error:

Error in apply(x, 2, fun2 <- function(x) sum(x > 0)) : dim(X) must have a positive length

When i get this error, my loop stops and i get only a few pairwise fst matrices. I've tried many ways to do that but every time it crashes when im using pairwise.WCfst. Any ideas?

jgx65 commented 8 years ago

Hi Pedro,

Why not using boot.ppfst in hierfstat?

As for why the crash, without a small dataset example replicating the problem, it is difficult to answer.

jgx65 commented 7 years ago

Hi @pedrosenna, can I consider this issue solved and close it? Thanks

pedrosenna commented 7 years ago

@jgx65 yeah sure, thank you 👍