aRchaic icon indicating copy to clipboard operation
aRchaic copied to clipboard

Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent

Open rsh249 opened this issue 7 years ago • 3 comments

I have a set of what I believe to be properly formatted mff files but aRchaic will not run when these are in a directory of their own. In that case I get an error when running archaic_prepare(): "Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent"

IF (and I don't know why this occurred to me to try) I put them in one of the example data folders (moderns or ancients) then I can run the model no problem but now my samples are labeled in the reference blocks so it's difficult to tell what's what.

I've looked at the code posted here for archaic_prepare() and found that this error tracks to the block of code starting on line 64, the section commented as "what if no .RData file is present and CSV files are present". The error itself occurs after line 116-120 is run and looking at the ancient_counts_filtered object is a matrix without columns so no column names can be assigned.

I would think it is something wrong with my data, but again these files work fine if they are placed in the aRchaic example directories.

Any help on resolving this will be appreciated.

Thanks!

rsh249 avatar Aug 04 '18 13:08 rsh249

@rsh249 Can you please elaborate on the directory structure you have? Are all the folders you are calling in aRchaic_prepare have CSV files in them? Since it works when you use the example directories, I would think the MFF format you have is fine. May be getting a better sense of the directory structure you have and how you are calling aRchaic_prepare would be helpful for me to answer. Thanks.

kkdey avatar Aug 06 '18 16:08 kkdey

@kkdey, the data I am testing are all in a single folder on my Desktop right now. I've tried other places but none work on my laptop or the server except in the archaic example data directories. The code I am using to call archaic_prepare is:


library(aRchaic)
moderns_dir <- system.file("extdata","moderns", package = "aRchaic")
list.files(moderns_dir, pattern = ".csv")
ancients_dir <- system.file("extdata","ancients", package = "aRchaic") #optional but if not, need more packrat samples to replace these files
list.files(ancients_dir, pattern = ".csv")
sample_dir <- "~/Desktop/arch"
list.files(sample_dir, pattern = ".csv")
out <- archaic_prepare(dirs = c(moderns_dir, ancients_dir, sample_dir), 
                       from_scratch=TRUE, delete=TRUE, one_mismatch=TRUE,
                       max_pos=20
)

I've been digging into this a little bit more this morning. By running the code in archaic_prepare() line by line I have found that the problem arises because the indices variable inside that function is empty with my data. Since I'm not entirely sure what is going on with this part of the code I can't say if that's a problem per se. However, I solved the error by catching that instance before using the indices variable to filter the ancient_counts object. Since indices was empty, using:

ancient_counts_filtered <- matrix(ancient_counts[, -indices],
                                 nrow = nrow(ancient_counts))

fails. But replacing that with this:


     if(length(indices)==0){
        ancient_counts_filtered <- matrix(ancient_counts,
                                          nrow = nrow(ancient_counts))
        } else {
          ancient_counts_filtered <- matrix(ancient_counts[, -indices],
                                            nrow = nrow(ancient_counts))
        }

works for me. Or, at least it let's me keep going through the aRchaic workflow and generate figures like the one attached.

structure.pdf

If these changes seem innocuous to the workflow then I could prepare a fork and submit a pull request.

rsh249 avatar Aug 06 '18 16:08 rsh249

yes that indeed looks like a bug in the code, thanks for pointing it out. I have updated the script. Sorry for the inconvenience caused.

kkdey avatar Aug 11 '18 16:08 kkdey