0
$\begingroup$

I'm getting an error when creating the counts from a single cell experiment.I'm identifying shared barcodes as well as lowUMI barcodes with the follow code:

shared = colnames(cts[[i]])[which(colnames(cts[[i]]) %in% lb[[libID]])]
lowUMI = colnames(cts[[i]])[colSums(cts[[i]])<1000]

but my code is erroring at

lowUMI = colnames(cts[[i]])[colSums(cts[[i]])<1000]

with this error

Error in colSums(cts[[i]]) : 'x' must be an array of at least two dimensions

My full code:

cts=list()
for (i in 1:length(mf$LibraryID)){
  # Read in all four input expression matrices
  message(i)
  message(mf$LibraryID[i])
  libID = mf$LibraryID[i]
  #lb[[libID]] = gsub("-1", "", lb[[libID]])
  lb[[libID]] = unique(lb[[libID]])
  ## by default we point to the 10X dir
  #data.dir = paste0(wd, mf$GSM[i], "/cellranger_out/",mf$LibraryID[i],"/filtered_feature_bc_matrix/") 
  data.dir = paste0(wd2, mf$GSM[i], "/metadata/cellranger_ASI_run/",mf$LibraryID[i],"/filtered_feature_bc_matrix/")
      if (!dir.exists(data.dir)) data.dir = paste0(wd3, mf$GSM[i], "/", mf$LibraryID[i],"/outs/filtered_feature_bc_matrix/")
  if (!dir.exists(data.dir)) data.dir = paste0(wd2, mf$GSM[i], "/metadata/cellranger_ASI_run/",mf$LibraryID[i],"/outs/filtered_feature_bc_matrix/")
  if (dir.exists(data.dir)){
    message(data.dir)
    cts[[i]] <- Read10X(data.dir)
    #colnames(cts[[i]]) = gsub("-1", "", colnames(cts[[i]]))
    shared = colnames(cts[[i]])[which(colnames(cts[[i]]) %in% lb[[libID]])]
    lowUMI = colnames(cts[[i]])[colSums(cts[[i]])<1000]
    to_filter = intersect(shared, lowUMI)
    #to_filter = shared
    ok = colnames(cts[[i]])[!(colnames(cts[[i]]) %in% to_filter)]
    cts[[i]] = cts[[i]][, ok]
    colnames(cts[[i]])=paste0(mf$LibraryID[i], "_", colnames(cts[[i]]))
    if (i==1) {
      cts_all=cts[[1]] 
    } else {
      cts_all = cbind(cts_all, cts[[i]])
    } 
  }
}  
dim(cts_all)
$\endgroup$
5
  • $\begingroup$ The error is clear - you are trying to use colSums on something with only one dimension, like a vector, whereas you need at least 2 dimensions, like a data.frame or matrix. But without any reproducible example, there is no chance that someone can fix the issue. $\endgroup$
    – user438383
    Nov 19 '21 at 10:16
  • $\begingroup$ It does have 2 dimensions: r dim(cts_all) 106477 82029 $\endgroup$
    – mmpp
    Nov 19 '21 at 13:53
  • $\begingroup$ Please can you provide a small sample of your data. $\endgroup$
    – user438383
    Nov 19 '21 at 14:16
  • $\begingroup$ Might be wrong but it seems you are invoking colSums on the value of the colnames function which is a character vector so it has only one dimension. Are you trying to get the name of columns in cts where colSums(cts[[i]])<1000 ? $\endgroup$ Nov 23 '21 at 15:53
  • $\begingroup$ @PaulEndymion Yes, I'm trying to retrieve all the barcodes that are less than 1000 and then filter out those barcodes. $\endgroup$
    – mmpp
    Dec 2 '21 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.