-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
179 lines (138 loc) · 6.03 KB
/
Copy pathserver.R
File metadata and controls
179 lines (138 loc) · 6.03 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
library(shiny)
require(pixelgram)
shinyServer(function(input, output, session) {
pg <- pixelgram::pixelgram()
updateAln <- reactive({
aln.formats <- c("fasta", "clustal", "phylip", "msf", "mase")
validate(
need(
(input$alnFormat==1 & grepl("fas|fst", input$alnFile$name, ignore.case=T)) |
(input$alnFormat==2 & grepl("cl", input$alnFile$name, ignore.case=T)) |
(input$alnFormat==3 & grepl("phy", input$alnFile$name, ignore.case=T)) |
(input$alnFormat==4 & grepl("msf", input$alnFile$name, ignore.case=T)) |
(input$alnFormat==5 & grepl("mas", input$alnFile$name, ignore.case=T)),
paste0("Sorry but your alignment file name must contain '",
aln.formats[as.numeric(input$alnFormat)],
# input$alnFormat,
"' to ensure it is formatted as you intend."))
)
pixelgram::set.aln.file(pg,
input$alnFile$datapath,
input$alnType,
aln.formats[as.numeric(input$alnFormat)],
input$pngs2o)
})
updateTre <- reactive({
validate(
need(input$alnFile$datapath,
"Please specify an alignment file."),
need(c(input$treFile$datapath,
(input$createTree & input$alnType=="codon")),
"Please specify a tree file or 'Build NJ tree from codon alignment'."),
need(is.numeric(input$pointSize),
"Please specify a numeric point size."),
need(input$pointSize > 0,
"Please specify a positive point size.")
)
# if (!is.null(input$treFile$datapath))
pixelgram::set.tre.file(updateAln(), input$treFile$datapath)
# else return (pg)
})
output$myPixgramPlot <- renderPlot({
# unset the checkbox if any conditions are true:
if (input$createTree &
(!is.null(input$treFile$datapath) | input$alnType == 'aa'))
updateCheckboxInput(session, input$createTree, value=F)
# if (input$tippch)
# tippch.parser <- pixelgram::create.timepoint.parser(input$tipcol.delimType, input$tipcol.fieldNumb)
# if (input$tipcol)
# tippch.parser <- pixelgram::create.timepoint.parser(input$tippch.delimType, input$tippch.fieldNumb)
# pg <- updateAln()
pg <- updateTre()
par(mar=c(0,0,0,0), oma=c(0,0,0,0), cex=input$pointSize/12)
plot(pg, #updateAln(updateTre()),
xform_type = input$xformType,
show_tree = !input$hideTree,
xform_master = input$xformMaster,
show_tip_label = input$labelTips,
raster_width = input$pixelWidth/100)
})
output$downloadFile <- downloadHandler(
filename = function() {
paste0("pixelgram-", gsub(" ", "_", Sys.Date()), "-",
input$outfileLayout, ".", input$outfileFormat) },
content = function(file) {
owd <- setwd(tempdir())
on.exit(setwd(owd))
tmpfile <- tempfile()#fileext=input$outfileFormat)
cat ( "\n", tmpfile, "\n", "i am", system("whoami"), "\n")
if (input$outfileFormat == "png") {
my.width = 8
my.height = 8
if (input$outfileLayout == "landscape")
my.width=10.5
else if (input$outfileLayout == "portrait")
my.height=10.5
png(file=tmpfile, width=my.width*72, height=my.height*72,
pointsize=input$pointSize)
} else if (input$outfileFormat == "svg") {
my.width = 8
my.height = 8
if (input$outfileLayout == "landscape")
my.width=10.5
else if (input$outfileLayout == "portrait")
my.height=10.5
svg(file=tmpfile, width=my.width, height=my.height, onefile=T,
pointsize=input$pointSize)
} else if (input$outfileFormat == "eps") {
switch(input$outfileLayout,
landscape = ps.options("paper"="us", "horizontal"=T,
"title"=tmpfile, "height"=8.5, "width"=11),
portrait = ps.options("paper"="us", "horizontal"=F,
"title"=tmpfile, "height"=11, "width"=8.5),
square = ps.options("paper"="special",
"title"=tmpfile, "height"=8, "width"=8))
# contentType = "application/postscript"
postscript(file=tmpfile)
} else if (input$outfileFormat == "pdf") {
switch(input$outfileLayout,
landscape = pdf.options("compress"=F, "paper"="USr",
"title"=tmpfile, "height"=8.5, "width"=11,
"useDingbats"=F, "pointsize"=input$pointSize),
portrait = pdf.options("compress"=F, "paper"="US",
"title"=tmpfile, "height"=11, "width"=8.5,
"useDingbats"=F, "pointsize"=input$pointSize),
square = pdf.options("compress"=F, "paper"="special",
"title"=tmpfile, "height"=8, "width"=8,
"useDingbats"=F, "pointsize"=input$pointSize))
# contentType = "application/pdf"
pdf(file=tmpfile)
} else { stop("ERROR: Unrecognized output file format") }
par(mar=c(0,0,0,0), oma=c(0,0,0,0))
plot(updateTre(),
xform_type = input$xformType,
show_tree = !input$hideTree,
xform_master = input$xformMaster,
show_tip_label = input$labelTips,
raster_width = input$pixelWidth/100)
dev.off()
file.rename(tmpfile, file)
} #,
# does this add filename suffixes?
# contentType = ifelse(input$outfileFormat == "pdf",
# "application/pdf",
# ifelse(input$outfileFormat == "eps",
# "application/postscript",
# ifelse(input$outfileFormat == "png",
# "image/png",
# "image/svg+xml")))
# if (input$outfileFormat == "pdf") {
# contentType = "application/pdf"
# } else if (input$outfileFormat == "eps") {
# contentType = "application/postscript" }
# else if (input$outfileFormat == "png") {
# contentType = "image/png" }
# else if (input$outfileFormat == "svg") {
# contentType = "image/svg+xml"
# }
)})