Skip to content

Commit

Permalink
Merge pull request #144 from Sage-Bionetworks/nf-clinical-release
Browse files Browse the repository at this point in the history
[GEN-1503] Add nextflow workflow for clinical release
  • Loading branch information
thomasyu888 authored Sep 13, 2024
2 parents 5b49793 + f00a8c6 commit eb1dc27
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 65 deletions.
7 changes: 6 additions & 1 deletion main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ include { run_quac_table_report } from './modules/run_quac_table_report'
include { run_quac_comparison_report } from './modules/run_quac_comparison_report'
include { create_masking_report } from './modules/create_masking_report'
include { update_case_count_table } from './modules/update_case_count_table'
include { run_clinical_release } from './modules/run_clinical_release'

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RUN WORKFLOW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

workflow {
workflow BPC_PIPELINE {
ch_cohort = Channel.value(params.cohort)
ch_comment = Channel.value(params.comment)

Expand All @@ -104,3 +105,7 @@ workflow {
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

workflow CLINICAL_RELEASE {
run_clinical_release('', params.cohort, params.production)
}
28 changes: 28 additions & 0 deletions modules/run_clinical_release.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
process run_clinical_release {

container 'sagebionetworks/genie-bpc-pipeline-clinical-release'
secret 'SYNAPSE_AUTH_TOKEN'
debug true

input:
val previous
val cohort
val production

output:
stdout

script:
if (production) {
"""
cd /usr/local/src/myscripts/
Rscript create_release_files.R -c $cohort -v -s
"""
}
else {
"""
cd /usr/local/src/myscripts/
Rscript create_release_files.R -c $cohort -v
"""
}
}
4 changes: 4 additions & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ profiles {
memory = 32.GB
cpus = 8
}
withName: run_clinical_release {
memory = 32.GB
cpus = 8
}
}
}
}
19 changes: 19 additions & 0 deletions scripts/release/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM rstudio/r-base:4.0-bullseye

WORKDIR /usr/local/src/myscripts

ENV RENV_VERSION 0.14.0
# RUN rm /etc/apt/apt.conf.d/default
RUN apt-get update -y && apt-get install -y dpkg-dev zlib1g-dev libssl-dev libffi-dev curl libcurl4-openssl-dev procps


RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')"
RUN R -e "remotes::install_version('synapser', version = '0.11.7', repos = c('http://ran.synapse.org', 'http://cran.fhcrc.org'))"

ENV PYTHON /usr/local/lib/R/site-library/PythonEmbedInR/bin/python3.6


COPY . .

RUN R -e "renv::restore()"
65 changes: 1 addition & 64 deletions scripts/release/create_release_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ option_list <- list(
action="store_true",
default = FALSE,
help="Copy release files from staging to release folder"),
make_option(c("-a", "--auth"),
type = "character",
default = NA,
help="Synapse personal access token or path to .synapseConfig (default: normal synapse login behavior)"),
make_option(c("-v", "--verbose"),
action="store_true",
default = FALSE,
Expand All @@ -41,7 +37,6 @@ opt <- parse_args(OptionParser(option_list=option_list))
selected_cohort <- opt$cohort
staging <- opt$staging
release <- opt$release
auth <- opt$auth
verbose <- opt$verbose

if (verbose) {
Expand Down Expand Up @@ -121,68 +116,10 @@ store_file <- function(var,
}
}

#' Extract personal access token from .synapseConfig
#' located at a custom path.
#'
#' @param path Path to .synapseConfig
#' @return personal acccess token
get_auth_token <- function(path) {

lines <- scan(path, what = "character", sep = "\t", quiet = T)
line <- grep(pattern = "^authtoken = ", x = lines, value = T)

token <- strsplit(line, split = ' ')[[1]][3]
return(token)
}

#' Override of synapser::synLogin() function to accept
#' custom path to .synapseConfig file or personal authentication
#' token. If no arguments are supplied, performs standard synLogin().
#'
#' @param auth full path to .synapseConfig file or authentication token
#' @param silent verbosity control on login
#' @return TRUE for successful login; F otherwise
synLogin <- function(auth = NA, silent = T) {

secret <- Sys.getenv("SCHEDULED_JOB_SECRETS")
if (secret != "") {
# Synapse token stored as secret in json string
syn = synapser::synLogin(silent = T, authToken = fromJSON(secret)$SYNAPSE_AUTH_TOKEN)
} else if (auth == "~/.synapseConfig" || is.na(auth)) {
# default Synapse behavior
syn <- synapser::synLogin(silent = silent)
} else {

# in case pat passed directly
token <- auth

# extract token from custom path to .synapseConfig
if (grepl(x = auth, pattern = "\\.synapseConfig$")) {
token = get_auth_token(auth)

if (is.na(token)) {
return(F)
}
}

# login with token
syn <- tryCatch({
synapser::synLogin(authToken = token, silent = silent)
}, error = function(cond) {
return(F)
})
}

# NULL returned indicates successful login
if (is.null(syn)) {
return(T)
}
return(F)
}

# synapse login ---------------

status <- synLogin(auth = auth)
synLogin()

# read --------------------

Expand Down

0 comments on commit eb1dc27

Please sign in to comment.