incorrect number of dimensions error

492 views
Skip to first unread message

Nikki Vollmer

unread,
Apr 12, 2021, 12:57:38 PM4/12/21
to dartR
Hello,
I am new to dartR have been trying to run a couple of different functions (hwe, monomorphs) and keep getting the following error: 

Error in x@other$loc.metrics[!x$loc.names %in% loc.list, ] : 
  incorrect number of dimensions

My guess is there is a problem with my conversion to genlight (I am working from a non-DArT source), but I can't figure out what it is. With adegenet, I have tried converting my data (4 populations 14 to 84 individuals in each, 5,767 SNP loci) from both genepop and structure format to a genind and then using gi2gl to go from there to a genlight, for example: 

> Fourpop<-read.structure("5767_4pops.str", n.ind=134, n.loc=5767, onerowperind = FALSE, col.lab = 1, col.pop = 2, row.marknames=1)

 Which other optional columns should be read (press 'return' when done)? 
1: 

 Converting data from a STRUCTURE .stru file to a genind object... 

> Fourpop.gl<-gi2gl(Fourpop, verbose=5)
Starting gi2gl 
Completed: gi2gl 

Running a compliance check produces an error. In addition to the error it says I have no monomorphic loci but I know I do in some of the populations: 

> gl2 <- gl.compliance.check(Fourpop.gl)
Starting gl.compliance.check 
  Processing a SNP dataset
  Checking coding of SNPs
    SNP data scored NA, 0, 1 or 2 confirmed
  Checking locus metrics and flags
  Recalculating locus metrics
  Checking for monomorphic loci
    No monomorphic loci detected
Error in if (nLoc(x) != nrow(x@other$loc.metrics)) { : 
  argument is of length zero

So next I tried repeating the above with just one of the 4 populations (n=21, 5767 snps; one I know has monomorphic loci) and I get the "dimensions" error after the monomorphic check:

> redpop<-read.structure("red5k.str", n.ind=21, n.loc=5767, onerowperind = FALSE, col.lab = 1, col.pop = 2, row.marknames=1)

 Which other optional columns should be read (press 'return' when done)? 
1: 

 Converting data from a STRUCTURE .stru file to a genind object... 

> redpop.gl<-gi2gl(redpop, verbose=5)
Starting gi2gl 
Completed: gi2gl 

> gl2 <- gl.compliance.check(redpop.gl)
Starting gl.compliance.check 
  Processing a SNP dataset
  Checking coding of SNPs
    SNP data scored NA, 0, 1 or 2 confirmed
  Checking locus metrics and flags
  Recalculating locus metrics
  Checking for monomorphic loci
Error in x@other$loc.metrics[!x$loc.names %in% loc.list, ] : 
  incorrect number of dimensions

FWIW, for either input dataset I have no errors when I run gl.report.callrate.  I am working in R 4.0.4, adegenet 2.1.3 and dartR 1.9.4. Also, there is missing data in all 4 populations, and for some of them there are some loci with all missing data, and at this point I have kept it all in there (originally as -9). 

Any ideas how I can figure out what is going on, or other options for inputing my data correctly?  I sincerely appreciate any help!!

Thank you, Nikki


Jose Luis Mijangos

unread,
Apr 13, 2021, 12:25:56 AM4/13/21
to dartR
Hi Nikki,

Can you try the following:

library(adegenet)
library(dartR)
# Import genepop file to genind object
Fourpop <- read.genepop(file = "your_data.gen")
# genind to genlight
Fourpop.gl <- gi2gl(Fourpop, verbose=5)
Fourpop.gl_2 <- gl.recalc.metrics(Fourpop.gl)
Fourpop.gl_2$other$loc.metrics <- as.data.frame(Fourpop.gl_2$other$loc.metrics)
Fourpop.gl_3 <- gl.compliance.check(Fourpop.gl_2)

Please let us know whether it worked for you.

Cheers,
Luis

Nikki Vollmer

unread,
Apr 13, 2021, 10:41:20 AM4/13/21
to da...@googlegroups.com
Thank you Luis, that worked! 

I have 3 follow up questions:
1) seems to me like the main difference that you suggested was to run gl.recalc.metric, is this something that one should always do when importing non-DaRT data, or is there another reason to run this function?
2) is there a way to get a list of the monomorphic loci?
3) is the bonferroni correction option for hwe tests a sequential bonferroni test?

Thank you again for your help and quick response. I can't stress how much I/we appreciate such well-curated help groups like this one!

Nikki



--
You received this message because you are subscribed to a topic in the Google Groups "dartR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dartr/WGoavfd4fbw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/6a3dd9b6-da43-4b3f-884b-082636f21ff3n%40googlegroups.com.

Jose Luis Mijangos

unread,
Apr 14, 2021, 3:12:16 AM4/14/21
to dartR
Hi Nikki,

Thank you for your kind words :)

1) In this case gl.recalc.metric is used to calculate metrics for each locus that are not calculated by default in other programs and are required for various functions in dartR. Actually, the main difference that I suggested is:

Fourpop.gl_2$other$loc.metrics <- as.data.frame(Fourpop.gl_2$other$loc.metrics)

I suggested this because the function gi2gl formats the slot "loc.metrics" as a list when it should be a data frame. We will fix this soon and should be available in the next release of dartR, however in case you want to have the latest version of the package you can download the developer version via:

install_github("green-striped-gecko/dartR@dev")

2) You can try:

x <- yourdata.gl
na.counter <- 0
loc.list <- array(NA, nLoc(x))
  mat <- as.matrix(x)
  lN <- locNames(x)
  for (i in 1:nLoc(x)) {
    row <- mat[, i]
    if (all(row == 0, na.rm = TRUE) | all(row == 2, na.rm = TRUE) |
        all(is.na(row))) {
      loc.list[i] <- lN[i]
      if (all(is.na(row))) {
        na.counter = na.counter + 1
      }
    }
  }
  loc.list <- loc.list[!is.na(loc.list)]

# display list of monomorphic loci

  print(loc.list)

# NB We will add an option to this function to make more accessible the off monomorphic loci

3) The correction for multiple tests used in the HWE function is the "standard" Bonferroni correction method not the sequential Bonferroni correction a.k.a. Holm-Bonferroni. The "standard" Bonferroni method is more stringent than the Holm-Bonferroni.

Cheers,

Luis

Nikki Vollmer

unread,
Apr 14, 2021, 3:27:17 PM4/14/21
to da...@googlegroups.com
Thanks again, and that code worked great for getting a list of the monomorphic loci! 

Reply all
Reply to author
Forward
0 new messages