Skip to content

Commit 7e2c027

Browse files
authored
Merge pull request #584 from Sage-Bionetworks/develop
v24.1.2
2 parents 366007f + 94bd899 commit 7e2c027

File tree

8 files changed

+217
-101
lines changed

8 files changed

+217
-101
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Rongrong Chai, Xengie Doan, Milen Nikolov, Sujay Patil, Robert Allaway,
66
License: file LICENSE
77
Encoding: UTF-8
88
Roxygen: list(markdown = TRUE)
9-
RoxygenNote: 7.2.1
9+
RoxygenNote: 7.2.3
10+
Imports: httr, dplyr, jsonlite
1011
Suggests:
1112
covr

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ RUN apt-get install -y libxml2 libglpk-dev libicu-dev libicu70 curl
1313
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
1414
RUN chmod 777 /etc/shiny-server/shiny-server.conf
1515

16-
# Update node. https://github.com/nodesource/distributions
17-
RUN apt-get remove nodejs
18-
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && apt-get install -y nodejs
19-
2016
USER shiny
2117

2218
WORKDIR /srv/shiny-server/app

NAMESPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(create_dca_template_config)
4+
export(create_template_config)
5+
export(format_edge_type)
36
export(get_asset_view_table)
7+
export(get_display_names)
8+
export(graph_by_edge_type)
49
export(manifest_download)
510
export(manifest_generate)
611
export(manifest_populate)
@@ -14,3 +19,6 @@ export(synapse_access)
1419
export(synapse_get)
1520
export(synapse_is_certified)
1621
export(synapse_user_profile)
22+
export(write_dca_template_config)
23+
importFrom(httr,GET)
24+
importFrom(httr,content)

