Getting Data from the Human Connectome Project (HCP)

John Muschelli


All code for this document is located at here.

Human Connectome Project (HCP)

The Human Connectome Project (HCP) is a consortium of sites whose goal is to map “human brain circuitry in a target number of 1200 healthy adults using cutting-edge methods of noninvasive neuroimaging” ( It includes a large cohort of individuals with a vast amount of neuroimaging data ranging from structural magnetic resonance imaging (MRI), functional MRI – both during tasks and resting-state– and diffusion tensor imaging (DTI), from multiple sites.

Getting Access to the Data

The data is available to those that agree to the license. Users can either pay to get hard drives of the data sent to them, named “Connectome In A Box”, or access the data online. The data can be obtained through the database at Data can be downloaded from the website directly in a browser or through an Amazon Simple Storage Solution (S3) bucket. We will focus on accessing the data from S3.

Getting an Access/API Key

Once logged into and the terms are accepted, the user must enable Amazon S3 access for their Amazon account. The user will then be provided an access key identifier (ID), which is required to authenticate a user to Amazon as well as a secret key. These access and secret keys are necessary for the neurohcp package, and will be referred to as access keys or API (application program interface) keys.

Installing the neurohcp package

We will install the neurohcp package using the Neuroconductor installer:

neuro_install("neurohcp", release = "stable")

Setting the API key

In the neurohcp package, set_aws_api_key will set the AWS access keys:

or these can be stored in AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY environment variables, respectively.

Once these are set, the functions of neurohcp are ready to use. To test that the API keys are set correctly, one can run bucketlist:

                                 Name             CreationDate
1 cf-templates-tgdhg13zvsxm-us-west-2 2017-04-05T20:37:43.000Z
2                      hcp-openaccess 2014-05-15T18:56:50.000Z
3                 hcp-openaccess-logs 2014-05-15T18:57:07.000Z
4                hcp-openaccess-trail 2016-06-02T20:22:11.000Z

We see that hcp-openaccess is a bucket that we have access to, and therefore have access to the data.

Getting Data: Downloading a Directory of Data

In the neurohcp package, there is a data set indicating the scans read for each subject, named hcp_900_scanning_info. We can subset those subjects that have diffusion tensor imaging:

# A tibble: 6 x 1
1 100307
2 100408
3 101006
4 101107
5 101309
6 101410

Let us download the complete directory of diffusion data using download_hcp_dir:

[1] "bvals"                   "bvecs"                  
[3] "data.nii.gz"             "grad_dev.nii.gz"        
[5] "nodif_brain_mask.nii.gz"

This diffusion data is the data that can be used to create summaries such as fractional anisotropy and mean diffusivity.

If we create a new column with all the directories, we can iterate over these to download all the diffusion data for these subjects from the HCP database.

Getting Data: Downloading a Single File

We can also download a single file using download_hcp_file. Here we will simply download the bvals file: