hemberg-lab / SC3

A tool for the unsupervised clustering of cells from single cell RNA-Seq experiments
http://bioconductor.org/packages/SC3
GNU General Public License v3.0
118 stars 55 forks source link

Error in rowSums(out_pathway) : 'x' must be an array of at least two dimensions #101

Closed zina-R closed 3 years ago

zina-R commented 3 years ago

i am trying to solve this problem can you help me:

kegg_brite_map <- read.table("E:\\Path\\KoG1\\picrust1_KO_BRITE_map.tsv", header=TRUE, sep="\t", quote = "", stringsAsFactors = FALSE, comment.char="", row.names=1)

test_ko <- read.table("E:\Path\KoG1\test_ko.tsv", header=TRUE, sep="\t", row.names=1)

Run function

categorize_by_function_l3 <- function(in_ko, kegg_brite_mapping) {
  # Function to create identical output as categorize_by_function.py script,
  # but with R objects instead of BIOM objects in Python.
  # Input KO table is assumed to have rownames as KOs and sample names as columns.

  out_pathway <- data.frame(matrix(NA, nrow=0, ncol=(ncol(in_ko) + 1)))

  colnames(out_pathway) <- c("pathway", colnames(in_ko))

  for(ko in rownames(in_ko)) {

    # Skip KO if not in KEGG BRITE mapping df
    # (this occurs with newer KOs that weren't present in PICRUSt1).
    if(! ko %in% rownames(kegg_brite_mapping)) {
      next
    }

    pathway_list <- strsplit(kegg_brite_mapping[ko, "metadata_KEGG_Pathways"], "\\|")[[1]]

    for(pathway in pathway_list) {

      pathway <- strsplit(pathway, ";")[[1]][3]

      new_row <- data.frame(matrix(c(NA, as.numeric(in_ko[ko,])), nrow=1, ncol=ncol(out_pathway)))
      colnames(new_row) <- colnames(out_pathway)
      new_row$pathway <- pathway
      out_pathway <- rbind(out_pathway, new_row)
    }

  }

  out_pathway = data.frame(aggregate(. ~ pathway, data = out_pathway, FUN=sum))

  rownames(out_pathway) <- out_pathway$pathway

  out_pathway <- out_pathway[, -which(colnames(out_pathway) == "pathway")]

  if(length(which(rowSums(out_pathway) == 0)) > 0) {
    out_pathway <- out_pathway[-which(rowSums(out_pathway) == 0), ]
  }

  return(out_pathway)

}

Run function to categorize all KOs by level 3 in BRITE hierarchy test_ko_L3 <- categorize_by_function_l3(test_ko, kegg_brite_map)

ERROR Error in rowSums(out_pathway) : 'x' must be an array of at least two dimensions Called from: rowSums(out_pathway)

wikiselev commented 3 years ago

Sorry, but it looks like you are not using SC3 in your script. I will close this.