R/schematic_rest_api.R

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,36 @@ manifest_populate <- function(url="http://localhost:3001/v1/manifest/populate",
115115
#' @export
116116
manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
117117
schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint
118-
data_type, file_name, restrict_rules=FALSE) {
118+
data_type, file_name, restrict_rules=FALSE, project_scope = NULL,
119+
access_token, asset_view = NULL) {
120+
121+
flattenbody <- function(x) {
122+
# A form/query can only have one value per name, so take
123+
# any values that contain vectors length >1 and
124+
# split them up
125+
# list(x=1:2, y="a") becomes list(x=1, x=2, y="a")
126+
if (all(lengths(x)<=1)) return(x);
127+
do.call("c", mapply(function(name, val) {
128+
if (length(val)==1 || any(c("form_file", "form_data") %in% class(val))) {
129+
x <- list(val)
130+
names(x) <- name
131+
x
132+
} else {
133+
x <- as.list(val)
134+
names(x) <- rep(name, length(val))
135+
x
136+
}
137+
}, names(x), x, USE.NAMES = FALSE, SIMPLIFY = FALSE))
138+
}
139+
119140
req <- httr::POST(url,
120-
query=list(
141+
httr::add_headers(Authorization = sprintf("Bearer %s", access_token)),
142+
query=flattenbody(list(
121143
schema_url=schema_url,
122144
data_type=data_type,
123-
restrict_rules=restrict_rules),
145+
restrict_rules=restrict_rules,
146+
project_scope = project_scope,
147+
asset_view = asset_view)),
124148
body=list(file_name=httr::upload_file(file_name))
125149
)
126150

@@ -314,3 +338,17 @@ get_asset_view_table <- function(url="http://localhost:3001/v1/storage/assets/ta
314338

315339
}
316340

341+
#' @param url URL of schematic API endpoint
342+
#' @param schema_url URL of data model
343+
#' @param relationship Argument to schematic graph_by_edge_type
344+
#' @export
345+
#' @importFrom httr GET content
346+
graph_by_edge_type <- function(url = "https://schematic-dev.api.sagebionetworks.org/v1/schemas/get/graph_by_edge_type",
347+
schema_url, relationship = "requiresDependency") {
348+
req <- httr::GET(url = url,
349+
query = list(
350+
schema_url = schema_url,
351+
relationship = relationship
352+
))
353+
httr::content(req)
354+
}

R/template_config.R

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#' @export
2+
format_edge_type <- function(edge_types) {
3+
et <- dplyr::bind_rows(lapply(edge_types, function(x) data.frame(value = x[[2]], schema_name = x[[1]])))
4+
components <- et |>
5+
dplyr::filter(tolower(value) == "component") |>
6+
dplyr::pull(schema_name)
7+
et |>
8+
dplyr::filter(value %in% c("Component", "Filename")) |>
9+
dplyr::group_by(schema_name) |>
10+
dplyr::summarise(file_based = "Filename" %in% value) |>
11+
dplyr::filter(schema_name %in% components)
12+
}
13+
14+
#' @export
15+
get_display_names <- function(qlist) {
16+
if (!"schema_url" %in% names(qlist)) stop("qlist needs element named `schema_url`")
17+
if (!"node_list" %in% names(qlist)) stop("qlist needs at least one element named `node_list`")
18+
httr::GET(
19+
url = "https://schematic-dev.api.sagebionetworks.org/v1/schemas/get_nodes_display_names",
20+
query = qlist
21+
)
22+
}
23+
24+
#' @export
25+
create_template_config <- function(data_model, include_schemas = NULL, exclude_schemas = NULL) {
26+
if (!is.null(include_schemas) && !is.null(exclude_schemas)) stop("include_schemas and exclude_schemas cannot both have values")
27+
edges <- graph_by_edge_type(schema_url = data_model)
28+
schema_names <- format_edge_type(edges)
29+
nl <- setNames(as.list(schema_names$schema_name), rep("node_list", length(schema_names$schema_name)))
30+
dnames <- get_display_names(c(schema_url = data_model, nl)) |> httr::content()
31+
config <- data.frame(display_name = unlist(dnames), schema_name = unlist(nl)) |>
32+
dplyr::left_join(schema_names, by = "schema_name") |>
33+
dplyr::mutate(type = ifelse(file_based, "file", "record")) |>
34+
dplyr::select(-file_based)
35+
if (!is.null(include_schemas)) {
36+
if (any(length(x <- setdiff(include_schemas, config$schema_name)))) stop(sprintf("%s is not a schema name in the data model", x))
37+
config <- dplyr::filter(config, schema_name %in% include_schemas)
38+
}
39+
if (!is.null(exclude_schemas)) {
40+
if (any(length(y <- setdiff(exclude_schemas, config$schema_name)))) stop(sprintf("%s is not a schema name in the data model", y))
41+
config <- dplyr::filter(config, !schema_name %in% exclude_schemas)
42+
}
43+
config
44+
}
45+
46+
#' @export
47+
create_dca_template_config <- function(data_model, include_schemas = NULL, exclude_schemas = NULL) {
48+
df <- create_template_config(data_model, include_schemas, exclude_schemas)
49+
schematic_version <- httr::GET("https://schematic-dev.api.sagebionetworks.org/v1/version") |>
50+
httr::content()
51+
list(
52+
manifest_schemas = df,
53+
service_version = schematic_version,
54+
schema_version = ""
55+
)
56+
}
57+
58+
#' @export
59+
#' @description Create a DCA-specific template generation function
60+
write_dca_template_config <- function(data_model, file, include_schemas = NULL, exclude_schemas = NULL) {
61+
df <- create_dca_template_config(data_model, include_schemas, exclude_schemas)
62+
jsonlite::write_json(df, file, pretty = TRUE, auto_unbox = TRUE)
63+
}

global.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ options(shiny.maxRequestSize=32*1024^2)
3737
source_files <- list.files(c("functions", "modules"), pattern = "*\\.R$", recursive = TRUE, full.names = TRUE)
3838
sapply(source_files, FUN = source)
3939

40-
dcc_config_file <- Sys.getenv("DCA_DCC_CONFIG")
41-
dcc_config <- read_csv(dcc_config_file, show_col_types = FALSE)
40+
if (Sys.getenv("DCA_DCC_CONFIG") == "") stop("missing DCA_DCC_CONFIG environment variable")
41+
dca_dcc_config <- read_json(Sys.getenv("DCA_DCC_CONFIG"), simplifyVector = TRUE)
42+
tenants_config <- dca_dcc_config$tenants
43+
config_dir <- dirname(Sys.getenv("DCA_DCC_CONFIG"))
4244

4345
## Set Up OAuth
4446
client_id <- Sys.getenv("DCA_CLIENT_ID")
@@ -127,11 +129,6 @@ api <- oauth_endpoint(
127129
# The 'openid' scope is required by the protocol for retrieving user information.
128130
scope <- "openid view download modify"
129131

130-
template_config_files <- setNames(dcc_config$template_menu_config_file,
131-
dcc_config$synapse_asset_view)
132-
if (dca_schematic_api == "offline") template_config_files <- setNames("www/template_config/config_offline.json",
133-
"synXXXXXX")
134-
135132
## Set Up Virtual Environment
136133
# ShinyAppys has a limit of 7000 files which this app' grossly exceeds
137134
# due to its Python dependencies. To get around the limit we zip up

0 commit comments

Comments
 (0)