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