Mercurial > repos > iuc > scater_plot_dist_scatter
annotate scater-plot-pca.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 | 81e5bdff4853 | 
| rev | line source | 
|---|---|
| 
0
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env Rscript | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
2 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
3 # Creates a PCA plot of a normalised SingleCellExperiment object. | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
4 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
5 # Load optparse we need to check inputs | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
6 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
7 library(optparse) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
8 library(workflowscriptscommon) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
9 library(LoomExperiment) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
10 library(scater) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
11 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
12 # parse options | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
13 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
14 option_list = list( | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
15 make_option( | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
16 c("-i", "--input-loom"), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
17 action = "store", | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
18 default = NA, | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
19 type = 'character', | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
20 help = "A SingleCellExperiment object file in Loom format." | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
21 ), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
22 make_option( | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
23 c("-c", "--colour-by"), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
24 action = "store", | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
25 default = NULL, | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
26 type = 'character', | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
27 help = "Feature (from annotation file) to colour PCA plot points by. The values represented in this options should be categorical" | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
28 ), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
29 make_option( | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
30 c("-s", "--size-by"), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
31 action = "store", | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
32 default = NULL, | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
33 type = 'character', | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
34 help = "Feature (from annotation file) to size PCA plot points by. The values represented in this options should be numerical and not categorical" | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
35 ), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
36 make_option( | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
37 c("-p", "--shape-by"), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
38 action = "store", | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
39 default = NULL, | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
40 type = 'character', | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
41 help = "Feature (from annotation file) to shape PCA plot points by. The values represented in this options should be categorical" | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
42 ), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
43 make_option( | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
44 c("-o", "--output-plot-file"), | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
45 action = "store", | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
46 default = NA, | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
47 type = 'character', | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
48 help = "Path of the PDF output file to save plot to." | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
49 ) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
50 ) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
51 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
52 opt <- wsc_parse_args(option_list, mandatory = c('input_loom', 'output_plot_file')) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
53 # Check parameter values | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
54 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
55 if ( ! file.exists(opt$input_loom)){ | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
56 stop((paste('File', opt$input_loom, 'does not exist'))) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
57 } | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
58 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
59 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
60 # Input from Loom format | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
61 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
62 scle <- import(opt$input_loom, format='loom', type='SingleCellLoomExperiment') | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
63 scle <- normalize(scle, exprs_values = 1) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
64 scle <- runPCA(scle) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
65 plot <- plotReducedDim(scle, "PCA", colour_by = opt$colour_by, size_by = opt$size_by, shape_by = opt$shape_by) | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
66 #do the scatter plot of reads vs genes | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
67 | 
| 
 
4887c4c69847
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 5fdcafccb6c645d301db040dfeed693d7b6b4278
 
iuc 
parents:  
diff
changeset
 | 
68 ggsave(opt$output_plot_file, plot, device="pdf") | 
