comparison scater-plot-dist-scatter.R @ 0:4887c4c69847 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:12:33 -0400
parents
children 2e41b35b5bdd
comparison
equal deleted inserted replaced
-1:000000000000 0:4887c4c69847
1 #!/usr/bin/env Rscript
2
3 # Plot the distribution of read counts and feature counts, side by side, then a scatter plot of read counts vs feature counts below
4
5 # Load optparse we need to check inputs
6
7 library(optparse)
8 library(workflowscriptscommon)
9 library(LoomExperiment)
10 library(scater)
11 library(ggpubr)
12
13 # parse options
14
15 option_list = list(
16 make_option(
17 c("-i", "--input-loom"),
18 action = "store",
19 default = NA,
20 type = 'character',
21 help = "A SingleCellExperiment object file in Loom format."
22 ),
23 make_option(
24 c("-o", "--output-plot-file"),
25 action = "store",
26 default = NA,
27 type = 'character',
28 help = "Path of the PDF output file to save plot to."
29 )
30 )
31
32 opt <- wsc_parse_args(option_list, mandatory = c('input_loom', 'output_plot_file'))
33
34 # Check parameter values
35
36 if ( ! file.exists(opt$input_loom)){
37 stop((paste('File', opt$input_loom, 'does not exist')))
38 }
39
40 # Input from Loom format
41
42 scle <- import(opt$input_loom, format='loom', type='SingleCellLoomExperiment')
43
44 #do the scatter plot of reads vs genes
45 total_counts <- scle$total_counts
46 total_features <- scle$total_features_by_counts
47 count_feats <- cbind(total_counts, total_features)
48 cf_dm <- as.data.frame(count_feats)
49
50 # Calculate binwidths for reads and features plots. Use 20 bins
51 read_bins <- max(total_counts / 1e6) / 20
52 feat_bins <- max(total_features) / 20
53
54 #make the plots
55 plot <- ggplot(cf_dm, aes(x=total_counts / 1e6, y=total_features)) + geom_point(shape=1) + geom_smooth() + xlab("Read count (millions)") +
56 ylab("Feature count") + ggtitle("Scatterplot of reads vs features")
57 plot1 <- qplot(total_counts / 1e6, geom="histogram", binwidth = read_bins, ylab="Number of cells", xlab = "Read counts (millions)", fill=I("darkseagreen3")) + ggtitle("Read counts per cell")
58 plot2 <- qplot(total_features, geom="histogram", binwidth = feat_bins, ylab="Number of cells", xlab = "Feature counts", fill=I("darkseagreen3")) + ggtitle("Feature counts per cell")
59 plot3 <- plotColData(scle, y="pct_counts_MT", x="total_features_by_counts") + ggtitle("% MT genes") + geom_point(shape=1) + theme(text = element_text(size=15)) + theme(plot.title = element_text(size=15))
60
61 final_plot <- ggarrange(plot1, plot2, plot, plot3, ncol=2, nrow=2)
62 ggsave(opt$output_plot_file, final_plot, device="pdf")