comparison scripts/raceID_filter.R @ 0:ea8215239735 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid commit 39918bfdb08f06862ca395ce58a6f5e4f6dd1a5e
author iuc
date Sat, 03 Mar 2018 17:33:56 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ea8215239735
1 #!/usr/bin/env Rscript
2
3 args = commandArgs(trailingOnly=T)
4
5 script_dir = args[1]
6 config_file = args[2]
7
8 # Load libs, common functions, source RaceID and Galaxy Params
9 source(paste(script_dir, "common.R", sep="/"))
10
11 # Read input data
12 x <- read.csv(count_matrix, sep="\t", header=TRUE)
13 rownames(x) <- x[,1]
14
15 message("Count matrix with %.0f cells and %.0f genes", dim(x)[1], dim(x)[2])
16
17 # Control gene filtering
18 # (if blank do nothing)
19 if (!( (!exists("control_genes_filter")) || control_genes_filter == "" || control_genes_filter == "None")){
20 c_genes <- unlist(strsplit(control_genes_filter, "\\s*,\\s"))
21 for (cg in c_genes){
22 x <- x[grep(cg, rownames(x), invert=T), -1]
23 message("Filtering against %s yielded %.0f cells and %.0f genes", cg, dim(x)[1], dim(x)[2])
24 }
25 } else {
26 x <- x[grep("INVALID", rownames(x), invert=T), -1]
27 }
28
29 if (!filtering){
30 # No filtering, just return an SCseq object
31 sc <- SCseq(x)
32 saveRDS(sc, output_rdat)
33 quit(status=0)
34 }
35
36
37 sc <- SCseq(x)
38
39 if (c_maxexpr == 0){
40 c_maxexpr = Inf
41 }
42
43 # Perform actual filtering beyond this point
44 message("Applying filtering parameters: mintotal = %.0f, minexpr = %.0f, minnumber= %.0f, maxexpr= %.0f, downsample= %.0f, dsn= %.0f, rseed=%.0f", c_mintotal, c_minexpr, c_minnumber, c_maxexpr, c_downsample, c_dsn, c_rseed)
45
46 sc <- filterdata(sc,
47 mintotal=c_mintotal,
48 minexpr=c_minexpr,
49 minnumber=c_minnumber,
50 maxexpr=c_maxexpr, downsample = c_downsample, dsn=c_dsn, rseed=c_rseed)
51
52 message("Output matrix yielded %.0f cells and %.0f genes", dim(sc@fdata)[1], dim(sc@fdata)[2])
53
54 # Output table
55 write.table(sc@fdata, output_table, row.names = T, col.names = T, sep="\t", quote=F)
56 # Output R object
57 saveRDS(sc, output_rdat)
58