Skip to content

Commit

Permalink
Fixed download template subject URL query
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Dec 14, 2023
1 parent e409270 commit c6f90fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: threeBrain
Type: Package
Title: 3D Brain Visualization
Version: 1.0.1.9018
Version: 1.0.1.9019
Authors@R: c(
person("Zhengjia", "Wang", email = "dipterix.wang@gmail.com", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "John.Magnotti@Pennmedicine.upenn.edu", role = c("aut", "res")),
Expand Down
35 changes: 23 additions & 12 deletions R/loaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,23 @@ available_templates <- function() {
}
})

# As of 2022-05-09
default_list <- list(
bert = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/bert.zip",
cvs_avg35 = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/cvs_avg35.zip",
cvs_avg35_inMNI152 = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/cvs_avg35_inMNI152.zip",
fsaverage = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/fsaverage.zip",
fsaverage_sym = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/fsaverage_sym.zip",
`N27-complete` = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27-complete.zip",
N27 = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip"
)

res <- tryCatch({
utils::download.file(url, destfile = tf, quiet = TRUE)
res <- jsonlite::read_json(tf)[[1]]
releases <- jsonlite::read_json(tf)
res <- releases[vapply(releases, function(rel) {
isTRUE(rel$tag_name == "1.0.0")
}, FALSE)][[1]]
res <- lapply(res$assets, function(asset){
list(
subject_name = gsub("\\..*", "", asset$name),
Expand All @@ -240,19 +254,16 @@ available_templates <- function() {
urls <- lapply(res, FUN = '[[', 'download_url')

names(urls) <- scodes
urls
urls <- as.list(urls)
nms <- names(default_list)
nms <- nms[!nms %in% names(urls)]
if(length(nms)) {
urls[nms] <- default_list[nms]
}

urls
}, error = function(e){
# As of 2022-05-09
list(
bert = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/bert.zip",
cvs_avg35 = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/cvs_avg35.zip",
cvs_avg35_inMNI152 = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/cvs_avg35_inMNI152.zip",
fsaverage = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/fsaverage.zip",
fsaverage_sym = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/fsaverage_sym.zip",
`N27-complete` = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27-complete.zip",
N27 = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip"
)
default_list
})

return(res)
Expand Down

0 comments on commit c6f90fe

Please sign in to comment.