comparison scater-pca-filter.R @ 0:e6ca62ac65c6 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
author iuc
date Thu, 18 Jul 2019 11:13:41 -0400
parents
children 7a365ec81b52
comparison
equal deleted inserted replaced
-1:000000000000 0:e6ca62ac65c6
1 #!/usr/bin/env Rscript
2 #Filters a SingleCellExperiment object, using PCA on the following metrics:
3 # "pct_counts_top_100_features"
4 # "total_features"
5 # "pct_counts_feature_control"
6 # "total_features_feature_control"
7 # "log10_total_counts_endogenous"
8 # "log10_total_counts_feature_control"
9
10 # Load optparse we need to check inputs
11 library(optparse)
12 library(workflowscriptscommon)
13 library(LoomExperiment)
14 library(scater)
15 library(mvoutlier)
16
17 # parse options
18 option_list = list(
19 make_option(
20 c("-i", "--input-loom"),
21 action = "store",
22 default = NA,
23 type = 'character',
24 help = "A SingleCellExperiment object file in Loom format."
25 ),
26 make_option(
27 c("-o", "--output-loom"),
28 action = "store",
29 default = NA,
30 type = 'character',
31 help = "File name in which to store the SingleCellExperiment object in Loom format."
32 )
33 )
34
35 opt <- wsc_parse_args(option_list, mandatory = c('input_loom', 'output_loom'))
36
37 # Check parameter values
38
39 if ( ! file.exists(opt$input_loom)){
40 stop((paste('File', opt$input_loom, 'does not exist')))
41 }
42
43 # Input from Loom format
44
45 scle <- import(opt$input_loom, format='loom', type='SingleCellLoomExperiment')
46 print(paste("Starting with", ncol(scle), "cells and", nrow(scle), "features."))
47
48 # Run PCA on data and detect outliers
49 scle <- runPCA(scle, use_coldata = TRUE, detect_outliers = TRUE)
50
51 # Filter out outliers
52 scle <- scle[, !scle$outlier]
53
54 print(paste("Ending with", ncol(scle), "cells and", nrow(scle), "features."))
55
56 # Output to a Loom file
57 if (file.exists(opt$output_loom)) {
58 file.remove(opt$output_loom)
59 }
60 export(scle, opt$output_loom, format='loom')