comparison signac-vlnplot.R @ 0:6e0b320d8b6a draft default tip

"planemo upload commit dc808171975d0012e25bd7b32adc7a5a5c56a145-dirty"
author gaelcge
date Tue, 02 Aug 2022 19:11:27 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6e0b320d8b6a
1 #!/usr/bin/env Rscript
2
3 # Load optparse we need to check inputs
4
5 suppressPackageStartupMessages(require(optparse))
6
7 # Load common functions
8
9 suppressPackageStartupMessages(require(workflowscriptscommon))
10
11 # parse options
12
13 option_list = list(
14 make_option(
15 c("--signac-object"),
16 action = "store",
17 default = NA,
18 type = 'character',
19 help = ""
20 ),
21 make_option(
22 c("--features"),
23 action = "store",
24 default = NA,
25 type = 'character',
26 help = "File to be used to derive a vector of genes to test."
27 ),
28 make_option(
29 c("--cols"),
30 action = "store",
31 default = NULL,
32 type = 'character',
33 help = "File to be used to derive a vector of colors."
34 ),
35 make_option(
36 c("-p", "--pt-size"),
37 action = "store",
38 default = 1,
39 type = 'integer',
40 help = "Adjust point size for plotting."
41 ),
42 make_option(
43 c("--group-by"),
44 action = "store",
45 default = "ident",
46 type = 'character',
47 help = "Group (color) cells in different ways (for example, orig.ident)."
48 ),
49 make_option(
50 c("--sort"),
51 action = "store",
52 type = 'logical',
53 help = "Sort identity classes (on the x-axis) by the average expression of the attribute being potted, can also pass 'increasing' or 'decreasing' to change sort direction."
54 ),
55 make_option(
56 c("--assay"),
57 action = "store",
58 default = NULL,
59 type = 'character',
60 help = "Name of assay to use, defaults to the active assay."
61 ),
62 # make_option(
63 # c("--split-by"),
64 # action = "store",
65 # default = NULL,
66 # type = 'character',
67 # help = "A variable to split the violin plots by."
68 # ),
69 make_option(
70 c("--same-y-lims"),
71 action = "store",
72 default = FALSE,
73 type = 'logical',
74 help = "Set all the y-axis limits to the same values."
75 ),
76 make_option(
77 c("--log"),
78 action = "store",
79 default = FALSE,
80 type = 'logical',
81 help = "plot the feature axis on log scale."
82 ),
83 make_option(
84 c("--ncol"),
85 action = "store",
86 default = NULL,
87 type = 'integer',
88 help = "Number of columns if multiple plots are displayed."
89 ),
90 make_option(
91 c("--slot"),
92 action = "store",
93 default = 'data',
94 type = 'character',
95 help = "Use non-normalized counts data for plotting."
96 ),
97 # make_option(
98 # c("--split-plot"),
99 # action = "store",
100 # default = FALSE,
101 # type = 'logical',
102 # help = "plot each group of the split violin plots by multiple or single violin shapes."
103 # ),
104 make_option(
105 c("--stack"),
106 action = "store",
107 default = FALSE,
108 type = 'logical',
109 help = "Horizontally stack plots for each feature."
110 ),
111 make_option(
112 c("--fill-by"),
113 action = "store",
114 default = 'feature',
115 type = 'character',
116 help = "Color violins/ridges based on either 'feature' or 'ident'."
117 ),
118 make_option(
119 c("--flip"),
120 action = "store",
121 default = FALSE,
122 type = 'logical',
123 help = "flip plot orientation (identities on x-axis)."
124 ),
125 make_option(
126 c("--png-width"),
127 action = "store",
128 default = 1000,
129 type = 'integer',
130 help = "Width of png (px)."
131 ),
132 make_option(
133 c("--png-height"),
134 action = "store",
135 default = 1000,
136 type = 'integer',
137 help = "Height of png file (px)."
138 ),
139 make_option(
140 c("--output_image_file"),
141 action = "store",
142 default = NA,
143 type = 'character',
144 help = "File name in which to store serialized R matrix object."
145 )
146 )
147
148 opt <- wsc_parse_args(option_list)
149
150 suppressPackageStartupMessages(require(Seurat))
151 suppressPackageStartupMessages(require(Signac))
152
153 set.seed(1234)
154
155 if (! file.exists(opt$signac_object)){
156 stop((paste('File', opt$signac_object, 'does not exist')))
157 }
158
159 # Check features
160 features <- NULL
161 if (! is.null(opt$features) && opt$features != 'NULL'){
162 features <- strsplit(opt$features, ",")[[1]]
163 }
164
165 # Check cols
166 cols <- NULL
167 if (! is.null(opt$cols) && opt$cols != 'NULL'){
168 if (! file.exists(opt$cols)){
169 stop((paste('Supplied features file', opt$cols, 'does not exist')))
170 }else{
171 cols <- readLines(opt$cols)
172 }
173 }
174
175 # Check assay
176 assay <- NULL
177 if (! is.null(opt$assay) && opt$assay != 'NULL'){
178 assay <- opt$assay
179 }
180
181 # extract gene annotations from EnsDb
182 signac_object <- readRDS(file = opt$signac_object)
183
184 group_by <- if(opt$group_by == 'ident'){
185 NULL
186 }else{
187 opt$group_by
188 }
189
190 # sort <- if(opt$sort == 'False'){
191 # FALSE
192 # }else{
193 # TRUE
194 # }
195
196 png(filename = opt$output_image_file, width = opt$png_width, height = opt$png_height)
197 VlnPlot(object = signac_object,
198 features = features,
199 cols = cols,
200 pt.size = opt$pt_size,
201 group.by = group_by,
202 sort = opt$sort,
203 assay = assay,
204 #split.by = opt$split_by,
205 same.y.lims = opt$same_y_lims,
206 log = opt$log,
207 ncol = opt$ncol,
208 slot = opt$slot,
209 #split.plot = opt$split_plot,
210 stack = opt$stack,
211 fill.by = opt$fill_by,
212 flip = opt$flip
213 )
214 dev.off()