Mercurial > repos > iuc > scater_plot_tsne
comparison scater-pca-filter.R @ 1:2b09ca1c5e41 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
author | iuc |
---|---|
date | Thu, 09 Sep 2021 12:24:39 +0000 |
parents | a30f4bfe8f01 |
children |
comparison
equal
deleted
inserted
replaced
0:a30f4bfe8f01 | 1:2b09ca1c5e41 |
---|---|
10 # Load optparse we need to check inputs | 10 # Load optparse we need to check inputs |
11 library(optparse) | 11 library(optparse) |
12 library(workflowscriptscommon) | 12 library(workflowscriptscommon) |
13 library(LoomExperiment) | 13 library(LoomExperiment) |
14 library(scater) | 14 library(scater) |
15 library(mvoutlier) | 15 library(robustbase) |
16 | 16 |
17 # parse options | 17 # parse options |
18 option_list = list( | 18 option_list <- list( |
19 make_option( | 19 make_option( |
20 c("-i", "--input-loom"), | 20 c("-i", "--input-loom"), |
21 action = "store", | 21 action = "store", |
22 default = NA, | 22 default = NA, |
23 type = 'character', | 23 type = "character", |
24 help = "A SingleCellExperiment object file in Loom format." | 24 help = "A SingleCellExperiment object file in Loom format." |
25 ), | 25 ), |
26 make_option( | 26 make_option( |
27 c("-o", "--output-loom"), | 27 c("-o", "--output-loom"), |
28 action = "store", | 28 action = "store", |
29 default = NA, | 29 default = NA, |
30 type = 'character', | 30 type = "character", |
31 help = "File name in which to store the SingleCellExperiment object in Loom format." | 31 help = "File name in which to store the SingleCellExperiment object in Loom format." |
32 ) | 32 ) |
33 ) | 33 ) |
34 | 34 |
35 opt <- wsc_parse_args(option_list, mandatory = c('input_loom', 'output_loom')) | 35 opt <- wsc_parse_args(option_list, mandatory = c("input_loom", "output_loom")) |
36 | 36 |
37 # Check parameter values | 37 # Check parameter values |
38 | 38 |
39 if ( ! file.exists(opt$input_loom)){ | 39 if (! file.exists(opt$input_loom)) { |
40 stop((paste('File', opt$input_loom, 'does not exist'))) | 40 stop((paste("File", opt$input_loom, "does not exist"))) |
41 } | 41 } |
42 | 42 |
43 # Input from Loom format | 43 # Filter out unexpressed features |
44 | 44 |
45 scle <- import(opt$input_loom, format='loom', type='SingleCellLoomExperiment') | 45 sce <- import(opt$input_loom, format = "loom", type = "SingleCellLoomExperiment") |
46 print(paste("Starting with", ncol(scle), "cells and", nrow(scle), "features.")) | |
47 | 46 |
48 # Run PCA on data and detect outliers | 47 print(paste("Starting with", ncol(sce), "cells")) |
49 scle <- runPCA(scle, use_coldata = TRUE, detect_outliers = TRUE) | |
50 | 48 |
51 # Filter out outliers | 49 sce <- runColDataPCA(sce, outliers = TRUE, variables = list("sum", "detected", "subsets_Mito_percent")) |
52 scle <- scle[, !scle$outlier] | 50 sce$use <- !sce$outlier |
51 sce <- sce[, colData(sce)$use] | |
52 print(paste("Ending with", ncol(sce), "cells")) | |
53 | 53 |
54 print(paste("Ending with", ncol(scle), "cells and", nrow(scle), "features.")) | |
55 | 54 |
56 # Output to a Loom file | 55 # Output to a Loom file |
57 if (file.exists(opt$output_loom)) { | 56 if (file.exists(opt$output_loom)) { |
58 file.remove(opt$output_loom) | 57 file.remove(opt$output_loom) |
59 } | 58 } |
60 export(scle, opt$output_loom, format='loom') | 59 export(sce, opt$output_loom, format = "loom") |