This package provides a thin wrapper around Rlabkey and connects to the ImmuneSpace database, making it easier to fetch datasets, including gene expression data, HAI, and so forth, from specific studies.

1 Configuration

In order to connect to ImmuneSpace, you will need a .netrc file in your home directory that will contain a machine name (hostname of ImmuneSpace), and login and password. See here for more information.

A netrc file may look like this:

machine www.immunespace.org
login myuser@domain.com
password supersecretpassword

Set up your netrc file now!

Put it in your home directory. If you type:

ls ~/.netrc

at the command prompt, you should see it there. If it’s not there, create one now. Make sure you have a valid login and password. If you don’t have one, go to ImmuneSpace now and set yourself up with an account.

2 Instantiate a connection

We’ll be looking at study SDY269. If you want to use a different study, change that string. The connections have state, so you can instantiate multiple connections to different studies simultaneously.

library(ImmuneSpaceR)
sdy269 <- CreateConnection(study = "SDY269")
sdy269
## <ImmuneSpaceConnection>
##   Study: SDY269
##   URL: https://www.immunespace.org/Studies/SDY269
##   User: unknown_user at not_a_domain.com
##   9 Available Datasets
##     - elispot
##     - pcr
##     - cohort_membership
##     - fcs_analyzed_result
##     - demographics
##     - hai
##     - gene_expression_files
##     - elisa
##     - fcs_sample_files
##   2 Available Expression Matrices

The call to CreateConnection instantiates the connection. Printing the object shows where it’s connected, to what study, and the available data sets and gene expression matrices.

Note that when a script is running on ImmuneSpace, some variables set in the global environments will automatically indicate which study should be used and the study argument can be skipped.

3 Fetching datasets

We can grab any of the datasets listed in the connection.

sdy269$getDataset("hai")
##      participant_id age_reported gender                      race
##   1:  SUB112866.269           34   Male                     White
##   2:  SUB112842.269           28   Male                     White
##   3:  SUB112863.269           29 Female                     White
##   4:  SUB112853.269           47 Female                     White
##   5:  SUB112885.269           28 Female                     White
##  ---                                                             
## 332:  SUB112838.269           39   Male                     White
## 333:  SUB112863.269           29 Female                     White
## 334:  SUB112888.269           34 Female                     White
## 335:  SUB112881.269           29 Female Black or African American
## 336:  SUB112881.269           29 Female Black or African American
##               cohort study_time_collected study_time_collected_unit
##   1: LAIV group 2008                    0                      Days
##   2:  TIV Group 2008                   28                      Days
##   3:  TIV Group 2008                    0                      Days
##   4:  TIV Group 2008                   28                      Days
##   5: LAIV group 2008                    0                      Days
##  ---                                                               
## 332: LAIV group 2008                   28                      Days
## 333:  TIV Group 2008                    0                      Days
## 334:  TIV Group 2008                   28                      Days
## 335: LAIV group 2008                   28                      Days
## 336: LAIV group 2008                    0                      Days
##                       virus value_preferred
##   1:       B/Florida/4/2006               5
##   2:     A/Brisbane/59/2007             160
##   3:     B/Brisbane/03/2007              20
##   4:     A/Uruguay/716/2007             320
##   5: A/South Dakota/06/2007               5
##  ---                                       
## 332:       B/Florida/4/2006               5
## 333:     A/Brisbane/59/2007              40
## 334:     A/Uruguay/716/2007              40
## 335: A/South Dakota/06/2007               5
## 336:       B/Florida/4/2006               5

The sdy269 object is an R6 class, so it behaves like a true object. Methods (like getDataset) are members of the object, thus the $ semantics to access member functions.

The first time you retrieve a data set, it will contact the database. The data is cached locally, so the next time you call getDataset on the same dataset, it will retrieve the cached local copy. This is much faster.

To get only a subset of the data and speed up the download, filters can be passed to getDataset. The filters are created using the makeFilter function of the Rlabkey package.

library(Rlabkey)
myFilter <- makeFilter(c("gender", "EQUAL", "Female"))
hai <- sdy269$getDataset("hai", colFilter = myFilter)

See ?Rlabkey::makeFilter for more information on the syntax.

For more information about getDataset’s options, refer to the dedicated vignette.

4 Fetching expression matrices

We can also grab a gene expression matrix

sdy269$getGEMatrix("SDY269_PBMC_LAIV_Geo")
## Downloading matrix..
## Constructing ExpressionSet
## ExpressionSet (storageMode: lockedEnvironment)
## assayData: 16442 features, 83 samples 
##   element names: exprs 
## protocolData: none
## phenoData
##   sampleNames: BS586100 BS586156 ... BS586239 (83 total)
##   varLabels: participant_id study_time_collected ...
##     exposure_process_preferred (8 total)
##   varMetadata: labelDescription
## featureData
##   featureNames: DDR1 RFC2 ... NUS1P3 (16442 total)
##   fvarLabels: FeatureId gene_symbol
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
## Annotation:

The object contacts the database and downloads the matrix file. This is stored and cached locally as a data.table. The next time you access it, it will be much faster since it won’t need to contact the database again.

It is also possible to call this function using multiple matrix names. In this case, all the matrices are downloaded and combined into a single ExpressionSet.

sdy269$getGEMatrix(c("SDY269_PBMC_TIV_Geo", "SDY269_PBMC_LAIV_Geo"))
## Downloading matrix..
## returning summary matrix from cache
## returning latest annotation from cache
## Constructing ExpressionSet
## Constructing ExpressionSet
## Combining ExpressionSets
## ExpressionSet (storageMode: lockedEnvironment)
## assayData: 16442 features, 163 samples 
##   element names: exprs 
## protocolData: none
## phenoData
##   sampleNames: BS586128 BS586240 ... BS586239 (163 total)
##   varLabels: participant_id study_time_collected ...
##     exposure_process_preferred (8 total)
##   varMetadata: labelDescription
## featureData
##   featureNames: 1 2 ... 16442 (16442 total)
##   fvarLabels: FeatureId gene_symbol
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
## Annotation:

Finally, the summary argument will let you download the matrix with gene symbols in place of probe ids.

gs <- sdy269$getGEMatrix("SDY269_PBMC_TIV_Geo", outputType = "summary", annotation = "latest")
## returning SDY269_PBMC_TIV_Geo_sum_eset from cache

If the connection was created with verbose = TRUE, some functions will display additional informations such as the valid dataset names.

5 Plotting

A plot of a dataset can be generated using the plot method which automatically chooses the type of plot depending on the selected dataset.

sdy269$plot("hai")

sdy269$plot("elisa")