Spark Cluster-Enabled DXJupyterLab

Learn to use the DXJupyterLab Spark Cluster app.

DXJupyterLab is accessible to all users of the UK Biobank Research Analysis Platform and the Our Future Health Trusted Research Environment.

A license is required to access DXJupyterLab on the DNAnexus Platform. Contact DNAnexus Sales for more information.

Overview

The DXJupyterLab Spark Cluster App is a Spark application that runs a fully-managed standalone Spark/Hadoop cluster. This cluster enables distributed data processing and analysis from directly within the JupyterLab application. In the JupyterLab session, you can interactively create and query DNAnexus databases or run any analysis on the Spark cluster.

Besides the core JupyterLab features, the Spark cluster-enabled JupyterLab app allows you to:

  • Explore the available databases and get an overview of the available datasets

  • Perform analyses and visualizations directly on data available in the database

  • Create databases

  • Submit data analysis jobs to the Spark cluster

Check the general Overview for an introduction to DNAnexus JupyterLab products.

Running and Using DXJupyterLab Spark Cluster

The Quickstart page contains information on how to start a JupyterLab session and create notebooks on the DNAnexus Platform. The References page has additional useful tips for using the environment.

Instantiating the Spark Context

Having created your notebook in the project, you can populate your first cells as below. It is good practice to instantiate your Spark context at the beginning of your analyses, as shown below.

Basic Operations on DNAnexus Databases

Exploring Existing Databases

To view any databases to which you have access to in your current region and project context, run a cell with the following code:

A sample output should be:

You can inspect one of the returned databases by running:

which should return an output similar to:

To find a database in your current region that may be in a different project than your current context, run the following code:

A sample output should be:

To inspect one of the databases listed in the output, use the unique database name. If you use only the database name, results are limited to the current project. For example:

Creating Databases

Here's an example of how to create and populate your own database:

You can separate each line of code into different cells to view the outputs iteratively.

Using Hail

Hail is an open-source, scalable framework for exploring and analyzing genomic data. It is designed to run primarily on a Spark cluster and is available with DXJupyterLab Spark Cluster. It is included in the app and can be used when the app is run with the feature input set to HAIL (set as default).

Initialize the context when beginning to use Hail. It's important to pass previously started Spark Context sc as an argument:

We recommend continuing your exploration of Hail with the GWAS using Hail tutorial. For example:

Using VEP with Hail

To use VEP (Ensembl Variant Effect Predictor) with Hail, select "Feature," then "HAIL" when launching Spark Cluster-Enabled DXJupyterLab via the CLI.

VEP can predict the functional effects of genomic variants on genes, transcripts, protein sequences, and regulatory regions. This includes the LOFTEE plugin, which is activated when using the configuration file below.

Add the following JSON configuration file to your DNAnexus project:

Once the vep-GRCh38.json file is in your project, you can annotate the Hail MatrixTable (mt) using the following command:

Behind the Scenes

The Spark cluster app is a Docker-based app which runs the JupyterLab server in a Docker container.

The JupyterLab instance runs on port 443. Because it is an HTTPS app, you can bring up the JupyterLab environment in a web browser using the URL https://job-xxxx.dnanexus.cloud, where job-xxxx is the ID of the job that runs the app.

The script run at the instantiation of the container, /opt/start_jupyterlab.sh, configures the environment and starts the server needed to connect to the Spark cluster. The environment variables needed are set by sourcing two scripts, bind-mounted into the container:

The default user in the container is root.

The option --network host is used when starting Docker to remove the network isolation between the host and the Docker container, which allows the container to bind to the host's network and access Sparks master port directly.

Accessing AWS S3 Buckets

S3 buckets can have private or public access. Either the s3 or the s3a scheme can be used to access S3 buckets. The s3 scheme is automatically aliased to s3a in all Apollo Spark Clusters.

Public Bucket Access

To access public s3 buckets, you do not need to have s3 credentials. The example below shows how to access the public 1000Genomes bucket in a JupyterLab notebook:

When the above is run in a notebook, the following is displayed:

Private Bucket Access

To access private buckets, see the example code below. The example assumes that a Spark session has been created as shown above.

Last updated

Was this helpful?