Skip to content

Commit

Permalink
Remove synapse_func.py and use syn object
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasyu888 committed Apr 19, 2021
1 parent 6ce6d82 commit 4910256
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ app_server <- function( input, output, session ) {
### login and update session; otherwise, notify to login to Synapse first
tryCatch({
syn$login(sessionToken = input$cookie)
values$tables <- get_tables()
values$tables <- get_tables(syn)
# get controlled-vocabulary list
values$cv_terms <- get_synapse_annotations("syn25322361", syn) %>%
select(key, value, columnType) %>%
Expand Down
6 changes: 4 additions & 2 deletions R/mod_validator.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ mod_validator_server <- function(input, output, session, values){
if (type == "dataset") {
annotations <- dataset_annots(row)
syn_id <- save_folder_to_synapse(
syn,
synapseclient,
name,
parent_folder[["dataset"]],
Expand All @@ -297,6 +298,7 @@ mod_validator_server <- function(input, output, session, values){

annotations <- file_annots(row, dataset_folder, tables$grants, tables$datasets)
syn_id <- save_file_to_synapse(
syn,
synapseclient,
name,
dataset_folder,
Expand Down Expand Up @@ -337,13 +339,13 @@ mod_validator_server <- function(input, output, session, values){
tables$publications
)
)
syn_store(synapseclient$Table(portal_table[[type]], new_portal_row))
syn$store(synapseclient$Table(portal_table[[type]], new_portal_row))
}
# output$diag <- DT::renderDT(new_portal_row)
# syn_store(synapseclient$Table(portal_table[[type]], new_portal_row))

### update stats on overview tab
values$tables <- get_tables()
values$tables <- get_tables(syn)
# TODO: make this tables value a reactive
# display_overview_stats(output, tables)
# display_quickview(output, tables)
Expand Down
9 changes: 0 additions & 9 deletions R/synapse_funcs.py

This file was deleted.

19 changes: 12 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ split_and_search <- function(annots, table, search_col, output_col,


## Save new entity to Synapse; Folder for dataset manifest, File for others
save_file_to_synapse <- function(synapseclient, name,
save_file_to_synapse <- function(syn, synapseclient, name,
parent, annotations) {
name <- syn_prettify(name)

Expand All @@ -57,22 +57,22 @@ save_file_to_synapse <- function(synapseclient, name,
parent = parent,
annotations = annotations
)
new_file <- syn_store(new_file)
new_file <- syn$store(new_file)

# remove dummy file
file.remove(name)

new_file$id
}
save_folder_to_synapse <- function(synapseclient, name,
save_folder_to_synapse <- function(syn, synapseclient, name,
parent, annotations) {
name <- syn_prettify(name)
new_folder <- synapseclient$Folder(
name,
parent = parent,
annotations = annotations
)
new_folder <- syn_store(new_folder)
new_folder <- syn$store(new_folder)
new_folder$id
}

Expand Down Expand Up @@ -164,27 +164,32 @@ publication_row <- function(syn_id, manifest, grants, datasets) {
}

#' Get Synapse tables used for the portal.
get_tables <- function() {
get_tables <- function(syn) {
grants <- get_portal_table(
syn,
portal_table[["grant"]],
c("grantId", "grantName", "grantNumber", "grantInstitution",
"themeId", "theme", "consortiumId", "consortium")
)
publications <- get_portal_table(
syn,
portal_table[["publication"]],
c("publicationId", "publicationTitle", "grantId", "grantNumber",
"grantName", "themeId", "theme", "consortiumId", "consortium"
)
)
datasets <- get_portal_table(
syn,
portal_table[["dataset"]],
c("datasetId", "datasetName", "datasetAlias")
)
tools <- get_portal_table(
syn,
portal_table[["tool"]],
c("toolId", "toolName")
)
files <- get_portal_table(
syn,
portal_table[["file"]],
c("fileName", "datasets", "parentId")
)
Expand All @@ -198,9 +203,9 @@ get_tables <- function() {
}

#' Get selected coloumns from a Synapse table.
get_portal_table <- function(table_id, cols) {
get_portal_table <- function(syn, table_id, cols) {
query <- sprintf("SELECT %s FROM %s", paste0(cols, collapse=","), table_id)
return(syn_table_query(query)$asDataFrame())
return(syn$tableQuery(query)$asDataFrame())
}


Expand Down

0 comments on commit 4910256

Please sign in to comment.