EricArcher / strataG

strataG is a toolkit for haploid sequence and multilocus genetic data summaries, and analyses of population structure.
25 stars 12 forks source link

Error in df2gtypes: "the number of genes in 'sequences' is not equal to the number of loci" #55

Closed akoontz11 closed 2 years ago

akoontz11 commented 2 years ago

I'm using strataG (v2.5.01; R version 4.2.0) to run fastSimcoal2 simulations (with DNA markers) and convert the Arlequin outputs to gtype objects. However, when I run fsc2gtypes on my fsc parameters object, I get the error in the title. I was able to trace the error back to this line of the df2gtypes function, but I haven't been able to fix it yet.

I've included a reprex below:

library(strataG)
# Simulation settings
demeA <- fscDeme(deme.size = 10, sample.size = 10)
dna <- fscBlock_dna(sequence.length = 15, mut.rate = 1e-3)
DNAgenetics <- fscSettingsGenetics(dna, dna, dna, num.chrom = 1)
# Build parameters and run
DNA_Demo.params <- fscWrite(demes = fscSettingsDemes(demeA), genetics = DNAgenetics, 
                                          label = "DNAmarker_Demo", use.wd=TRUE)
DNA_Demo.params <- fscRun(DNA_Demo.params, num.sims = 5, all.sites = TRUE)
# Convert to gtype
DNA_Demo_gtype <- fsc2gtypes(DNA_Demo.params, marker = "dna")
# Error: the number of genes in 'sequences' is not equal to the number of loci

Ultimately, my goal is to convert the Arlequin outputs to genind, and I was planning on doing this by calling gtypes2genind next. If there's something I'm messing up, or there's another means of achieving this conversion (Arlequin to genind) using strataG, please let me know.

Thank you for your time, and for creating an incredibly useful package!

EricArcher commented 2 years ago

Thanks for flagging this and the reprex. The issue was in fsc2gtypes() in that it was only checking the marker type to decide whether or not to make a haploid or polyploid gtypes object. I've changed that so that haploid objects are only created if ploidy = 1 and marker type is DNA. Your reprex now works as it should.