-
Notifications
You must be signed in to change notification settings - Fork 1
/
2022-01-06_jocelyn_copy_files.R
110 lines (87 loc) · 3.42 KB
/
2022-01-06_jocelyn_copy_files.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
# Description: Move data on Synapse for BrCa sponsored project
# Author: Haley Hunter-Zinck
# Date: 2022-01-06
# Request:
# Source: Freedcamp task from Jocelyn: https://freedcamp.com/view/3082480/tasks/44200194
# Date requested: 2021-01-06
# setup ----------------------------
tic = as.double(Sys.time())
library(glue)
library(synapser)
synLogin()
# synapse
synid_file_duke_data <- "syn26602640"
synid_file_ucsf_data <- "syn26586228"
synid_file_msk_data <- "syn26612339"
synid_folder_dest <- "syn26023438"
# provenance
prov_name <- "copy file"
prov_desc <- "copy file to Synapse directory for delivery"
prov_exec <- "https://github.com/hhunterzinck/genie_requests/blob/main/2022-01-06_jocelyn_copy_files.R"
# functions ----------------------------
get_synapse_folder_children <- function(synapse_id,
include_types=list("folder", "file", "table", "link", "entityview", "dockerrepo")) {
ent <- as.list(synGetChildren(synapse_id, includeTypes = include_types))
children <- c()
if (length(ent) > 0) {
for (i in 1:length(ent)) {
children[ent[[i]]$name] <- ent[[i]]$id
}
}
return(children)
}
save_to_synapse <- function(path,
parent_id,
file_name = NA,
prov_name = NA,
prov_desc = NA,
prov_used = NA,
prov_exec = NA) {
if (is.na(file_name)) {
file_name = path
}
file <- File(path = path, parentId = parent_id, name = file_name)
if (!is.na(prov_name) || !is.na(prov_desc) || !is.na(prov_used) || !is.na(prov_exec)) {
act <- Activity(name = prov_name,
description = prov_desc,
used = prov_used,
executed = prov_exec)
file <- synStore(file, activity = act)
} else {
file <- synStore(file)
}
return(T)
}
# main ----------------------------
synid_folder_children <- get_synapse_folder_children(synapse_id = synid_folder_dest,
include_types=list("file"))
# duke
ent_duke <- synGet(synid_file_duke_data)
save_to_synapse(path = ent_duke$path,
parent_id = synid_folder_dest,
file_name = grep(pattern = "DUKE", x = names(synid_folder_children), value = T),
prov_name = prov_name,
prov_desc = prov_desc,
prov_used = synid_file_duke_data,
prov_exec = prov_exec)
# ucsf
ent_ucsf <- synGet(synid_file_ucsf_data)
save_to_synapse(path = ent_ucsf$path,
parent_id = synid_folder_dest,
file_name = grep(pattern = "UCSF", x = names(synid_folder_children), value = T),
prov_name = prov_name,
prov_desc = prov_desc,
prov_used = synid_file_ucsf_data,
prov_exec = prov_exec)
# msk
ent_msk <- synGet(synid_file_msk_data)
save_to_synapse(path = ent_msk$path,
parent_id = synid_folder_dest,
file_name = grep(pattern = "MSK", x = names(synid_folder_children), value = T),
prov_name = prov_name,
prov_desc = prov_desc,
prov_used = synid_file_msk_data,
prov_exec = prov_exec)
# close out ----------------------------
toc = as.double(Sys.time())
print(glue("Runtime: {round(toc - tic)} s"))