Mercurial > repos > iuc > dropletutils
annotate scripts/dropletutils.Rscript @ 1:94ee8160ace3 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
| author | iuc | 
|---|---|
| date | Mon, 26 Aug 2019 05:06:15 -0400 | 
| parents | 1335bf5bcd0e | 
| children | 58105e5efa8d | 
| rev | line source | 
|---|---|
| 0 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 1 ## Load in data | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 2 args = commandArgs(trailingOnly = T) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 3 if (length(args) != 1){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 4 stop("Please provide the config file") | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 5 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 6 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 7 suppressWarnings(suppressPackageStartupMessages(require(DropletUtils))) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 8 suppressWarnings(suppressPackageStartupMessages(require(Matrix))) | 
| 1 
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
 iuc parents: 
0diff
changeset | 9 suppressWarnings(suppressPackageStartupMessages(require(scater))) | 
| 0 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 10 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 11 source(args[1]) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 12 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 13 ## Helper functions | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 14 setSparse <- function(obj){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 15 return(as(obj, "dgCMatrix")) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 16 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 17 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 18 writeTSV <- function(fileout, obj){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 19 write.table(as.matrix(obj), file=fileout, col.names=NA, sep='\t', quote=FALSE) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 20 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 21 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 22 writeOut <- function(counts, fileout, typeout){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 23 if (typeout == "tsv"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 24 writeTSV(fileout, counts) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 25 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 26 else if (typeout == "h5ad"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 27 write10xCounts(fileout, counts, type="HDF5", overwrite=TRUE) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 28 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 29 else if (typeout == "directory"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 30 write10xCounts(fileout, counts, type="sparse", overwrite=TRUE) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 31 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 32 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 33 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 34 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 35 read10xFiles <- function(filein, typein){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 36 sce <- NULL | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 37 if (typein == "tsv"){ | 
| 1 
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
 iuc parents: 
0diff
changeset | 38 ## Exploding memory problems occured here | 
| 
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
 iuc parents: 
0diff
changeset | 39 ## - solution is to use the readSparseCounts function from scater | 
| 
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
 iuc parents: 
0diff
changeset | 40 sce <- SingleCellExperiment(assays = list(counts = readSparseCounts(filein))) | 
| 0 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 41 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 42 else if (typein == "h5ad"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 43 sce <- read10xCounts(filein, col.names=T, type="HDF5") # use barcodes.tsv as column names | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 44 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 45 else if (typein == "directory"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 46 sce <- read10xCounts(filein, col.names=T, type="sparse") | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 47 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 48 counts(sce) <- setSparse(counts(sce)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 49 return(sce) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 50 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 51 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 52 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 53 ## Methods | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 54 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 55 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 56 doEmptyDrops <- function(files, eparams, in.type="directory", out.type="h5ad", fdr_threshold = 0.01){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 57 sce <- read10xFiles(files$infile, in.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 58 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 59 eparams$... <- NULL ## hack | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 60 eparams$m = Matrix(counts(sce), sparse=TRUE) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 61 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 62 e.out <- do.call(emptyDrops, c(eparams)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 63 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 64 bar.names <- colnames(sce) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 65 if (length(bar.names) != nrow(e.out)){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 66 stop("Length of barcodes and output metrics don't match.") | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 67 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 68 e.out <- cbind(bar.names, e.out) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 69 e.out$is.Cell <- e.out$FDR <= fdr_threshold | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 70 e.out$is.CellAndLimited <- e.out$is.Cell & e.out$Limited | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 71 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 72 # Write to table | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 73 writeTSV(files$table, e.out) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 74 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 75 # Print to log | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 76 print(table(Limited=e.out$Limited, Significant=e.out$is.Cell)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 77 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 78 # Write to Plot | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 79 png(files$plot) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 80 plot(e.out$Total, -e.out$LogProb, col=ifelse(e.out$is.Cell, "red", "black"), | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 81 xlab="Total UMI count", ylab="-Log Probability") | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 82 dev.off() | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 83 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 84 # Filtered | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 85 called <- e.out$is.CellAndLimited | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 86 called[is.na(called)] <- FALSE # replace NA's with FALSE | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 87 sce.filtered <- sce[,called] | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 88 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 89 writeOut(counts(sce.filtered), files$out, out.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 90 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 91 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 92 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 93 doDefaultDrops <- function(files, dparams, in.type="directory", out.type="h5ad"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 94 sce <- read10xFiles(files$infile, in.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 95 | 
| 1 
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
 iuc parents: 
0diff
changeset | 96 dparams$m = counts(sce) | 
| 0 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 97 called <- do.call(defaultDrops, c(dparams)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 98 print(table(called)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 99 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 100 # Filtered | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 101 sce.filtered <- sce[,called] | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 102 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 103 writeOut(Matrix(counts(sce.filtered),sparse=TRUE), files$out, out.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 104 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 105 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 106 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 107 doBarcodeRankings <- function(files, bparams, in.type="directory"){ | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 108 sce <- read10xFiles(files$infile, in.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 109 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 110 bparams$... <- NULL ## hack | 
| 1 
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
 iuc parents: 
0diff
changeset | 111 bparams$m = counts(sce) | 
| 0 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 112 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 113 br.out <- do.call(barcodeRanks, c(bparams)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 114 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 115 png(files$plot) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 116 plot(br.out$rank, br.out$total, log="xy", xlab="(log) Rank", ylab="(log) Total Number of Barcodes") | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 117 o <- order(br.out$rank) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 118 lines(br.out$rank[o], br.out$fitted[o], col="red") | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 119 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 120 abline(h=br.out$knee, col="dodgerblue", lty=2) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 121 abline(h=br.out$inflection, col="forestgreen", lty=2) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 122 legend("bottomleft", lty=2, col=c("dodgerblue", "forestgreen"), legend=c("knee", "inflection")) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 123 dev.off() | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 124 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 125 print(paste("knee =", br.out$knee, ", inflection = ", br.out$inflection)) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 126 } | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 127 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 128 ## Main | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 129 set.seed(seed.val) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 130 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 131 if (do.method == "barcodeRankings") { | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 132 doBarcodeRankings(files, bparams, in.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 133 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 134 } else if (do.method == "defaultDrops") { | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 135 doDefaultDrops(files, dparams, in.type, out.type) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 136 | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 137 } else if (do.method == "emptyDrops") { | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 138 doEmptyDrops(files, eparams, in.type, out.type, empty.fdr_threshold) | 
| 
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
 iuc parents: diff
changeset | 139 } | 
