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

Does read.genepop really needs ncode? #326

Open
courtiol opened this issue Feb 28, 2022 · 0 comments
Open

Does read.genepop really needs ncode? #326

courtiol opened this issue Feb 28, 2022 · 0 comments

Comments

@courtiol
Copy link
Contributor

Hi all,

I am not fully familiar with the genepop format and its possible variants...
But I am wondering if it is really necessary to ask the user to input ncode.
Since the function only handles diploid case, then it should be straightforward to determine ncode automatically.

For example, just before

adegenet/R/import.R

Lines 707 to 711 in b8b7b3b

## check that data are consistent with NCODE and ploidy=2
if(!all(unique(nchar(X))==(ncode*2))) stop(paste("some alleles are not encoded with", ncode,
"characters\nCheck 'ncode' argument"))
res <- df2genind(X=X, pop=as.character(pop), ploidy=2, ncode=ncode, NA.char=NA.char)

we could thus have something like this:

if (is.null(ncode)) ncode <- nchar(strsplit(vec.genot[1], split = " ")[[1]][1])/2
NA.char <- paste(rep("0", ncode), collapse = "")

Or if things are supposed to be heterogeneous (I don't think so but could be, no idea) we could have something like:

if (is.null(ncode)) { 
      ncodes <- unique(unlist(lapply(sapply(vec.genot, strsplit, split = " "), nchar)))
      if (length(ncodes) > 1) stop("ncode must be defined for this dataset")
      ncode <- ncodes/2
    }
NA.char <- paste(rep("0", ncode), collapse = "")

I used if (is.null(ncode)) for backward compatibility, but we could also drop the argument altogether.

If that sounds useful, I am happy to write a PR which would include tests and documentation too, but I would need information or some datasets other than nancycats.gen in case there would be variation in genepop formats beyond a variable number of digit.

I would also need to know whether dropping the argument altogether in an option.
I could check if the user defines it and return a message saying it is now ignored.

++

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

1 participant