forked from katholt/plotTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
192 lines (156 loc) · 5.7 KB
/
Copy pathserver.R
File metadata and controls
192 lines (156 loc) · 5.7 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
library(shiny)
library(ape)
source("plotTree.R")
shinyServer( function(input, output, session) {
# An event observer for changes to INFO CSV file
observeEvent(input$info_file,
{
# read the CSV file and get the column names.
# re-reading this file repeatedly is inefficient
df = read.table(input$info_file$datapath, header=TRUE, sep=',')
# build a list of values, this is what is required by update methods
info_cols = list()
for (v in colnames(df)) {
info_cols[v] = v
}
# update the two input widgets using the column names
updateSelectInput(session, inputId='colour_tips_by', choices=c('(none)',info_cols[-1]))
updateSelectInput(session, inputId='print_column', choices=c(info_cols[-1]))
# switch on the meta data plotting option
updateCheckboxInput(session, inputId='info_data', value=TRUE)
}
)
# An event observer for changes to HEATMAP file
observeEvent(input$heatmap,
{
# switch on the heatmap plotting option
updateCheckboxInput(session, inputId='chk_heatmap', value=TRUE)
}
)
# An event observer for changes to BAR DATA file
observeEvent(input$barData,
{
# switch on the heatmap plotting option
updateCheckboxInput(session, inputId='chk_barplot', value=TRUE)
}
)
# An event observer for changes to BLOCKS file
observeEvent(input$blockFile,
{
# switch on the heatmap plotting option
updateCheckboxInput(session, inputId='chk_blocks', value=TRUE)
}
)
# An event observer for changes to SNPs file
observeEvent(input$snpFile,
{
# switch on the heatmap plotting option
updateCheckboxInput(session, inputId='chk_snps', value=TRUE)
}
)
output$Tree <- renderPlot({
input$drawButton == 0
### ALL VARIABLES PULLED FROM 'input' GO INSIDE HERE
isolate ( {
l<-input$Layout
t<-input$Tree
i<-input$Info
o<-input$Other
d<-input$Data
treeFile <- input$tree$datapath
# tree plotting options
label_tips <- input$label_tips
tree_line_width <- as.integer(input$tree_line_width)
branch_colour <- input$branch_colour
tipLabelSize <- as.integer(input$tipLabelSize)
offset <- as.integer(input$offset)
# metadata variables
infoFile <- input$info_file$datapath
tip_size <- input$tip_size
colour_tips_by <- input$colour_tips_by
if (colour_tips_by == '(none)') {colour_tips_by <- NULL}
ancestral <- input$ancestral
pie_size <- input$pie_size
legend <- input$legend
legend_pos <- input$legend_pos
print_column <- input$print_column
print_metadata <- input$print_metadata
if (!print_metadata) { print_column <- NA }
# heatmap variables
heatmapFile <- input$heatmap$datapath
cluster <- input$clustering
heatmapDecimalPlaces <- as.integer(input$heatmapDecimalPlaces)
colLabelCex <- as.integer(input$colLabelCex)
vlines_heatmap_col <-input$vlines_heatmap_col
vlines_heatmap <- input$vlines_heatmap
# heatColoursSpecify <- input$heatColoursSpecify
# if (heatColoursSpecify) {
# heatmap_colours <- input$heatmap_colour_vector
# }
# else {
heatmap_colours <- colorRampPalette(c(input$start_col,input$middle_col,input$end_col),space="rgb")(as.integer(input$heatmap_breaks))
# }
# barplot variables
barDataFile <- input$barData$datapath
barDataCol <- input$barDataCol
# block plot variables
blockFile <- input$blockFile$datapath
block_colour <- input$block_colour
blwd <- input$blwd
genome_size <- input$genome_size
snpFile <- input$snpFile$datapath
snp_colour <- input$snp_colour
# Layout/spacing
tree_width <- as.numeric(input$tree_width)
info_width <- as.numeric(input$info_width)
heatmap_width <- as.numeric(input$heatmap_width)
bar_width <- as.numeric(input$bar_width)
genome_width <- as.numeric(input$genome_width)
main_height <- as.numeric(input$main_height)
label_height <- as.numeric(input$label_height)
edge_width <- as.numeric(input$edge_width)
# TRACK DATA TYPES TO PLOT
chk_heatmap <- input$chk_heatmap
info_data <- input$info_data
chk_barplot <- input$chk_barplot
chk_blocks <- input$chk_blocks
chk_snps <- input$chk_snps
if (is.null(treeFile)) { return(NULL) }
if (!info_data) { infoFile <- NULL }
else { infoFile <- infoFile }
if (!chk_heatmap) { heatmapFile <- NULL }
else { heatmapFile <- heatmapFile }
if (!chk_barplot) { barDataFile <- NULL }
else { barDataFile <- barDataFile }
if (!chk_blocks) { blockFile <- NULL }
else { blockFile <- blockFile }
if (!chk_snps) { snpFile <- NULL }
else { snpFile <- snpFile }
}) # end isolate
### PLOT THE TREE
# main plotting function
doPlotTree <-function() {
# underlying call to plotTree(), drawn to screen and to file
plotTree(tree=treeFile,
tip.labels=label_tips, tipLabelSize=tipLabelSize, offset=offset,
lwd=tree_line_width, edge.color=branch_colour,
infoFile=infoFile, infoCols=print_column,
colourNodesBy=colour_tips_by, tip.colour.cex=tip_size,
ancestral.reconstruction=ancestral, pie.cex=pie_size,
legend=legend, legend.pos=legend_pos,
heatmapData=heatmapFile, cluster=cluster,
heatmap.colours=heatmap_colours,
heatmapDecimalPlaces=heatmapDecimalPlaces, colLabelCex=colLabelCex,
vlines.heatmap=vlines_heatmap, vlines.heatmap.col=vlines_heatmap_col,
barData=barDataFile, barDataCol=barDataCol,
blockFile=blockFile, block_colour=block_colour, blwd=blwd,
genome_size=genome_size,
snpFile=snpFile, snp_colour=snp_colour,
treeWidth=tree_width, infoWidth=info_width, dataWidth=heatmap_width,
barDataWidth=bar_width, blockPlotWidth=genome_width,
mainHeight=main_height, labelHeight=label_height, edgeWidth=edge_width
)
}
doPlotTree()
}) # end render plot
}) # shinyServer