-
Notifications
You must be signed in to change notification settings - Fork 5
/
seurat-hover-locator.R
executable file
·125 lines (110 loc) · 3.88 KB
/
seurat-hover-locator.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env Rscript
# This script has been automatically generated through
#
# YAML2RScript.py -i ../r-seurat-scripts/cli-generated/manually_crafted_YAML/seurat-hover-locator.yaml -o ../r-seurat-scripts/seurat-hover-locator.R
#
# to change this file edit the input YAML and re-run the above command
suppressPackageStartupMessages(require(Seurat))
suppressPackageStartupMessages(require(workflowscriptscommon))
suppressPackageStartupMessages(require(plotly))
suppressPackageStartupMessages(require(ggplot2))
suppressPackageStartupMessages(require(data.table))
suppressPackageStartupMessages(require(htmlwidgets))
suppressPackageStartupMessages(require(optparse))
option_list <- list(
make_option(
c("--plot-rds"),
action = "store",
metavar = "RDS with ggplot2 object from Seurat 4",
type = "character",
help = "FILE IN"
),
make_option(
c("--information-table"),
action = "store",
default = NULL,
type = "character",
help = "Table with information for overlaying on the plot. Usually the result of calling FetchData on the original Seurat object."
),
make_option(
c("--do-not-stringsAsFactors"),
action = "store_false",
default = TRUE,
type = "logical",
help = "Load strings as factors."
),
make_option(
c("--key"),
action = "store",
default = NULL,
type = "character",
help = "Key (index) for the information table"
),
make_option(
c("--do-not-keepLeadingZeros"),
action = "store_false",
default = TRUE,
type = "logical",
help = "If TRUE a column containing numeric data with leading zeros will be read as character, otherwise leading zeros will be removed and converted to numeric."
),
make_option(
c("--do-not-axes"),
action = "store_false",
default = TRUE,
type = "logical",
help = "Display x- and y-axes"
),
make_option(
c("--dark-theme"),
action = "store_true",
default = FALSE,
type = "logical",
help = "Plot using a dark theme?"
),
make_option(
c("--output-html"),
action = "store",
type = "character",
help = "HTML output file"
),
make_option(
c("--do-not-selfcontained"),
action = "store_false",
default = TRUE,
type = "logical",
help = "Whether to save the HTML as a single self-contained file (with external resources base64 encoded) or a file with external resources placed in an adjacent directory."
),
make_option(
c("--libdir"),
action = "store",
default = NULL,
type = "character",
help = "Directory to copy HTML dependencies into (defaults to filename_files)."
)
)
opt <- wsc_parse_args(option_list,
mandatory = c("plot_rds", "output_html"))
if ( !file.exists(opt$plot_rds)) {
stop((paste("File", opt$plot_rds, "does not exist")))
}
if (!is.null(opt$information_table) && !file.exists(opt$information_table)) {
stop((paste("File", opt$information_table, "does not exist")))
}
ggplot2_object <- readRDS(file = opt$plot_rds)
if (!is.null(opt$information_table)) {
info_df <- fread(file = opt$information_table,
stringsAsFactors = opt$do_not_stringsAsFactors,
key = opt$key,
keepLeadingZeros = opt$do_not_keepLeadingZeros)
} else {
info_df <- NULL
}
plotly_obj <- HoverLocator(plot = ggplot2_object,
information = info_df,
axes = opt$do_not_axes,
dark.theme = opt$dark_theme)
plotly_widget <- as.widget(x = plotly_obj)
saveWidget(widget = plotly_widget,
file = opt$output_html,
selfcontained = opt$do_not_selfcontained,
libdir = opt$libdir)