juicebox-notebook is an module for Jupyter and Colab notesbooks which exposes a python API that enables creation and interaction with a juicebox.js instance in a cell.
Example notebooks are available in the github repository in the "examples" directory of the github repository.
Requirements:
- python >= 3.6.4
- jupyter >= 4.2.0
pip install juicebox-notebook
After installing import and intialize igv_notebook as follows.
import juicebox_notebook
juicebox_notebook.init()
For a Jupyter notebook this should be done once per notebook. Colab notebooks display output in a sandboxed iFrame for each cell, so these steps must be repeated for each cell in which juicebox-notebook is used.
The juicebox_notebook.Browser constructor takes a configuration object which is converted to JSON and passed to the juicebox.js createBrowser function. The configuration object is described in the juicebox.js documentation. To open an empty "browser" to dynamically load maps pass an empty dictionary.
Example:
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser(
{
"name": "GM12878",
"url": "https://www.encodeproject.org/files/ENCFF179HVU/@@download/ENCFF179HVU.hic",
"tracks": [
{
"url": "https://www.encodeproject.org/files/ENCFF000ARJ/@@download/ENCFF000ARJ.bigWig",
"name": "CTCF",
"color": "rgb(22, 129, 198)"
}
]
}
)
Typically maps and tracks are loaded in the initial juicebox.Browser
creation. However its also possible to
load them post creation using the b.load_map(config
and b.load_track
functions.
Maps
To load a map into an existing browser pass a hic file configuration object to the load_map function
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser({})
b.load_map(
{
"url": "https://hicfiles.s3.amazonaws.com/hiseq/gm12878/in-situ/primary.hic"
}
)
Tracks
To load a track pass a track configuration object to load_track. Track configuration objects are described in the juicebox.js documentation. The configuration object will be converted to JSON and passed to the juicebox.js browser instance.
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser({
"name": "GM12878",
"url": "https://www.encodeproject.org/files/ENCFF179HVU/@@download/ENCFF179HVU.hic"
}
)
b.load_track({
"url": "https://www.encodeproject.org/files/ENCFF000ARJ/@@download/ENCFF000ARJ.bigWig",
"name": "CTCF",
"color": "#ff8802"
}
)
Configuration objects for juicebox.js maps (.hic files) and tracks have properties to specify URLs to files for
data and indexes. These properties are supported in juicebox-notebook, however juicebox-notebook also provides
equivalent path
properties for specfiying paths to local files when used with Jupyter Notebook or Colab.
The path
properties are useful for
- Loading data in a Colab notebook from the local Colab file system or a mounted Google Drive
- Loading data in Jupyter Notebook from the local file system that is outside the Jupyter file tree.
URL and Path properties
juicebox.js url property | juicebox-notebook path property | notes |
---|---|---|
url | path | |
indexURL | indexPath | Used in some track configurations. See igv.js |
(Note: The path
properties cannot be used with JupyterLab, however local files can
be loaded by URL).
For Jupyter servers (Notebook and Lab) local files can be also be loaded via the url property if the file is in
Jupyter directory tree. This will usually yield better performance than using path
properties. URLs that begin
with a "/" are relative to the Jupyter server startup directory, that is the directory from where you started
Jupyter Notebook or JupyterLab. For Jupyter Notebook only, URL paths without a leading slash can be used and
are assumed to be relative to the notebook directory. See below for examples. You can also use the JupyterLab
"download url" for the file, obtainable through the JupyterLab UI, as the
URL for juicebox.
Examples:
Jupyter Notebook and Colab. Local files using absolute file paths, potentially outside the Jupyter file tree. Note the use
of path
instead of url
.
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser(
{
"name": "GM12878",
"path": "/TestData/juicebox/HCT-116_Untreated.hic",
"tracks": [
{
"path": "/TestData/juicebox/CTCF_Untreated.bw",
"type": "wig",
"name": "CTCF",
"color": "rgb(22, 129, 198)"
}
]
}
)
Jupyter Notebook and JupyterLab. Local files using urls relative to the startup directory of the Jupyter server.
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser(
{
"name": "GM12878",
"url": "/TestData/juicebox/HCT-116_Untreated.hic",
"tracks": [
{
"url": "/TestData/juicebox/CTCF_Untreated.bw",
"type": "wig",
"name": "CTCF",
"color": "rgb(22, 129, 198)"
}
]
}
)
Jupyter Notebook and Lab. Local files using urls relative to the directory of the notebook.
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser(
{
"name": "GM12878",
"url": "TestData/juicebox/HCT-116_Untreated.hic",
"tracks": [
{
"path": "TestData/juicebox/CTCF_Untreated.bw",
"type": "wig",
"name": "CTCF",
"color": "rgb(22, 129, 198)"
}
]
}
)
All platforms. Remote files using urls.
import juicebox_notebook
juicebox_notebook.init()
b = juicebox_notebook.Browser(
{
"name": "GM12878",
"url": "https://www.encodeproject.org/files/ENCFF179HVU/@@download/ENCFF179HVU.hic",
"tracks": [
{
"url": "https://www.encodeproject.org/files/ENCFF000ARJ/@@download/ENCFF000ARJ.bigWig",
"name": "CTCF",
"color": "rgb(22, 129, 198)"
}
]
}
)