Giter Site home page Giter Site logo

mricloudr's Introduction

Travis build status AppVeyor build status

MriCloudR

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")
devtools::install_github("muschellij2/MriCloudR")

Example

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.

library(MriCloudR)
library(keyringr)

# 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, "[email protected]", mypwd)

List Jobs

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

listJobs(mriCloudR)

T1 Segmentation Example

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

library(neurohcp)
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

library(ANTsR)
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)) {
  print("Finished");
} 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

and

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

mricloudr's People

Contributors

adigherman avatar bcaffo avatar kb1ooo avatar muschellij2 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.