This vignette shows detailed examples for all functionalities of the getDataset function.

Contents

  1. Connections
  2. List the datasets
  3. Download a dataset
  4. Filters
  5. Views
  6. Caching
  7. sessionInfo

Connections

As explained into the user guide vignette, datasets must be downloaded from ImmuneSpaceConnection objects. We must first instantiate a connection to the study or studies of interest. Throughout this vignette, we will use two connections, one to a single study, and one to to all available data.

library(ImmuneSpaceR)
sdy269 <- CreateConnection("SDY269")
all <- CreateConnection("")

List the datasets

Now that the connections have been instantiated, we can start downloading from them. But we need to figure out which datasets are available within our chosen studies.

Printing the connections will, among other information, list the datasets availables. The listDatasets method will display only the information we are looking for.

sdy269$listDatasets()
## datasets
##  demographics
##  pcr
##  cohort_membership
##  elisa
##  elispot
##  hai
##  gene_expression_files
##  fcs_analyzed_result
##  fcs_sample_files
## Expression Matrices
##  TIV_2008
##  LAIV_2008
all$listDatasets()
## datasets
##  elispot
##  mbaa
##  hai
##  elisa
##  pcr
##  neut_ab_titer
##  fcs_analyzed_result
##  gene_expression_files
##  fcs_sample_files
##  fcs_control_files
##  cohort_membership
##  demographics
## Expression Matrices
##  VLplus
##  Cohort2_older
##  Fluzone_group1
##  TIV_2007
##  Fluzone_group2
##  TIV_2011
##  TIV_older
##  Cohort1_young
##  Saline_group2
##  older_PBMC_year2
##  TIV_2008
##  TIV_young
##  young_PBMC_year1
##  VLminus
##  pH1N1_2009
##  Pneumovax23_group1
##  older_PBMC_year1
##  Pneumovax23_group2
##  LAIV_2008
##  TIV_2010
##  Saline_group1
##  young_PBMC_year2

Naturally, all contains every dataset available on ImmuneSpace as it combines all available studies.

Additionaly, when creating connection object with verbose = TRUE, a call to the getDataset function with an invalid dataset name will return the list of valid datasets.

Back to top

Download

Calling getDataset returns a selected dataset as it is displayed on ImmuneSpace.

hai_269 <- sdy269$getDataset("hai")
hai_all <- all$getDataset("hai")

print(head(hai_269))
##    participant_id age_reported gender  race          cohort
## 1:  SUB112847.269           24   Male White  TIV Group 2008
## 2:  SUB112860.269           32 Female White LAIV group 2008
## 3:  SUB112842.269           28   Male White  TIV Group 2008
## 4:  SUB112859.269           32   Male White LAIV group 2008
## 5:  SUB112878.269           28 Female White  TIV Group 2008
## 6:  SUB112877.269           27   Male White  TIV Group 2008
##    study_time_collected study_time_collected_unit
## 1:                   28                      Days
## 2:                    0                      Days
## 3:                   28                      Days
## 4:                    0                      Days
## 5:                   28                      Days
## 6:                   28                      Days
##                                     virus value_reported
## 1: A/Uruguay/716/2007  NYMC X-175C (H3N2)            320
## 2:           A/South Dakota/6/2007 (H1N1)             40
## 3:                      B/Brisbane/3/2007             80
## 4:           A/South Dakota/6/2007 (H1N1)              5
## 5: A/Uruguay/716/2007  NYMC X-175C (H3N2)            160
## 6:              A/Brisbane/59/2007 (H1N1)             40

Because some datasets such as flow cytometry results can contain a large number of rows, the function returns data.table objects to improve performance. This is especially important with multi-study connections.

Back to top

Filters

The datasets can be filtered before download. Filters should be created using Rlabkey’s makeFilter function.

Each filter is composed of three part: - A column name or column label - An operator - A value or array of values separated by a semi-colon

library(Rlabkey)
# Get participants under age of 30
young_filter <- makeFilter(c("age_reported", "LESS_THAN", 30))
# Get a specific list of two participants
pid_filter <- makeFilter(c("participantid", "IN", "SUB112841.269;SUB112834.269"))

For a list of available operators, see ?makeFilter.

