JupyterLab in Galaxy
How can I manipulate data using JupyterLab in Galaxy?
How can I start a notebook in JupyterLab?
How can I import/export dataset from/to my history to/from the notebook?
How can I save my notebook to my history?
Launch JupyterLab in Galaxy
Start a notebook
Use get() to import datasets from your history to the notebook
Use put() to export datasets from the notebook to your history
Save your notebook into your historyTime estimation: 1 hourSupporting Materials:Last modification: Sep 28, 2022License: Tutorial Content is licensed under Creative Commons Attribution 4.0 International License. The GTN Framework is licensed under MITpurl PURL: https://gxy.io/GTN:T00153version Revision: 11
JupyterLab is an Integrated Development Environment (IDE). Like most IDEs, it provides a graphical interface for R/Python, making it more user-friendly, and providing dozens of useful features. We will introduce additional benefits of using JupyterLab as you cover the lessons.
In this tutorial, we will cover:
Opening up JupyterLab is quite easy:
Hands-on: Launch JupyterLabHands-on: Run JupyterLab
- Interactive Jupyter Notebook. Note that on some Galaxies this is called Interactive JupyTool and notebook:
- Click Run Tool
The tool will start running and will stay running permanently
This may take a moment, but once the
Executed notebookin your history is orange, you are up and running!
- Click on the User menu at the top and go to Active Interactive Tools and locate the JupyterLab instance you started.
- Click on your JupyterLab instance
If JupyterLab is not available on the Galaxy instance:
- Start Try JupyterLab
You should now be looking at a page with the JupyterLab interface:
As shown on the figure above, JupyterLab interface is made of 3 main areas:
- The menu barat the top
- The left side bar with in particular the File Browser
- The main work area in the central panel
Start your first notebook
Now that we are ready to start exploring JupyterLab, we will want to keep a record of the commands we are using. To do this we can start a Notebook.
Hands-on: Start a notebook
- On the left side bar, in the File Browser, double-click on the file called ipython_galaxy_notebook.ipynb. This will open the default notebook in the main work area.
- If ipython_galaxy_notebook.ipynb does not exist (for instance on Try JupyterLab) then click on + (top left) to start The launcher and then Python icon in the Notebook section to create a new blank notebook.
A new notebook appears in the centre panel. Before we go any further, you should learn to save your script.
Hands-on: Save a Python notebook
- Click the File menu and select **Save Notebook As… Alternatively, you can also:
- Click the galaxy-save icon (Save the notebook contents and create checkpoint) in the bar above the first line in the script editor
- Click the File menu and select Save Notebook
- Type CTRL+S (CMD+S on OSX)
- In the Save Notebook As window that opens, name your file
ipython_galaxy_notebokAlternatively, you can also rename your Jupyter Notbook:
- Right click on the name (
Untitled.ipynb) in the bar above the first line in the script editor and select Rename Notebook
The new script
ipython_galaxy_notebook.ipynb should appear in the File Browser* in the left panel. By convention, Jupyter notebooks end with the file extension
.ipynb independently of the programming language (R, Python, Octave, Julia, etc.).
Depending on your JupyterLab instance, the list of supported programming languages may vary. On Live.useGalaxy.eu, the following programming languages are currently supported:
- Python 3
By default, a Python notebook is started. Don’t worry if you are not familiar with Python programming language, it is not necessary for this tutorial. The same functionalities applies for any available programming languages.
Once you have created a Notebook, you can switch to another available programming language (Switch kernel).
- On the top right of your running Notebook, click on Python 3. A new window pops up:
- In this new window, click on Python 3 to select an available programming language (R, octave, Julia, etc.).
- Click on Select to activate your selection. The pop-up window closes and you are ready to use your notebook with the selected programming language. Alternatively, you can also:
- Click on + (top left menu) to start the Launcher. The list of available programming language is given in the Notebook section.
- Click on icon of your choice in the Notebook section.
- A new notebook is created with the programming language of your choice.
Hands-on: Import Python libraries
- Click on a cell of your notebook to edit it (verify that it is defined as a “Code” cell)
- Enter the following lines:
import numpy as np import matplotlib.pyplot as plt
- Shift+Return to run the cell or click on the run cell button.
Graph Display in JupyterLab with Python
In this tutorial we are going to simply plot a simple graph using generated data.
Hands-on: Draw a simple plot
Generate a simple dataset
x = np.linspace(0, 2, 100) y = x**2
Create your figure with the command:
fig, ax = plt.subplots( nrows=1, ncols=1 ,figsize=(15, 10) )
nrows=1, ncols=1means you will have one plot in your figure (one row and one column)
figsizeparameter determine the size of the figure
Draw the plot with the command
Interaction between JupyterLab and Galaxy
Import / export Data
You can import data from Galaxy history using the
get(12) command, with the number of your dataset in the history (If you are working on a collection, unhide datasets to see their numbers).
If you want to save a file you generated in your notebook, use the
put("file_name") command. That is what we are going to do with our distribution plot.
Hands-on: Save an Jupyter generated image into a Galaxy History
- Create an image file with the figure you just draw with the command
- Export your image into your history with the command
Save the Notebook in your history
Once you are done with you analysis or anytime during the editing process, you can save the notebook into your history using the
put("ipython_galaxy_notebook.ipynb"). If you create additional notebooks with different names, make sure you save them all before you quit JupyterLab.
This will create a new notebook
.pynb file in your history every time you click on this icon.
Hands-on: Closing JupyterLab
Click User: Active Interactive Tools
Tick galaxy-selector the box of your Jupyter Interactive Tool, and click Stop