R: argument is of length zero
0
0
Entering edit mode
2.2 years ago

I want to loop through all the values of the variable u. It each loop iteration, I want to:

  • Get the correct mapping between the ith transcript cluster ID and the exon probe IDs
  • Subset the gene and exon matrices by the appropriate transcript cluster ID or exon probe IDs
  • Call the exon.ni function
  • Store the output p-values, test statistics, and CIs from this function for each transcript cluster ID (and exon probe IDs) I also want only to conduct this calculation when I have at least 2 rows in the d.exon matrix.

My Code

# Exon ni value calculation and t-test function
exon.ni <- function(genex, exonx, r) {
  ni <- t(t(exonx) -genex)
  ttest <- t(apply(ni, 1, t.two, sam=as.logical(r), v=F))
  return(ttest)
}


# Calculate ni p-values

ni.out <- for (i in u) {
  ex <- dimnames(map[map$transcript_cluster_id %in% i,])[[1]]
  d.exon <- as.numeric(unlist(e[ex,]))
  d.gene <- as.numeric(unlist(g[i,]))
  if(!is.null(d.exon) & nrow(d.exon) >= 2) {
    exon.ni(genex=as.numeric(d.gene), exonx=d.exon, rx=r)
  }
}

Traceback

Error in if (!is.null(d.exon) & nrow(d.exon) >= 2) { : 
  argument is of length zero

Data

> dput(map[1:3,])
structure(list(start = c("chr1", "chr1", "chr1"), stop = c(357616L, 
358431L, 742655L), transcript_cluster_id = c(358324L, 358460L, 
742719L), exon_id = c(2315251L, 2315251L, 2315373L), gene_assignment = c(90L, 
90L, 163L), probeset_type = c("NM_001005224 // OR4F3 /// NM_001005221 // OR4F29 /// NM_001005504 // OR4F21 /// NM_001005277 // OR4F16 /// ENST00000333864 // OR4F3 /// ENST00000332831 // OR4F29", 
"NM_001005221 // OR4F29 /// NM_001005277 // OR4F16 /// NM_001005224 // OR4F3 /// ENST00000333864 // OR4F3 /// ENST00000332831 // OR4F29", 
"---"), X = c("main", "main", "main")), row.names = c(2315252L, 
2315253L, 2315374L), class = "data.frame")

> dput(d.exon)
c(7.15477, 6.73452, 7.83324, 7.74893, 7.70502, 7.71924, 7.81656, 
7.93411, 7.91731, 8.22131, 7.23939, 7.32724, 7.9622, 7.16362, 
7.60169, 6.93187, 8.36692, 7.86296, 7.93925, 8.15436, 7.65065, 
7.33006, 7.2545, 7.19284, 7.9268, 7.40626)

> dput(d.gene)
c(5.64052, 5.62837, 5.67166, 5.58459, 5.58858, 5.95862, 5.69327, 
5.51709, 5.68322, 5.66781, 5.69987, 5.85948, 5.53388, 5.68834, 
5.89737, 5.66356, 5.75942, 5.63467, 5.388, 5.70666, 5.56539, 
5.79975, 6.16952, 5.77802, 5.63582, 5.84903
statistics r • 2.1k views
ADD COMMENT
0
Entering edit mode

I don't know about all the rest, but your nrow(d.exon) >= 2 is what's giving you a zero-length argument to the if statement. d.exon is a vector, not a matrix, so it has no rows, and you end up with NULL >= 2 which evaluates to a zero-length logical vector and crashes your if statement. Calling as.numeric just before that when creating d.exon is forcing it to be a vector (rather than whatever it would have been otherwise).

ADD REPLY
0
Entering edit mode
ADD REPLY

Login before adding your answer.

Traffic: 2497 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6