Mercurial > repos > iuc > dropletutils
annotate scripts/dropletutils.Rscript @ 5:d5e4b59d5331 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit ea9a67b5711b53fb911a0c50b6b49eb9db2366a7"
| author | iuc |
|---|---|
| date | Wed, 29 Jan 2020 20:07:15 +0000 |
| parents | 2bbf0052aaa9 |
| children | a79cf05ca77d |
| rev | line source |
|---|---|
|
0
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
1 ## Load in data |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
2 args = commandArgs(trailingOnly = T) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
3 if (length(args) != 1){ |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
4 stop("Please provide the config file") |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
5 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
6 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
7 suppressWarnings(suppressPackageStartupMessages(require(DropletUtils))) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
8 suppressWarnings(suppressPackageStartupMessages(require(Matrix))) |
|
1
94ee8160ace3
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 40d4a92c62d75fe931baba8657cde006a26d84cf"
iuc
parents:
0
diff
changeset
|
9 suppressWarnings(suppressPackageStartupMessages(require(scater))) |
|
0
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
10 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
11 source(args[1]) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
12 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
13 ## Helper functions |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
14 setSparse <- function(obj){ |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
15 return(as(obj, "dgCMatrix")) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
16 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
17 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
18 writeTSV <- function(fileout, obj){ |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
19 write.table(as.matrix(obj), file=fileout, col.names=NA, sep='\t', quote=FALSE) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
20 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
21 |
|
3
2bbf0052aaa9
"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){ |
|
2bbf0052aaa9
"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)){ |
|
2bbf0052aaa9
"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) |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
25 } |
|
2bbf0052aaa9
"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)) |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
27 } |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
28 |
|
2bbf0052aaa9
"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){ |
|
2bbf0052aaa9
"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)) |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
31 } |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
32 |
|
2bbf0052aaa9
"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
1335bf5bcd0e
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
2bbf0052aaa9
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
36 } |
|
5
d5e4b59d5331
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit ea9a67b5711b53fb911a0c50b6b49eb9db2366a7"
iuc
parents:
3
diff
changeset
|
37 else if (typeout == "h5"){ |
|
3
2bbf0052aaa9
"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), |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
39 type="HDF5", |
|
2bbf0052aaa9
"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), |
|
2bbf0052aaa9
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
42 } |
|
1335bf5bcd0e
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
2bbf0052aaa9
"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), |
|
2bbf0052aaa9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit a4cee4cac5097029188d836d5b904b605dbb943d"
iuc
parents:
2
diff
changeset
|
45 type="sparse", |
|
2bbf0052aaa9
"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), |
|
2bbf0052aaa9
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
48 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
49 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
50 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
51 read10xFiles <- function(filein, typein){ |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
52 sce <- NULL |
|
1335bf5bcd0e
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
94ee8160ace3
"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 |
|
94ee8160ace3
"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 |
|
94ee8160ace3
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
57 } |
|
5
d5e4b59d5331
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit ea9a67b5711b53fb911a0c50b6b49eb9db2366a7"
iuc
parents:
3
diff
changeset
|
58 else if (typein == "h5"){ |
|
0
1335bf5bcd0e
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 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
60 } |
|
1335bf5bcd0e
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"){ |
|
1335bf5bcd0e
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") |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
63 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
64 counts(sce) <- setSparse(counts(sce)) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
65 return(sce) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
66 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
67 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
68 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
69 ## Methods |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
70 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
71 |
|
5
d5e4b59d5331
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit ea9a67b5711b53fb911a0c50b6b49eb9db2366a7"
iuc
parents:
3
diff
changeset
|
72 doEmptyDrops <- function(files, eparams, in.type="directory", out.type="h5", fdr_threshold = 0.01){ |
|
0
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
74 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
75 eparams$... <- NULL ## hack |
|
1335bf5bcd0e
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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
77 |
|
0
1335bf5bcd0e
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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
79 |
|
0
1335bf5bcd0e
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
58105e5efa8d
"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
1335bf5bcd0e
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.") |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
83 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
84 e.out <- cbind(bar.names, e.out) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
85 e.out$is.Cell <- e.out$FDR <= fdr_threshold |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
86 e.out$is.CellAndLimited <- e.out$is.Cell & e.out$Limited |
|
2
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
87 |
|
58105e5efa8d
"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 |
|
58105e5efa8d
"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 |
|
58105e5efa8d
"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 |
|
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
91 |
|
58105e5efa8d
"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 |
|
58105e5efa8d
"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),]) |
|
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
94 |
|
0
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
95 png(files$plot) |
|
1335bf5bcd0e
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
58105e5efa8d
"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", |
|
58105e5efa8d
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
99 dev.off() |
|
2
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
100 |
|
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
101 ## Filtered |
|
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
102 called <- NULL |
|
58105e5efa8d
"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){ |
|
58105e5efa8d
"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 |
|
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
105 } else { |
|
58105e5efa8d
"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 |
|
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
107 } |
|
0
1335bf5bcd0e
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 |
|
1335bf5bcd0e
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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
110 |
|
3
2bbf0052aaa9
"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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
112 |
|
58105e5efa8d
"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)))) |
|
58105e5efa8d
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
115 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
116 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
117 |
|
5
d5e4b59d5331
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit ea9a67b5711b53fb911a0c50b6b49eb9db2366a7"
iuc
parents:
3
diff
changeset
|
118 doDefaultDrops <- function(files, dparams, in.type="directory", out.type="h5"){ |
|
0
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
120 |
|
1
94ee8160ace3
"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
1335bf5bcd0e
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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
123 |
|
0
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
124 # Filtered |
|
1335bf5bcd0e
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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
126 |
|
3
2bbf0052aaa9
"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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
128 |
|
58105e5efa8d
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
130 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
131 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
132 |
|
1335bf5bcd0e
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"){ |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
135 |
|
1335bf5bcd0e
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
94ee8160ace3
"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
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
138 |
|
1335bf5bcd0e
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
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
140 |
|
0
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
141 png(files$plot) |
|
1335bf5bcd0e
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") |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
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") |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
145 |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
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")) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
149 dev.off() |
|
2
58105e5efa8d
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit 4d89eb1eb951ef094d1f77c46824d9c38be4445b"
iuc
parents:
1
diff
changeset
|
150 |
|
0
1335bf5bcd0e
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)) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
152 } |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
153 |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
154 ## Main |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
156 |
|
1335bf5bcd0e
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") { |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
159 |
|
1335bf5bcd0e
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") { |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
162 |
|
1335bf5bcd0e
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") { |
|
1335bf5bcd0e
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) |
|
1335bf5bcd0e
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
165 } |