# HAI data for participants of study SDY269 under age of 30
hai_young <- sdy269$getDataset("hai", colFilter = young_filter)
# List of participants under age 30
demo_young <- all$getDataset("demographics", colFilter = young_filter)
# ELISPOT assay results for two participants
mbaa_pid2 <- all$getDataset("elispot", colFilter = pid_filter)

Note that filtering is done before download. When performance is a concern, it is faster to do the filtering via the colfFilter argument than on the returned table.

Views

Any dataset grid on ImmuneSpace offers the possibility to switch views between ‘Default’ and ‘Full’. The Default view contains information that is directly relevant to the user. Sample description and results are joined with basic demographic. However, this is not the way data is organized in the database. The ‘Full’ view is a representation of the data as it is stored on ImmPort. The accession columns are used under the hood for join operations. They will be useful to developers and user writing reports to be displayed in ImmuneSpace studies.

Screen capture of the button bar of a dataset grid on ImmuneSpace

The original_view argument decides which view is downloaded. If set to TRUE, the ‘Full’ view is returned.

full_hai <- sdy269$getDataset("hai", original_view = TRUE)
print(colnames(full_hai))
##  [1] "participant_id"            "arm_accession"            
##  [3] "biosample_accession"       "expsample_accession"      
##  [5] "experiment_accession"      "study_accession"          
##  [7] "study_time_collected"      "study_time_collected_unit"
##  [9] "virus"                     "virus_strain"             
## [11] "virus_strain_preferred"    "value_reported"           
## [13] "value_preferred"           "unit_reported"            
## [15] "unit_preferred"

For additional information, refer to the ‘Working with tabular data’ video tutorial available in the menu bar on any page of the portal.

Back to top

Caching

As explained in the user guide, the ImmuneSpaceConnection class is a Reference class. It means its objects have fields accessed by reference. As a consequence, they can be modified without making a copy of the entire object. ImmuneSpaceR uses this feature to store downloaded datasets and expression matrices. Subsequent calls to getDataset with the same input will be faster.

See ?setRefClass for more information about reference classes.

We can see the data currently cached using the data_cache field. This is not intended to be used for data manipulation and only displayed here to explain what gets cached.

pcr <- sdy269$getDataset("pcr")
names(sdy269$data_cache)
## [1] "GE_matrices" "hai"         "hai_full"    "pcr"

Different views are saved separately.

pcr_ori <- sdy269$getDataset("pcr", original_view = TRUE)
names(sdy269$data_cache)
## [1] "GE_matrices" "hai"         "hai_full"    "pcr"         "pcr_full"

Because of the infinite number of filters and combinations of filters, we do not cache filtered datasets.

If, for any reason, a specific dataset needs to be redownloaded, the reload argument will clear the cache for that specific getDataset call and download the table again.

hai_269 <- sdy269$getDataset("hai", reload = TRUE)

Finally, it is possible to clear every cached dataset (and expression matrix).

sdy269$clear_cache()
names(sdy269$data_cache)
## [1] "GE_matrices"

Again, the data.cache field should never be modified manually. When in doubt, simply reload the dataset.

Back to top

sessionInfo()

sessionInfo()
## R version 3.3.0 (2016-05-03)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 14.04.4 LTS
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] Rlabkey_2.1.129    rjson_0.2.15       RCurl_1.95-4.8    
## [4] bitops_1.0-6       ImmuneSpaceR_1.0.2 rmarkdown_0.9.6   
## [7] knitr_1.13        
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.5         magrittr_1.5        BiocGenerics_0.18.0
##  [4] munsell_0.4.3       colorspace_1.2-6    plyr_1.8.3         
##  [7] stringr_1.0.0       caTools_1.17.1      tools_3.3.0        
## [10] parallel_3.3.0      grid_3.3.0          Biobase_2.32.0     
## [13] data.table_1.9.6    gtable_0.2.0        KernSmooth_2.23-15 
## [16] gtools_3.5.0        htmltools_0.3.5     yaml_2.1.13        
## [19] digest_0.6.9        reshape2_1.4.1      RColorBrewer_1.1-2 
## [22] ggplot2_2.1.0       formatR_1.4         evaluate_0.9       
## [25] labeling_0.3        pheatmap_1.0.8      gdata_2.17.0       
## [28] stringi_1.0-1       gplots_3.0.1        scales_0.4.0       
## [31] chron_2.3-47