Opal Projects

Yannick Marcon

2022-06-09

Opal stores data and meta-data (dictionaries) in projects that are accessible through web services. See the Variables and Data documentation page that explains the data model of Opal. See also the Resources documentation for an alternate way of accessing data in a project.

The Opal R package exposes projects related functions:

Note that these functions do not create a R session on the server side: it is only accessing the content of the Opal server (permission checks apply).

Setup

Setup the connection with Opal:

library(opalr)
o <- opal.login("administrator", "password", url = "https://opal-demo.obiba.org")

Project

List the projects:

opal.projects(o)

Create a project, linked to a database (default or first one):

if (opal.project_exists(o, "dummy"))
  opal.project_delete(o, "dummy")  
opal.project_create(o, "dummy", database = TRUE)
opal.project(o, "dummy")

Backup and Restore

Backup a project and download the backup archive (encrypted):

Restore a project from an uploaded (and encrypted) archive:

Tables

In Opal there are two kinds of tables:

List the tables in a project, with their count of variables and entities:

opal.tables(o, "CNSIM", counts = TRUE)

The table object can be retrieved as follow:

opal.table(o, "CNSIM", "CNSIM1", counts = TRUE)

The existence of a table can be checked:

opal.table_exists(o, "CNSIM", "CNSIM1")

And more specifically, verify whether a table is a view or not:

opal.table_exists(o, "CNSIM", "CNSIM1", view = TRUE)

A table can be created, either as a raw table or a view. To create a view, specify which tables are referred:

# drop table if it exists
opal.table_delete(o, "CNSIM", "CNSIM123")
# then create a view, no variables
opal.table_create(o, "CNSIM", "CNSIM123", tables = c("CNSIM.CNSIM1", "CNSIM.CNSIM2", "CNSIM.CNSIM3"))

Dictionaries

List the variables of a table and get the details of the variable annotations (one column per variable attribute with namespace). This is a summary dictionary, as it includes the concatenated category properties:

It is also possible to get the full data dictionary of a table, as separate data frames of variables and categories. This is the recommended format for working with a data dictionary:

Here we modify the data dictionary by appending a derivation script to each of the variables:

Then we apply this derived variables dictionary to the view we have previously created and verify the counts of columns (variables) and rows (entities) in this table:

Assign this view to a symbol in the R server, and get the summary statics:

Values

Get the values in a table for a specific Participant entity:

Get all the values of a table in our local R session as a data.frame (tibble) object:

Then do some alterations on this data.frame and save it back as a raw table:

Verify that this raw table resulting from the merge of the other tables as same values for a given Participant:

It is possible to truncate a table, i.e. delete ALL the values of a table (which must not be a view), without modifying the dictionary:

Annotations

Variables can be described by taxonomy terms.

List the taxonomies:

List the vocabularies of a taxonomy:

List the terms of a vocabulary:

To apply a taxonomy term to a table dictionary, use the following for batch annotation:

To list the variable annotations:

Resources

Resources are an alternative way of accessing data or computation systems. In a project are stored references to resources, i.e. how to build a resource object in R and the permissions to use this resource.

To list the resource references:

opal.resources(o, "RSRC")

To create a reference to a resource (a compressed CSV file, stored in a Opal file system, authorized by a personal access token):

if (opal.resource_exists(o, "RSRC", "CNSIM4"))
  opal.resource_delete(o, "RSRC", "CNSIM4")
opal.resource_create(o, "RSRC", "CNSIM4", 
   url = "opal+https://opal-demo.obiba.org/ws/files/projects/RSRC/CNSIM3.zip", 
   format = "csv", secret = "EeTtQGIob6haio5bx6FUfVvIGkeZJfGq")
# verify the resource reference object
opal.resource(o, "RSRC", "CNSIM4")

From a resource reference, it is possible to build and get the resource object in the local R session:

opal.resource_get(o, "RSRC", "CNSIM4")

Depending on the nature of the resource, it may be possible to coerce it to a data.frame in the client side:

library(resourcer)
as.data.frame(opal.resource_get(o, "RSRC", "CNSIM4"))

The same operation can be done on the R server side:

# assign the resource object
opal.assign.resource(o, "rsrc", "RSRC.CNSIM4")
# coerce it to a data.frame
opal.assign.script(o, "D", quote(as.data.frame(rsrc)))
# get some summary statistics
opal.execute(o, "summary(as.factor(D$GENDER))")

Permissions

Permissions can be managed (list, add, delete) at different levels:

Teardown

Good practice is to free server resources by sending a logout request:

opal.logout(o)