Mercurial > repos > iuc > dropletutils
annotate scripts/dropletutils.Rscript @ 3:f0de368eabca draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
author | iuc |
---|---|
date | Tue, 15 Oct 2019 09:03:56 -0400 |
parents | a8aa294401be |
children | cdf4443d5625 |
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 |
3
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
22 determineGeneIDs <- function(object){ |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
23 if (!is.null(rowData(object)$Symbol)){ |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
24 return(rowData(object)$Symbol) |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
25 } |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
26 return(rownames(object)) |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
27 } |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
28 |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
29 getCounts <- function(object){ |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
30 return(Matrix(counts(object), sparse=TRUE)) |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
31 } |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
32 |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
33 writeOut <- function(object, fileout, typeout){ |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
34 if (typeout == "tsv"){ |
3
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
35 writeTSV(fileout, getCounts(object)) |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
36 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
37 else if (typeout == "h5ad"){ |
3
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
38 write10xCounts(fileout, getCounts(object), |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
39 type="HDF5", |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
40 gene.symbol=determineGeneIDs(object), |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
41 overwrite=TRUE) |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
42 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
43 else if (typeout == "directory"){ |
3
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
44 write10xCounts(fileout, getCounts(object), |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
45 type="sparse", |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
46 gene.symbol=determineGeneIDs(object), |
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
47 overwrite=TRUE) |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
48 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
49 } |
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 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
|
52 sce <- NULL |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
53 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
|
54 ## 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
|
55 ## - 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
|
56 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
|
57 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
58 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
|
59 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
|
60 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
61 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
|
62 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
|
63 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
64 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
|
65 return(sce) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
66 } |
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 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
69 ## Methods |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
70 |
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 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
|
73 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
|
74 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
75 eparams$... <- NULL ## hack |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
76 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
|
77 |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
78 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
|
79 |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
88 ## 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
|
89 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
|
90 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
|
91 |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
92 ## 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
|
93 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
|
94 |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
95 png(files$plot) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 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
|
100 |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
101 ## Filtered |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
102 called <- NULL |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
103 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
|
104 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
|
105 } else { |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
106 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
|
107 } |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
108 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
|
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 |
3
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
111 writeOut(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
|
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(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
|
114 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
|
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 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
118 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
|
119 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
|
120 |
1
cfe1e6c28d95
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents:
0
diff
changeset
|
121 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
|
122 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
|
123 |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
124 # Filtered |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
125 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
|
126 |
3
f0de368eabca
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
127 writeOut(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
|
128 |
a8aa294401be
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
129 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
|
130 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
131 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
132 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
133 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
|
134 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
|
135 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
136 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
|
137 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
|
138 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
139 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
|
140 |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
141 png(files$plot) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 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
|
150 |
0
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
151 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
|
152 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
153 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
154 ## Main |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
155 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
|
156 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
157 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
|
158 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
|
159 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
160 } 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
|
161 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
|
162 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
163 } 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
|
164 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
|
165 } |