oasis_predict: OASIS Prediction

Description Usage Arguments Value Examples

View source: R/oasis_predict.R

Description

This function creates the OASIS probability map from a single MRI study with FLAIR, T1, T2, and PD volumes.

Usage

1
2
3
oasis_predict(flair, t1, t2, pd = NULL, brain_mask = NULL, model = NULL,
  return_preproc = FALSE, binary = FALSE, threshold = 0.16,
  verbose = TRUE, ...)

Arguments

flair

flair volume of class nifti

t1

t1 volume of class nifti

t2

t2 volume of class nifti

pd

pd volume of class nifti

brain_mask

brain mask of class nifti, if NULL a brain mask will be created using fslbet. Note that provided brain masks should be in the same space as the T1 volume if preproc = TRUE, as all volumes will be registered to this space

model

an object of class glm used to make the OASIS predictions

return_preproc

is a logical value that indicates whether the preprocessed images should be returned, if NULL then the model from the OASIS paper will be used

binary

logical indicating whether a binary map should be returned by thresholding the probability map

threshold

numeric indicating the threshold value for the probability map, with default of 0.16 for the OASIS paper

verbose

print diagnostic messages

...

options passed to oasis_train_dataframe

Value

A list of volumes: the OASIS probability map, the preprocessed volumes (if return_preproc = TRUE), the brain mask for the subject, the voxel selection mask, and a thresholded, binary mask (if binary = TRUE) .

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
library(ROCR)
p = predict( oasis::oasis_model,
    newdata = example_oasis_df,
    type = 'response')
nopd_p = predict( oasis::nopd_oasis_model,
    newdata = example_oasis_df,
    type = 'response')    
y =  example_oasis_df$GOLD_Lesions
pred = ROCR::prediction(p, y)
perf = ROCR::performance(pred, "tpr", "fpr")
plot(perf)


library(neurobase)
dl_file = function(url) {
   tfile = tempfile(fileext = ".nii.gz")
   req <- httr::GET(url,
   httr::write_disk(path = tfile))
   httr::stop_for_status(req)
   tfile
}
in_ci <- function() {
 nzchar(Sys.getenv("CI"))
}
on_cran = function() {
 identical(Sys.getenv("NOT_CRAN"), "false")
} 
if (in_ci() || on_cran()) {
  if (fslr::have.fsl() && require(httr)) {
    mods = c("FLAIR", "T1W", "T2W", "consensus_gt", "brainmask")
    base_url = file.path(
      "https://raw.githubusercontent.com/muschellij2/open_ms_data", 
      "master/cross_sectional/coregistered/patient01/")
    files = paste0(base_url, mods, ".nii.gz")
    files = sapply(files, dl_file)
    names(files) = mods

    flair <- readnii(files["FLAIR"])
    t1 <- readnii(files["T1W"])
    t2 <- readnii(files["T2W"])
    brain_mask <- readnii(files["brainmask"])
    gold_standard = readnii(files["consensus_gt"])
    oasis_preprocessed_data <- oasis_predict(flair, t1, t2, 
      brain_mask = brain_mask, preproc = TRUE)
  } 
}

neuroconductor/oasis documentation built on May 19, 2021, 5:25 a.m.