diff scripts/dropletutils.Rscript @ 3:f0de368eabca draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
author iuc
date Tue, 15 Oct 2019 09:03:56 -0400
parents a8aa294401be
children cdf4443d5625
line wrap: on
line diff
--- a/scripts/dropletutils.Rscript	Fri Sep 06 10:56:16 2019 -0400
+++ b/scripts/dropletutils.Rscript	Tue Oct 15 09:03:56 2019 -0400
@@ -19,19 +19,35 @@
     write.table(as.matrix(obj), file=fileout, col.names=NA, sep='\t', quote=FALSE)
 }
 
-writeOut <- function(counts, fileout, typeout){
+determineGeneIDs <- function(object){
+    if (!is.null(rowData(object)$Symbol)){
+        return(rowData(object)$Symbol)
+    }
+    return(rownames(object))
+}
+
+getCounts <- function(object){
+    return(Matrix(counts(object), sparse=TRUE))
+}
+
+writeOut <- function(object, fileout, typeout){
     if (typeout == "tsv"){
-        writeTSV(fileout, counts)
+        writeTSV(fileout, getCounts(object))
     }
     else if (typeout == "h5ad"){
-        write10xCounts(fileout, counts, type="HDF5", overwrite=TRUE)
+        write10xCounts(fileout, getCounts(object),
+                       type="HDF5",
+                       gene.symbol=determineGeneIDs(object),
+                       overwrite=TRUE)
     }
     else if (typeout == "directory"){
-        write10xCounts(fileout, counts, type="sparse", overwrite=TRUE)
+        write10xCounts(fileout, getCounts(object),
+                       type="sparse",
+                       gene.symbol=determineGeneIDs(object),
+                       overwrite=TRUE)
     }
 }
 
-
 read10xFiles <- function(filein, typein){
     sce <- NULL
     if (typein == "tsv"){
@@ -92,7 +108,7 @@
     called[is.na(called)] <- FALSE    # replace NA's with FALSE
     sce.filtered <- sce[,called]
 
-    writeOut(counts(sce.filtered), files$out, out.type)
+    writeOut(sce.filtered, files$out, out.type)
 
     message(paste("Cells:", sum(na.omit(e.out$is.Cell))))
     message(paste("Cells and Limited:", sum(na.omit(e.out$is.CellAndLimited))))
@@ -108,7 +124,7 @@
     # Filtered
     sce.filtered <- sce[,called]
 
-    writeOut(Matrix(counts(sce.filtered),sparse=TRUE), files$out, out.type)
+    writeOut(sce.filtered, files$out, out.type)
 
     message(paste("Cells:", sum(called)))
 }