Mercurial > repos > iuc > scater_plot_tsne
annotate scater-plot-tsne.R @ 2:99f912d5af9f draft default tip
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 9961b5acbf9081f10e14bc272406b36854fa2924"
author | iuc |
---|---|
date | Mon, 08 Nov 2021 12:03:09 +0000 |
parents | 2b09ca1c5e41 |
children |
rev | line source |
---|---|
0
a30f4bfe8f01
"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 |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
2 |
a30f4bfe8f01
"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. |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
4 |
a30f4bfe8f01
"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 |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
6 |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
7 library(optparse) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
8 library(workflowscriptscommon) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
9 library(LoomExperiment) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
10 library(scater) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
11 library(Rtsne) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
12 |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
13 # parse options |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
14 |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
15 option_list <- list( |
0
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
16 make_option( |
a30f4bfe8f01
"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"), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
18 action = "store", |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
19 default = NA, |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
20 type = "character", |
0
a30f4bfe8f01
"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." |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
22 ), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
23 make_option( |
a30f4bfe8f01
"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"), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
25 action = "store", |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
26 default = NULL, |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
27 type = "character", |
0
a30f4bfe8f01
"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" |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
29 ), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
30 make_option( |
a30f4bfe8f01
"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"), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
32 action = "store", |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
33 default = NULL, |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
34 type = "character", |
0
a30f4bfe8f01
"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" |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
36 ), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
37 make_option( |
a30f4bfe8f01
"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"), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
39 action = "store", |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
40 default = NULL, |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
41 type = "character", |
0
a30f4bfe8f01
"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" |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
43 ), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
44 make_option( |
a30f4bfe8f01
"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"), |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
46 action = "store", |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
47 default = NA, |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
48 type = "character", |
0
a30f4bfe8f01
"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." |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
50 ) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
51 ) |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
52 |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
53 opt <- wsc_parse_args(option_list, mandatory = c("input_loom", "output_plot_file")) |
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
54 |
0
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
55 # Check parameter values |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
56 |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
57 if (! file.exists(opt$input_loom)) { |
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
58 stop((paste("File", opt$input_loom, "does not exist"))) |
0
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
59 } |
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
60 |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
61 # Filter out unexpressed features |
0
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
62 |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
63 sce <- import(opt$input_loom, format = "loom", type = "SingleCellLoomExperiment") |
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
64 sce <- logNormCounts(sce) |
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
65 sce <- runTSNE(sce, perplexity = 10) |
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
66 plot <- plotTSNE(sce, colour_by = opt$colour_by, size_by = opt$size_by, shape_by = opt$shape_by) |
0
a30f4bfe8f01
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 61f3899168453092fd25691cf31871a3a350fd3b"
iuc
parents:
diff
changeset
|
67 |
1
2b09ca1c5e41
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scater commit 154318f74839a4481c7c68993c4fb745842c4cce"
iuc
parents:
0
diff
changeset
|
68 ggsave(opt$output_plot_file, plot, device = "pdf") |