Skip to content
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

Loom file support? #4

Open
ekernf01 opened this issue Nov 15, 2019 · 0 comments
Open

Loom file support? #4

ekernf01 opened this issue Nov 15, 2019 · 0 comments

Comments

@ekernf01
Copy link

ekernf01 commented Nov 15, 2019

It would be much easier for data analysts to access this tool if it would accept file formats readily exported from Seurat, Scanpy, or similar tools. Is there any plan to support h5ad or loom files?

For the Seurat 3 users out there, here is a snippet of R code to export a Seurat v3 object to 10X triplet format, which is a good workaround for now. This uses pipes from magrittr, objects from Seurat >=3, and sparse matrices from Matrix, but I think it has no other dependencies.

Write10X = function (object, data.dir, metadata.include = colnames([email protected]), 
                     slot = "counts", include_all = FALSE, ...) 
{
  dir.create(data.dir, recursive = T, showWarnings = F)
  write.table(FetchData(object, metadata.include), file.path(data.dir, 
                                                             paste0("metadata.tsv")), row.names = T, col.names = T, 
              quote = F, sep = "\t")
  raw_dge = GetAssayData(object, slot = slot, ...)
  if (!include_all) {
    raw_dge = raw_dge[, Cells(object)]
  }
  rm(object)
  gc()
  if ("Matrix" != attr(class(raw_dge), "package")) {
    warning("\nAttempting to coerce data to sparse matrix from Matrix::Matrix before export. Please check your results.\n")
    raw_dge %<>% (Matrix::Matrix(sparse = T))
  }
  add_fake_ensg = function(x) data.frame("PLACEHOLDER_FOR_ENSG" %>% 
                                           paste0(seq_along(x)), x)
  wtsv = function(X, file) write.table(X, file, sep = "\t", 
                                       quote = F, row.names = F, col.names = F)
  Matrix::writeMM(raw_dge, file = file.path(data.dir, "matrix.mtx"))
  raw_dge %>% colnames %>% wtsv(file.path(data.dir, "barcodes.tsv"))
  raw_dge %>% rownames %>% add_fake_ensg %>% wtsv(file.path(data.dir, 
                                                            "genes.tsv"))
  return()
}
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

1 participant