Mercurial > repos > iuc > dropletutils
comparison scripts/dropletutils.Rscript @ 3:2bbf0052aaa9 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:33 -0400 |
| parents | 58105e5efa8d |
| children | d5e4b59d5331 |
comparison
equal
deleted
inserted
replaced
| 2:58105e5efa8d | 3:2bbf0052aaa9 |
|---|---|
| 17 | 17 |
| 18 writeTSV <- function(fileout, obj){ | 18 writeTSV <- function(fileout, obj){ |
| 19 write.table(as.matrix(obj), file=fileout, col.names=NA, sep='\t', quote=FALSE) | 19 write.table(as.matrix(obj), file=fileout, col.names=NA, sep='\t', quote=FALSE) |
| 20 } | 20 } |
| 21 | 21 |
| 22 writeOut <- function(counts, fileout, typeout){ | 22 determineGeneIDs <- function(object){ |
| 23 if (!is.null(rowData(object)$Symbol)){ | |
| 24 return(rowData(object)$Symbol) | |
| 25 } | |
| 26 return(rownames(object)) | |
| 27 } | |
| 28 | |
| 29 getCounts <- function(object){ | |
| 30 return(Matrix(counts(object), sparse=TRUE)) | |
| 31 } | |
| 32 | |
| 33 writeOut <- function(object, fileout, typeout){ | |
| 23 if (typeout == "tsv"){ | 34 if (typeout == "tsv"){ |
| 24 writeTSV(fileout, counts) | 35 writeTSV(fileout, getCounts(object)) |
| 25 } | 36 } |
| 26 else if (typeout == "h5ad"){ | 37 else if (typeout == "h5ad"){ |
| 27 write10xCounts(fileout, counts, type="HDF5", overwrite=TRUE) | 38 write10xCounts(fileout, getCounts(object), |
| 39 type="HDF5", | |
| 40 gene.symbol=determineGeneIDs(object), | |
| 41 overwrite=TRUE) | |
| 28 } | 42 } |
| 29 else if (typeout == "directory"){ | 43 else if (typeout == "directory"){ |
| 30 write10xCounts(fileout, counts, type="sparse", overwrite=TRUE) | 44 write10xCounts(fileout, getCounts(object), |
| 45 type="sparse", | |
| 46 gene.symbol=determineGeneIDs(object), | |
| 47 overwrite=TRUE) | |
| 31 } | 48 } |
| 32 } | 49 } |
| 33 | |
| 34 | 50 |
| 35 read10xFiles <- function(filein, typein){ | 51 read10xFiles <- function(filein, typein){ |
| 36 sce <- NULL | 52 sce <- NULL |
| 37 if (typein == "tsv"){ | 53 if (typein == "tsv"){ |
| 38 ## Exploding memory problems occured here | 54 ## Exploding memory problems occured here |
| 90 called <- e.out$is.Cell | 106 called <- e.out$is.Cell |
| 91 } | 107 } |
| 92 called[is.na(called)] <- FALSE # replace NA's with FALSE | 108 called[is.na(called)] <- FALSE # replace NA's with FALSE |
| 93 sce.filtered <- sce[,called] | 109 sce.filtered <- sce[,called] |
| 94 | 110 |
| 95 writeOut(counts(sce.filtered), files$out, out.type) | 111 writeOut(sce.filtered, files$out, out.type) |
| 96 | 112 |
| 97 message(paste("Cells:", sum(na.omit(e.out$is.Cell)))) | 113 message(paste("Cells:", sum(na.omit(e.out$is.Cell)))) |
| 98 message(paste("Cells and Limited:", sum(na.omit(e.out$is.CellAndLimited)))) | 114 message(paste("Cells and Limited:", sum(na.omit(e.out$is.CellAndLimited)))) |
| 99 } | 115 } |
| 100 | 116 |
| 106 called <- do.call(defaultDrops, c(dparams)) | 122 called <- do.call(defaultDrops, c(dparams)) |
| 107 | 123 |
| 108 # Filtered | 124 # Filtered |
| 109 sce.filtered <- sce[,called] | 125 sce.filtered <- sce[,called] |
| 110 | 126 |
| 111 writeOut(Matrix(counts(sce.filtered),sparse=TRUE), files$out, out.type) | 127 writeOut(sce.filtered, files$out, out.type) |
| 112 | 128 |
| 113 message(paste("Cells:", sum(called))) | 129 message(paste("Cells:", sum(called))) |
| 114 } | 130 } |
| 115 | 131 |
| 116 | 132 |
