Mercurial > repos > iuc > dropletutils
annotate scripts/dropletutils.Rscript @ 0:4cd9f0008d9c draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
author | iuc |
---|---|
date | Tue, 04 Jun 2019 17:19:52 -0400 |
parents | |
children | cfe1e6c28d95 |
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))) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
9 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
10 source(args[1]) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
11 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
12 ## Helper functions |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
13 setSparse <- function(obj){ |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
14 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
|
15 } |
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 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
|
18 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
|
19 } |
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 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
|
22 if (typeout == "tsv"){ |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
23 writeTSV(fileout, counts) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
24 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
25 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
|
26 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
|
27 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
28 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
|
29 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
|
30 } |
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 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
|
35 sce <- NULL |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
36 if (typein == "tsv"){ |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
37 dat <- read.table(filein, header = TRUE, sep='\t', stringsAsFactors=FALSE, quote="", row.names=1) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
38 sce <- SingleCellExperiment(assays = list(counts = as.matrix(dat))) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
39 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
40 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
|
41 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
|
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 (typein == "directory"){ |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
44 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
|
45 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
46 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
|
47 return(sce) |
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 ## Methods |
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 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
54 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
|
55 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
|
56 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
57 eparams$... <- NULL ## hack |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
58 eparams$m = Matrix(counts(sce), sparse=TRUE) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
59 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
60 e.out <- do.call(emptyDrops, c(eparams)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
61 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
62 bar.names <- colnames(sce) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
63 if (length(bar.names) != nrow(e.out)){ |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
64 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
|
65 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
66 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
|
67 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
|
68 e.out$is.CellAndLimited <- e.out$is.Cell & e.out$Limited |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
69 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
70 # Write to table |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
71 writeTSV(files$table, e.out) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
72 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
73 # Print to log |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
74 print(table(Limited=e.out$Limited, Significant=e.out$is.Cell)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
75 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
76 # Write to Plot |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
77 png(files$plot) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
78 plot(e.out$Total, -e.out$LogProb, col=ifelse(e.out$is.Cell, "red", "black"), |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
79 xlab="Total UMI count", ylab="-Log Probability") |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
80 dev.off() |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
81 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
82 # Filtered |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
83 called <- e.out$is.CellAndLimited |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
84 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
|
85 sce.filtered <- sce[,called] |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
86 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
87 writeOut(counts(sce.filtered), files$out, out.type) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
88 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
89 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
90 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
91 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
|
92 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
|
93 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
94 dparams$m = as.matrix(counts(sce)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
95 called <- do.call(defaultDrops, c(dparams)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
96 print(table(called)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
97 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
98 # Filtered |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
99 sce.filtered <- sce[,called] |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
100 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
101 writeOut(Matrix(counts(sce.filtered),sparse=TRUE), files$out, out.type) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
102 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
103 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
104 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
105 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
|
106 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
|
107 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
108 bparams$... <- NULL ## hack |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
109 bparams$m = as.matrix(counts(sce)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
110 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
111 br.out <- do.call(barcodeRanks, c(bparams)) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
112 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
113 png(files$plot) |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 dev.off() |
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 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
|
124 } |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
125 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
126 ## Main |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
127 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
|
128 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
129 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
|
130 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
|
131 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
132 } 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
|
133 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
|
134 |
4cd9f0008d9c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/dropletutils/ commit e66ab3d4fc0c1a72523e8f93447cc07cdd6816b7
iuc
parents:
diff
changeset
|
135 } 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
|
136 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
|
137 } |