The goal of MriCloudR is to wraps the MRICloud API so that it can be accessed from R.

And the development version from GitHub with:

# install.packages("devtools")


Because MriCloudR currently only works with email/password combinations, we have to store our passwords. The keyringr package has a great vignette to show how to store your password by the password manaager for your operating system. In our example, we have named the keychain (OS X) entry as mricloudr.


# MriCloud object.  Submit requests and retrieve results.
mypwd <- decrypt_kc_pw("mricloudr")

mriCloudR <- MriCloudR(verbose = TRUE)

# Login using MriCloud credentials.  Currently, standard credentials are
# supported, not OpenId
login(mriCloudR, "", mypwd)

List Jobs

If you have previous jobs in your queue, you can see your job identifiers with listJobs


T1 Segmentation Example

Here we download a nifti image from the Human Connectome Project using the neurohcp package:

img = "HCP_1200/102614/T1w/T1w_acpc_dc.nii.gz"
img = download_hcp_file(img)

Now that we have the downloaded image, we have to convert it to ANALYZE format because this is required for MRICloud

img = antsImageRead(img)

tfile = tempfile(fileext = ".hdr")
antsImageWrite(r, filename = tfile)

hdr = tfile
dat = sub("[.]hdr$", ".img", hdr)

Here we create a T1SegData object which contains payload information:

# Create T1SegData object which contains payload information
t1SegData <- T1SegData()
t1SegData$sliceType <- "Axial"
t1SegData$hdr <- hdr
t1SegData$img <- dat
t1SegData$age <- 40
t1SegData$description <- "Testing"
t1SegData$atlas <- "Adult_286labels_10atlases_V5L"

# submit to perform t1Seg.  Get back jobId.
jobId <- t1Seg(mriCloudR, t1SegData)

Now we have the jobId, isJobFinished checks status of job. We can also see this new job ID in listJobs:

if (isJobFinished(mriCloudR, jobId = jobId)) {
} else {
  print(paste(c("Job ", jobId, " not completed yet!"), collapse = ''))

After the job is finished, you can download the result using downloadResult:

# downloadResult will download the result if the jobId is finished.  If the
# argument waitForJobToFinish is TRUE, then downloadResult will wait until the
# job is completed (checking every minute), and then download the result.

x = downloadResult(mriCloudR, jobId = jobId, waitForJobToFinish = TRUE)

Now that the result was downloaded, it is a zip file, and we can unzip it using unzip:

tdir = tempfile()
dir.create(tdir, showWarnings = FALSE)
unz = unzip(x, exdir = tdir)

Here we can read in the 286 labels from the segmentation:

seg_hdr = unz[grepl("_286Labels.hdr$", unz)]
res = antsImageRead(seg_hdr)

Example code

Please see T1Example.r and DtiExample.r for examples on using the interfaces. They may be run via Rscript:

Rscript T1Example.r


Rscript DtiExample.r 

Release Notes

0.9.0 Initial release supporting T1 segmentation
0.9.1 Added Dti segmentation and adjusted default mricloud URL 0.9.2 Changed the directory structure so that it can be submitted to Neuroconductor