Skip to content

Commit

Permalink
change people functions to synapser
Browse files Browse the repository at this point in the history
  • Loading branch information
allaway committed Feb 16, 2024
1 parent 8fa6a20 commit 922c9aa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Imports:
emoji,
plyr,
readxl,
yaml
yaml,
synapser
URL: https://github.com/nf-osi/nfportalutils
BugReports: https://github.com/nf-osi/nfportalutils/issues
Suggests:
Expand Down
16 changes: 0 additions & 16 deletions R/add_publication_from_unpaywall.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,4 @@ add_publication_from_unpaywall <- function(publication_table_id,
}
}}

#' Adds a row to a table.
#' @param schema A synapse table Schema object.
#' @param new_row A data frame of one or more rows that match the provided schema.
#' @export
.store_rows <- function(schema, new_row){

table <- .syn$store(synapseclient$Table(schema, new_row))

}

# .pluck_column_type_and_name <- function(column){
# coltype <- purrr::pluck(column, "columnType")
# name <- purrr::pluck(column, "name")
#
# c(coltype, name)
# }

18 changes: 18 additions & 0 deletions R/basic_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ walk <- function(syn_id, as_list = TRUE) {

}


#' Adds a row to a table.
#' @param schema A synapse table Schema object.
#' @param new_row A data frame of one or more rows that match the provided schema.
#' @export
.store_rows <- function(schema, new_row){

table <- synapser::synStore(synapser::Table(schema, new_row))

}

# .pluck_column_type_and_name <- function(column){
# coltype <- purrr::pluck(column, "columnType")
# name <- purrr::pluck(column, "name")
#
# c(coltype, name)
# }

10 changes: 4 additions & 6 deletions R/login.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Logs into Synapse.
#'
#'
#' Wrapper around https://python-docs.synapse.org/build/html/index.html#synapseclient.Synapse.login
#' Username and password authentication is not supported.
#' Recommendation is to store `SYNAPSE_AUTH_TOKEN` in environment, so login can be used simply as `syn_login()`.
#'
#'
#' @param authtoken Uses `SYNAPSE_AUTH_TOKEN` environmental variable, or a personal access token (PAT) can be provided.
#' @examples
#' \dontrun{
Expand All @@ -22,9 +22,7 @@ syn_login <- function(authtoken = Sys.getenv("SYNAPSE_AUTH_TOKEN")){
#' @returns A message.
#' @keywords internal
.check_login <- function(){
if(!exists(".syn")){
stop('Please run `nfportalutils::syn_login()` prior to running functions that require a connection to Synapse. (Alternatively, the Python `synapseclient` is unavailable.)')
}else if(capture.output(.syn) == "<pointer: 0x0>"){
stop('Please run `nfportalutils::syn_login()` prior to running functions that require a connection to Synapse. (Alternatively, the Python `synapseclient` is unavailable.)')
if(!exists(".syn") & !exists("syn")){
stop('Please run `nfportalutils::syn_login()` or `synapser::synLogin()` prior to running functions that require a connection to Synapse. (Alternatively, the Python `synapseclient` is unavailable.)')
}
}
12 changes: 7 additions & 5 deletions R/update_people_table.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Update the People table from a source Table or View column
#'
#'
#' @param people_table_id The synapse id of the table used for referencing people.
#' @param people_column Column name within the people table that contains the relevant people values.
#' @param people_column Column name within the people table that contains the relevant people values.
#' @param source_table_id The synapse id of the source table.
#' @param source_column Column name within the source table that contains the relevant source values.
#' @inheritParams update_study_annotations
Expand All @@ -15,15 +15,17 @@ add_people_from_table <- function(people_table_id, people_column, source_table_i
#get current people ids
old_people_query <- glue::glue("select {people_column} from {people_table_id}")

old_people <- .syn$tableQuery(old_people_query)$asDataFrame() %>%
old_people <- synapser::synTableQuery(old_people_query, includeRowIdAndRowVersion = F)$asDataFrame() %>%
tibble::as_tibble() %>%
dplyr::distinct()

old_ids <- old_people[[{{people_column}}]]

#get ids from new source table
new_people_query <- glue::glue("select {source_column} from {source_table_id}")

new_people <- .syn$tableQuery(new_people_query)$asDataFrame() %>%
new_people <- synapser::synTableQuery(new_people_query, includeRowIdAndRowVersion = F)$asDataFrame() %>%
tibble::as_tibble() %>%
dplyr::distinct() %>%
dplyr::filter(!(!!rlang::sym(source_column)) %in% old_ids) %>% #filter out existing ids
purrr::pluck(source_column)
Expand All @@ -32,7 +34,7 @@ add_people_from_table <- function(people_table_id, people_column, source_table_i

new_rows <- tibble::tibble(!!people_column := new_people)

schema <- .syn$get(people_table_id)
schema <- synapser::synGet(people_table_id)

if(dry_run == F){
.store_rows(schema, new_rows)
Expand Down
2 changes: 1 addition & 1 deletion man/dot-store_rows.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 922c9aa

Please sign in to comment.