Skip to content

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

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

Open
rsh249 opened this issue Aug 4, 2018 · 3 comments

Comments

@rsh249
Copy link

rsh249 commented Aug 4, 2018

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!

@kkdey
Copy link
Owner

kkdey commented Aug 6, 2018

@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.

@rsh249
Copy link
Author

rsh249 commented Aug 6, 2018

@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.

@kkdey
Copy link
Owner

kkdey commented Aug 11, 2018

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.

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

2 participants