Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change people functions to synapser #168

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-13, r: 'release'}
- {os: windows-2022, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
Expand All @@ -29,7 +29,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -40,9 +40,18 @@ jobs:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
id: install-deps
continue-on-error: true
with:
extra-packages: any::rcmdcheck
needs: check

- name: If source build fails on macOS or Windows, fall back to typical install
if: steps.install-deps.outcome == 'failure'
shell: Rscript {0}
run: |
reticulate::install_miniconda()
install.packages("synapser", repos="http://ran.synapse.org")

- uses: r-lib/actions/check-r-package@v2
with:
Expand Down
5 changes: 4 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 (>= 1.0.0)
URL: https://github.com/nf-osi/nfportalutils
BugReports: https://github.com/nf-osi/nfportalutils/issues
Suggests:
Expand All @@ -50,3 +51,5 @@ Suggests:
withr
Config/testthat/edition: 2
VignetteBuilder: knitr
Remotes:
github::Sage-Bionetworks/synapser
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.

Loading