annotate scripts/dropletutils.Rscript @ 2:a8aa294401be draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
author iuc
date Fri, 06 Sep 2019 10:56:16 -0400
parents cfe1e6c28d95
children f0de368eabca
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)
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
61
0
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))
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
63
0
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)
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
65 if (length(bar.names) != nrow(e.out)){
0
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
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
71
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
72 ## Write to Plot
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
73 e.out$is.Cell[is.na(e.out$is.Cell)] <- FALSE
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
74 xlim.dat <- e.out[complete.cases(e.out),]$Total
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
75
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
76 ## Write to table
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
77 writeTSV(files$table, e.out[complete.cases(e.out),])
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
78
0
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"),
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
81 xlab="Total UMI count", ylab="-Log Probability",
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
82 xlim=c(min(xlim.dat),max(xlim.dat)))
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
83 dev.off()
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
84
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
85 ## Filtered
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
86 called <- NULL
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
87 if (fdr_threshold != 0){
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
88 called <- e.out$is.CellAndLimited
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
89 } else {
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
90 called <- e.out$is.Cell
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
91 }
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
92 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
93 sce.filtered <- sce[,called]
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
94
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
95 writeOut(counts(sce.filtered), files$out, out.type)
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
96
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
97 message(paste("Cells:", sum(na.omit(e.out$is.Cell))))
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
98 message(paste("Cells and Limited:", sum(na.omit(e.out$is.CellAndLimited))))
0
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
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
101
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
102 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
103 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
104
1
cfe1e6c28d95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents: 0
diff changeset
105 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
106 called <- do.call(defaultDrops, c(dparams))
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
107
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
108 # Filtered
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
109 sce.filtered <- sce[,called]
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
110
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
111 writeOut(Matrix(counts(sce.filtered),sparse=TRUE), files$out, out.type)
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
112
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
113 message(paste("Cells:", sum(called)))
0
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
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
116
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
117 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
118 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
119
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
120 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
121 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
122
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
123 br.out <- do.call(barcodeRanks, c(bparams))
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
124
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
125 png(files$plot)
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
126 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
127 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
128 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
129
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
130 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
131 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
132 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
133 dev.off()
2
a8aa294401be "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents: 1
diff changeset
134
0
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
135 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
136 }
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
137
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
138 ## Main
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
139 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
140
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
141 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
142 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
143
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
144 } 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
145 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
146
4cd9f0008d9c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff changeset
147 } 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
148 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
149 }