/
NetworkViews.R
605 lines (571 loc) · 28 KB
/
NetworkViews.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# ==============================================================================
# Functions for performing VIEW operations in addition to getting and setting
# view properties.
#
# Dev Notes: refer to StyleValues.R, StyleDefaults.R and StyleBypasses.R for
# getting/setting node, edge and network visual properties via VIEW operations.
# ------------------------------------------------------------------------------
#' @title Create Network View
#'
#' @description Create a network view if one does not already exist
#' @param layout (optional) If TRUE (default), the preferred layout will be
#' applied to the new view. If FALSE, no layout will be applied.
#' @param network (optional) Name or SUID of the network. Default is the
#' "current" network active in Cytoscape.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @details For networks larger than the view creation threshold, a network
#' view is not created by default. This function creates a network view if
#' one does not already exist.
#' @return Network view SUID
#' @examples \donttest{
#' getNetworkViews()
#' }
#' @export
createView <- function(layout = TRUE, network=NULL, base.url =.defaultBaseUrl) {
net.SUID <- getNetworkSuid(network,base.url)
netview.SUID <- getNetworkViewSuid(network,base.url)
if (!is.null(netview.SUID))
return (netview.SUID)
res <- commandsPOST(paste0('view create network=SUID:',net.SUID,
' layout=', tolower(layout)),
base.url = base.url)
return(unname(res[[1]]["view"]))
}
# ------------------------------------------------------------------------------
#' @title Get Network Views
#'
#' @description Retrieve list of network view SUIDs
#' @param network (optional) Name or SUID of the network. Default is the
#' "current" network active in Cytoscape.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @return List of network view SUIDs
#' @examples \donttest{
#' getNetworkViews()
#' }
#' @export
getNetworkViews <- function(network=NULL, base.url =.defaultBaseUrl) {
net.SUID <- getNetworkSuid(network,base.url)
res <- NULL
tryCatch(
expr = {
res <- cyrestGET(paste("networks", net.SUID, "views", sep="/"),
base.url = base.url)
},
error=function(e){}
)
return(res)
}
# ------------------------------------------------------------------------------
#' @title Get the SUID of a network view
#'
#' @description Retrieve the SUID of a network view
#' @param network (optional) Name or SUID of the network. Default is the
#' "current" network active in Cytoscape. If a network view SUID is provided,
#' then it is validated and returned.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @return (\code{numeric}) Network view suid. The first (presumably only) view
#' associated a network is returned.
#' @author Alexander Pico
#' @examples
#' \donttest{
#' getNetworkViewSuid()
#' getNetworkViewSuid("myNetwork")
#' # 90
#' }
#' @export
getNetworkViewSuid <- function(network = NULL, base.url = .defaultBaseUrl) {
net.SUID <- getNetworkSuid(network, base.url)
any.views <- getNetworkViews(net.SUID,base.url)
if(is.null(any.views)){
return(NULL)
}
else if(length(any.views)>1) {
message("Warning: This network has multiple views. Returning last.")
tail(any.views,n=1)
} else {
any.views
}
}
# ------------------------------------------------------------------------------
#' @title Fit Content
#'
#' @description Zoom and pan network view to maximize either height or width of
#' current network window.
#' @details Takes first (presumably only) view associated with provided network
#' @param selected.only (Boolean) Whether to fit only current selection. Default
#' is false, i.e., to fit the entire network.
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @return None
#' @examples \donttest{
#' fitContent()
#' }
#' @export
fitContent <- function(selected.only=FALSE, network=NULL,
base.url =.defaultBaseUrl) {
view.SUID <- getNetworkViewSuid(network,base.url)
if(selected.only){
commandsPOST(paste0('view fit selected view=SUID:',view.SUID), base.url = base.url)
} else {
commandsPOST(paste0('view fit content view=SUID:',view.SUID), base.url = base.url)
}
}
# ------------------------------------------------------------------------------
#' @title Set Current View
#'
#' @description Set which network view is "current".
#' @details Takes first (presumably only) view associated with provided network
#' @param network (optional) Name or SUID of a network or view. The first
#' (presummably only) view associated a network is used if a specific view
#' SUID is not provided.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @return None
#' @examples \donttest{
#' setCurrentView()
#' }
#' @export
setCurrentView <- function(network = NULL,
base.url =.defaultBaseUrl) {
view.SUID <- getNetworkViewSuid(network,base.url)
commandsPOST(paste0('view set current view=SUID:"',view.SUID,'"'), base.url = base.url)
}
# ------------------------------------------------------------------------------
#' Export Image
#'
#' @description Saves the current network view as an image file.
#' @details The image is cropped per the current view in Cytoscape. Consider
#' applying \code{\link{fitContent}} prior to export.
#' @param filename (\code{character}) Full path or path relative to current
#' working directory, in addition to the name of the file. Extension is
#' automatically added based on the \code{type} argument. If blank, the current
#' network name will be used.
#' @param type (\code{character}) Type of image to export, e.g., PNG (default),
#' JPEG, PDF, SVG, PS (PostScript).
#' @param resolution (\code{numeric}) The resolution of the exported image, in DPI. Valid
#' only for bitmap formats, when the selected width and height 'units' is inches. The
#' possible values are: 72 (default), 100, 150, 300, 600.
#' @param units (\code{character}) The units for the 'width' and 'height' values. Valid
#' only for bitmap formats, such as PNG and JPEG. The possible values are: pixels (default), inches.
#' @param height (\code{numeric}) The height of the exported image. Valid only for bitmap
#' formats, such as PNG and JPEG.
#' @param width (\code{numeric}) The width of the exported image. Valid only for bitmap
#' formats, such as PNG and JPEG.
#' @param zoom (\code{numeric}) The zoom value to proportionally scale the image. The default
#' value is 100.0. Valid only for bitmap formats, such as PNG and JPEG
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @param overwriteFile (optional) FALSE allows Cytoscape show a message box before overwriting the file if the file already
#' exists; TRUE allows Cytoscape to overwrite it without asking. Default value is TRUE.
#' @return server response
#' @examples
#' \donttest{
#' exportImage('/fullpath/myNetwork','PDF')
#' }
#' @export
exportImage<-function(filename=NULL, type="PNG", resolution=NULL, units=NULL, height=NULL,
width=NULL, zoom=NULL, network=NULL, base.url=.defaultBaseUrl, overwriteFile=TRUE){
cmd.string <- 'view export' # a good start
# filename must be supplied
if(is.null(filename))
filename <- getNetworkName(network,base.url)
# view must be supplied
view.SUID <- getNetworkViewSuid(network,base.url)
# optional args
if(!is.null(resolution))
cmd.string <- paste0(cmd.string,' Resolution="',resolution,'"')
if(!is.null(units))
cmd.string <- paste0(cmd.string,' Units="',units,'"')
if(!is.null(height))
cmd.string <- paste0(cmd.string,' Height="',height,'"')
if(!is.null(width))
cmd.string <- paste0(cmd.string,' Width="',width,'"')
if(!is.null(zoom))
cmd.string <- paste0(cmd.string,' Zoom="',zoom,'"')
ext <- paste0(".",tolower(type),"$")
if (!grepl(ext,filename))
filename <- paste0(filename,".",tolower(type))
fileInfo <- sandboxGetFileInfo(filename, base.url=base.url)
if (length(fileInfo[['modifiedTime']] == 1) && fileInfo[['isFile']]){
if (overwriteFile){
sandboxRemoveFile(filename, base.url=base.url)
}
else {
warning("This file already exists. A Cytoscape popup will be
generated to confirm overwrite.",
call. = FALSE,
immediate. = TRUE)
}
}
commandsPOST(paste0(cmd.string,
' OutputFile="',getAbsSandboxPath(filename),'"',
' options="',toupper(type),'"',
' view=SUID:"',view.SUID,'"'),
base.url = base.url)
}
# ------------------------------------------------------------------------------
#' Export PNG
#'
#' @description Saves the current network view as an png file.
#' @details Exports the current view to a graphics file and returns the path to
#' the saved file. To speed up image export for large networks use the option 'allGraphicsDetails=FALSE'.
#' Available for Cytoscape v3.10 or later.
#' @param filename (\code{character}) Full path or path relative to current
#' working directory, in addition to the name of the file. Extension is
#' automatically added based on the \code{type} argument. If blank, the current
#' network name will be used.
#' @param zoom (\code{numeric}) The zoom value to proportionally scale the image. The default
#' value is 100.0. Valid only for bitmap formats, such as PNG and JPEG
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param allGraphicsDetails (optional): TRUE results in image with highest detail; False allows faster image
#' generation. The default is TRUE.
#' @param hideLabels (optional): TRUE makes node and edge labels invisible in image. False allows them to be
#' drawn. The default is False.
#' @param transparentBackground (optional): TRUE causes background to be transparent. The default is FALSE.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @param overwriteFile (optional) FALSE allows Cytoscape show a message box before overwriting the file if the file already
#' exists; TRUE allows Cytoscape to overwrite it without asking. Default value is TRUE.
#' @return server response
#' @examples
#' \donttest{
#' exportPNG('/fullpath/myNetwork')
#' }
#' @export
exportPNG<-function(filename=NULL, allGraphicsDetails=TRUE, hideLabels=FALSE, transparentBackground=FALSE,
zoom=NULL, network=NULL, base.url=.defaultBaseUrl, overwriteFile=TRUE){
.verifySupportedVersions(1, "3.10")
cmd.string <- 'view export png' # a good start
# filename must be supplied
if(is.null(filename))
filename <- getNetworkName(network,base.url)
# view must be supplied
view.SUID <- getNetworkViewSuid(network,base.url)
# optional args
if(!is.null(allGraphicsDetails))
cmd.string <- paste0(cmd.string,' allGraphicsDetails="',allGraphicsDetails,'"')
if(!is.null(hideLabels))
cmd.string <- paste0(cmd.string,' hideLabels="',hideLabels,'"')
if(!is.null(transparentBackground))
cmd.string <- paste0(cmd.string,' transparentBackground="',transparentBackground,'"')
if(!is.null(zoom))
cmd.string <- paste0(cmd.string,' zoom="',zoom,'"')
ext <- paste0(".",tolower("PNG"),"$")
if (!grepl(ext,filename))
filename <- paste0(filename,".",tolower("PNG"))
fileInfo <- sandboxGetFileInfo(filename, base.url=base.url)
if (length(fileInfo[['modifiedTime']] == 1) && fileInfo[['isFile']]){
if (overwriteFile){
sandboxRemoveFile(filename, base.url=base.url)
}
else {
warning("This file already exists. A Cytoscape popup will be
generated to confirm overwrite.",
call. = FALSE,
immediate. = TRUE)
}
}
commandsPOST(paste0(cmd.string,
' outputFile="',getAbsSandboxPath(filename),'"',
' view=SUID:"',view.SUID,'"'),
base.url = base.url)
}
# ------------------------------------------------------------------------------
#' Export JPG
#'
#' @description Saves the current network view as an jpg file.
#' @details Exports the current view to a graphics file and returns the path to
#' the saved file. To speed up image export for large networks use the option 'allGraphicsDetails=FALSE'.
#' Available for Cytoscape v3.10 or later.
#' @param filename (\code{character}) Full path or path relative to current
#' working directory, in addition to the name of the file. Extension is
#' automatically added based on the \code{type} argument. If blank, the current
#' network name will be used.
#' @param zoom (\code{numeric}) The zoom value to proportionally scale the image. The default
#' value is 100.0. Valid only for bitmap formats, such as PNG and JPEG
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param allGraphicsDetails (optional): TRUE results in image with highest detail; False allows faster image
#' generation. The default is TRUE.
#' @param hideLabels (optional): TRUE makes node and edge labels invisible in image. False allows them to be
#' drawn. The default is False.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @param overwriteFile (optional) FALSE allows Cytoscape show a message box before overwriting the file if the file already
#' exists; TRUE allows Cytoscape to overwrite it without asking. Default value is TRUE.
#' @return server response
#' @examples
#' \donttest{
#' exportJPG('/fullpath/myNetwork')
#' }
#' @export
exportJPG<-function(filename=NULL, allGraphicsDetails=TRUE, hideLabels=FALSE,
zoom=NULL, network=NULL, base.url=.defaultBaseUrl, overwriteFile=TRUE){
.verifySupportedVersions(1, "3.10")
cmd.string <- 'view export jpg' # a good start
# filename must be supplied
if(is.null(filename))
filename <- getNetworkName(network,base.url)
# view must be supplied
view.SUID <- getNetworkViewSuid(network,base.url)
# optional args
if(!is.null(allGraphicsDetails))
cmd.string <- paste0(cmd.string,' allGraphicsDetails="',allGraphicsDetails,'"')
if(!is.null(hideLabels))
cmd.string <- paste0(cmd.string,' hideLabels="',hideLabels,'"')
if(!is.null(zoom))
cmd.string <- paste0(cmd.string,' zoom="',zoom,'"')
ext <- paste0(".",tolower("JPG"),"$")
if (!grepl(ext,filename))
filename <- paste0(filename,".",tolower("JPG"))
fileInfo <- sandboxGetFileInfo(filename, base.url=base.url)
if (length(fileInfo[['modifiedTime']] == 1) && fileInfo[['isFile']]){
if (overwriteFile){
sandboxRemoveFile(filename, base.url=base.url)
}
else {
warning("This file already exists. A Cytoscape popup will be
generated to confirm overwrite.",
call. = FALSE,
immediate. = TRUE)
}
}
commandsPOST(paste0(cmd.string,
' outputFile="',getAbsSandboxPath(filename),'"',
' view=SUID:"',view.SUID,'"'),
base.url = base.url)
}
# ------------------------------------------------------------------------------
#' Export PDF
#'
#' @description Saves the current network view as an pdf file.
#' @details Exports the current view to a graphics file and returns the path to
#' the saved file. To speed up image export for large networks use the option 'allGraphicsDetails=FALSE'.
#' Available for Cytoscape v3.10 or later.
#' @param filename (\code{character}) Full path or path relative to current
#' working directory, in addition to the name of the file. Extension is
#' automatically added based on the \code{type} argument. If blank, the current
#' network name will be used.
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param hideLabels (optional): TRUE makes node and edge labels invisible in image. False allows them to be
#' drawn. The default is False.
#' @param exportTextAsFont (optional): If TRUE (the default value), texts will be exported as fonts.
#' @param orientation (optional): Page orientation, portrait or landscape.
#' @param pageSize (optional): (Auto|Letter|Legal|Tabloid|A0|A1|A2|A3|A4|A5)
#' Predefined standard page size, or choose custom. Default is 'Letter'.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @param overwriteFile (optional) FALSE allows Cytoscape show a message box before overwriting the file if the file already
#' exists; TRUE allows Cytoscape to overwrite it without asking. Default value is TRUE.
#' @return server response
#' @examples
#' \donttest{
#' exportPDF('/fullpath/myNetwork')
#' }
#' @export
exportPDF<-function(filename=NULL, exportTextAsFont=TRUE, hideLabels=FALSE, pageSize="Letter",
orientation="Portrait", network=NULL, base.url=.defaultBaseUrl, overwriteFile=TRUE){
.verifySupportedVersions(1, "3.10")
cmd.string <- 'view export pdf' # a good start
# filename must be supplied
if(is.null(filename))
filename <- getNetworkName(network,base.url)
# view must be supplied
view.SUID <- getNetworkViewSuid(network,base.url)
# optional args
if(!is.null(exportTextAsFont))
cmd.string <- paste0(cmd.string,' exportTextAsFont="',exportTextAsFont,'"')
if(!is.null(hideLabels))
cmd.string <- paste0(cmd.string,' hideLabels="',hideLabels,'"')
if(!is.null(pageSize))
cmd.string <- paste0(cmd.string,' pageSize="',pageSize,'"')
if(!is.null(orientation))
cmd.string <- paste0(cmd.string,' orientation="',orientation,'"')
ext <- paste0(".",tolower("PDF"),"$")
if (!grepl(ext,filename))
filename <- paste0(filename,".",tolower("PDF"))
fileInfo <- sandboxGetFileInfo(filename, base.url=base.url)
if (length(fileInfo[['modifiedTime']] == 1) && fileInfo[['isFile']]){
if (overwriteFile){
sandboxRemoveFile(filename, base.url=base.url)
}
else {
warning("This file already exists. A Cytoscape popup will be
generated to confirm overwrite.",
call. = FALSE,
immediate. = TRUE)
}
}
commandsPOST(paste0(cmd.string,
' outputFile="',getAbsSandboxPath(filename),'"',
' view=SUID:"',view.SUID,'"'),
base.url = base.url)
}
# ------------------------------------------------------------------------------
#' Export PS
#'
#' @description Saves the current network view as an ps file.
#' @details Exports the current view to a graphics file and returns the path to
#' the saved file. To speed up image export for large networks use the option 'allGraphicsDetails=FALSE'.
#' Available for Cytoscape v3.10 or later.
#' @param filename (\code{character}) Full path or path relative to current
#' working directory, in addition to the name of the file. Extension is
#' automatically added based on the \code{type} argument. If blank, the current
#' network name will be used.
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param hideLabels (optional): TRUE makes node and edge labels invisible in image. False allows them to be
#' drawn. The default is False.
#' @param exportTextAsFont (optional): If TRUE (the default value), texts will be exported as fonts.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @param overwriteFile (optional) FALSE allows Cytoscape show a message box before overwriting the file if the file already
#' exists; TRUE allows Cytoscape to overwrite it without asking. Default value is TRUE.
#' @return server response
#' @examples
#' \donttest{
#' exportPS('/fullpath/myNetwork')
#' }
#' @export
exportPS<-function(filename=NULL, exportTextAsFont=TRUE, hideLabels=FALSE,
network=NULL, base.url=.defaultBaseUrl, overwriteFile=TRUE){
.verifySupportedVersions(1, "3.10")
cmd.string <- 'view export ps' # a good start
# filename must be supplied
if(is.null(filename))
filename <- getNetworkName(network,base.url)
# view must be supplied
view.SUID <- getNetworkViewSuid(network,base.url)
# optional args
if(!is.null(exportTextAsFont))
cmd.string <- paste0(cmd.string,' exportTextAsFont="',exportTextAsFont,'"')
if(!is.null(hideLabels))
cmd.string <- paste0(cmd.string,' hideLabels="',hideLabels,'"')
ext <- paste0(".",tolower("PS"),"$")
if (!grepl(ext,filename))
filename <- paste0(filename,".",tolower("PS"))
fileInfo <- sandboxGetFileInfo(filename, base.url=base.url)
if (length(fileInfo[['modifiedTime']] == 1) && fileInfo[['isFile']]){
if (overwriteFile){
sandboxRemoveFile(filename, base.url=base.url)
}
else {
warning("This file already exists. A Cytoscape popup will be
generated to confirm overwrite.",
call. = FALSE,
immediate. = TRUE)
}
}
commandsPOST(paste0(cmd.string,
' outputFile="',getAbsSandboxPath(filename),'"',
' view=SUID:"',view.SUID,'"'),
base.url = base.url)
}
# ------------------------------------------------------------------------------
#' Export SVG
#'
#' @description Saves the current network view as an svg file.
#' @details Exports the current view to a graphics file and returns the path to
#' the saved file. To speed up image export for large networks use the option 'allGraphicsDetails=FALSE'.
#' Available for Cytoscape v3.10 or later.
#' @param filename (\code{character}) Full path or path relative to current
#' working directory, in addition to the name of the file. Extension is
#' automatically added based on the \code{type} argument. If blank, the current
#' network name will be used.
#' @param network (optional) Name or SUID of a network or view. Default is the
#' "current" network active in Cytoscape. The first (presummably only) view
#' associated a network is used if a specific view SUID is not provided.
#' @param hideLabels (optional): TRUE makes node and edge labels invisible in image. False allows them to be
#' drawn. The default is False.
#' @param exportTextAsFont (optional): If TRUE (the default value), texts will be exported as fonts.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @param overwriteFile (optional) FALSE allows Cytoscape show a message box before overwriting the file if the file already
#' exists; TRUE allows Cytoscape to overwrite it without asking. Default value is TRUE.
#' @return server response
#' @examples
#' \donttest{
#' exportSVG('/fullpath/myNetwork')
#' }
#' @export
exportSVG<-function(filename=NULL, exportTextAsFont=TRUE, hideLabels=FALSE,
network=NULL, base.url=.defaultBaseUrl, overwriteFile=TRUE){
.verifySupportedVersions(1, "3.10")
cmd.string <- 'view export svg' # a good start
# filename must be supplied
if(is.null(filename))
filename <- getNetworkName(network,base.url)
# view must be supplied
view.SUID <- getNetworkViewSuid(network,base.url)
# optional args
if(!is.null(exportTextAsFont))
cmd.string <- paste0(cmd.string,' exportTextAsFont="',exportTextAsFont,'"')
if(!is.null(hideLabels))
cmd.string <- paste0(cmd.string,' hideLabels="',hideLabels,'"')
ext <- paste0(".",tolower("SVG"),"$")
if (!grepl(ext,filename))
filename <- paste0(filename,".",tolower("SVG"))
fileInfo <- sandboxGetFileInfo(filename, base.url=base.url)
if (length(fileInfo[['modifiedTime']] == 1) && fileInfo[['isFile']]){
if (overwriteFile){
sandboxRemoveFile(filename, base.url=base.url)
}
else {
warning("This file already exists. A Cytoscape popup will be
generated to confirm overwrite.",
call. = FALSE,
immediate. = TRUE)
}
}
commandsPOST(paste0(cmd.string,
' outputFile="',getAbsSandboxPath(filename),'"',
' view=SUID:"',view.SUID,'"'),
base.url = base.url)
}
# ------------------------------------------------------------------------------
#' @title Toggle Graphics Details
#'
#' @description Regardless of the current zoom level and network size,
#' show (or hide) graphics details, e.g., node labels.
#' @details Displaying graphics details on a very large network will affect pan
#' and zoom performance, depending on your available RAM.
#' See \link{cytoscapeMemoryStatus}.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @return None
#' @examples \donttest{
#' showGraphicsDetails(TRUE)
#' }
#' @export
toggleGraphicsDetails <- function (base.url=.defaultBaseUrl) {
resource.uri <- paste(base.url, "ui/lod/", sep="/")
request.res <- PUT(resource.uri)
invisible (request.res)
}