annotate scripts/dropletutils.Rscript @ 1:cfe1e6c28d95 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:39 -0400
parents 4cd9f0008d9c
children a8aa294401be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
1 ## Load in data
4cd9f0008d9c 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)
4cd9f0008d9c 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){
4cd9f0008d9c 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")
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
5 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
6
4cd9f0008d9c 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)))
4cd9f0008d9c 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
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
9 suppressWarnings(suppressPackageStartupMessages(require(scater)))
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
10
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
11 source(args[1])
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
12
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
13 ## Helper functions
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
14 setSparse <- function(obj){
4cd9f0008d9c 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"))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
16 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
17
4cd9f0008d9c 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){
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
20 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
21
4cd9f0008d9c 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){
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
23 if (typeout == "tsv"){
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
24 writeTSV(fileout, counts)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
25 }
4cd9f0008d9c 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"){
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
28 }
4cd9f0008d9c 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"){
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
31 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
32 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
33
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
34
4cd9f0008d9c 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){
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
36 sce <- NULL
4cd9f0008d9c 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
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
38 ## Exploding memory problems occured here
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
39 ## - solution is to use the readSparseCounts function from scater
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
40 sce <- SingleCellExperiment(assays = list(counts = readSparseCounts(filein)))
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
41 }
4cd9f0008d9c 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"){
4cd9f0008d9c 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
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
44 }
4cd9f0008d9c 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"){
4cd9f0008d9c 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")
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
47 }
4cd9f0008d9c 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))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
49 return(sce)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
50 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
51
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
52
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
53 ## Methods
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
54
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
55
4cd9f0008d9c 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){
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
58
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
59 eparams$... <- NULL ## hack
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
61
4cd9f0008d9c 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))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
63
4cd9f0008d9c 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)
4cd9f0008d9c 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)){
4cd9f0008d9c 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.")
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
67 }
4cd9f0008d9c 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)
4cd9f0008d9c 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
4cd9f0008d9c 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
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
71
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
72 # Write to table
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
74
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
75 # Print to log
4cd9f0008d9c 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))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
77
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
78 # Write to Plot
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
79 png(files$plot)
4cd9f0008d9c 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"),
4cd9f0008d9c 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")
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
82 dev.off()
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
83
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
84 # Filtered
4cd9f0008d9c 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
4cd9f0008d9c 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
4cd9f0008d9c 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]
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
88
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
90 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
91
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
92
4cd9f0008d9c 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"){
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
95
1
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
96 dparams$m = counts(sce)
0
4cd9f0008d9c 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))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
98 print(table(called))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
99
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
100 # Filtered
4cd9f0008d9c 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]
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
102
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
104 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
105
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
106
4cd9f0008d9c 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"){
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
109
4cd9f0008d9c 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
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
111 bparams$m = counts(sce)
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
112
4cd9f0008d9c 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))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
114
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
115 png(files$plot)
4cd9f0008d9c 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")
4cd9f0008d9c 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)
4cd9f0008d9c 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")
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
119
4cd9f0008d9c 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)
4cd9f0008d9c 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)
4cd9f0008d9c 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"))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
123 dev.off()
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
124
4cd9f0008d9c 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))
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
126 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
127
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
128 ## Main
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
130
4cd9f0008d9c 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") {
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
133
4cd9f0008d9c 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") {
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
136
4cd9f0008d9c 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") {
4cd9f0008d9c 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)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
139 }