Skip to content

Commit

Permalink
Fixed xform parser; added more template options
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed May 10, 2022
1 parent 1c8b54d commit 598b4d4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
3 changes: 2 additions & 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: 0.2.4.9002
Version: 0.2.4.9003
Authors@R: c(
person("Zhengjia", "Wang", email = "[email protected]", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "[email protected]", role = c("aut")),
Expand Down Expand Up @@ -33,6 +33,7 @@ Language: en-US
URL: https://dipterix.org/threeBrain/ https://github.com/dipterix/threeBrain
BugReports: https://github.com/dipterix/threeBrain/issues
Imports:
utils,
grDevices,
graphics,
dipsaus,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(GeomGroup)
export(SphereGeom)
export(TubeGeom)
export(add_voxel_cube)
export(available_templates)
export(brain_proxy)
export(brain_setup)
export(check_freesurfer_path)
Expand Down
2 changes: 1 addition & 1 deletion R/fs_brain.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ freesurfer_brain <- function(fs_subject_folder, subject_name,
has_volume <- FALSE
if( file.exists(path_xform) ){
ss <- readLines(path_xform)
ss <- stringr::str_match(ss, '^([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+)[;]{0,1}$')
ss <- stringr::str_match(ss, '^([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+)[;]{0,1}[ ]{0,}$')
ss <- ss[!is.na(ss[,1]), -1, drop = FALSE]
if( nrow(ss) >= 3 ){
ss <- ss[1:3,1:4]
Expand Down
2 changes: 1 addition & 1 deletion R/fs_import-xform.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import_fs.xform <- function(subject_name, fs_path, quiet = FALSE, dtype, sub_typ
xfm <- diag(c(1,1,1,1))
if( file.exists(path_xform) ){
ss <- readLines(path_xform)
ss <- stringr::str_match(ss, '^([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+)[;]{0,1}$')
ss <- stringr::str_match(ss, '^([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+) ([-]{0,1}[0-9.]+)[;]{0,1}[ ]{0,}$')
ss <- ss[!is.na(ss[,1]), -1, drop = FALSE]
if( nrow(ss) >= 3 ){
ss <- ss[1:3,1:4]
Expand Down
46 changes: 46 additions & 0 deletions R/loaders.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,49 @@ threebrain_finalize_installation <- function(upgrade = c('ask', 'always', 'never
return(invisible())
}


#' @rdname template_subject
#' @export
available_templates <- function() {

url <- "https://api.github.com/repos/dipterix/threeBrain-sample/releases"
tf <- tempfile()
on.exit({
if(file.exists(tf)) {
unlink(tf)
}
})

res <- tryCatch({
utils::download.file(url, destfile = tf, quiet = TRUE)
res <- jsonlite::read_json(tf)[[1]]
res <- lapply(res$assets, function(asset){
list(
subject_name = gsub("\\..*", "", asset$name),
download_url = asset$browser_download_url
)
})

scodes <- vapply(res, FUN = '[[', FUN.VALUE = "", 'subject_name')
urls <- lapply(res, FUN = '[[', 'download_url')

names(urls) <- scodes
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"
)
})

return(res)
}


3 changes: 3 additions & 0 deletions man/template_subject.Rd

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

0 comments on commit 598b4d4

Please sign in to comment.