Skip to main content

Package for embedding the igv.js genome visualization in IPython notebooks

Project description

igv.js notebook module

Binder Jupyter Notebook

Binder JupyterLab

Colab Google Colab

PyPI

============

igv-notebook is a Python package which wraps igv.js for embedding in an IPython notebook. Both Jupyter and Google Colab platforms are supported.

Related projects

Other projects enabling embedding igv.js in notebooks include

The main differences between igv-notebook and these other projects are:

  • igv-notebook is a "plain" Python package, while the projects listed above are Jupyter extensions;
  • igv-notebook works with Google Colab, in addition to Jupyter and JupyterLab; and
  • igv-notebook supports loading data files from any location on the local or mounted file system when used with Jupyter Notebook or Google Colab. NOTE: General local file paths do not work with JupyterLab, for JupyterLab local files must be in the JupyterLab file tree.

Examples

Example notebooks are available in the github repository, and can be run from the Binder and Colab links above. To download examples without cloning the repository use this link. Notebooks are available in the "examples" directory.

Usage

Typical usage proceeds as follow

  1. Install igv-notebook
  2. Initialize igv-notebook
  3. Create igv "browser" object
  4. Add tracks to browser
  5. Navigate to loci of interest

Installation

pip install igv-notebook

Initialization

After installing, import and intialize igv_notebook as follows.

import igv_notebook
igv_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 initialization must be repeated for each cell in which igv-notebook is used. `

Browser creation

The Browser initializer takes a configuration dictionary which is converted to JSON and passed to the igv.js createBrowser function. The configuration options are described in the igv.js documentation.

Example:

import igv_notebook
igv_notebook.init()
igv_browser= igv_notebook.Browser(
    {
        "genome": "hg19",
        "locus": "chr22:24,376,166-24,376,456",
        "tracks": [{
            "name": "BAM",
            "url": "https://s3.amazonaws.com/igv.org.demo/gstt1_sample.bam",
            "indexURL": "https://s3.amazonaws.com/igv.org.demo/gstt1_sample.bam.bai",
            "format": "bam",
            "type": "alignment"
        }],
        "roi": [
            {
                "name": "ROI set 1",
                "url": "https://s3.amazonaws.com/igv.org.test/data/roi/roi_bed_1.bed",
                "indexed": False,
                "color": "rgba(94,255,1,0.25)"
            }
        ]
    }
)

URLS and paths

Configuration objects for igv.js have properties to specify URLs to files for data and indexes. These properties are supported in igv-notebook, however igv-notebook also provides equivalent path properties for specfiying paths to local files when used with Jupyter Notebook or Colab. (Note: The path properties cannot be used with JupyterLab, however local files can be loaded by URL if they are in the Jupyter file tree). The path properties are useful for:

  • loading data in a Colab notebook from the local Colab file system or a mounted Google Drive; and
  • loading data in Jupyter Notebook from the local file system that is outside the Jupyter file tree.

URL and Path properties

igv.js url property igv-notebook path property
url path
indexURL indexPath
fastaURL fastaPath
cytobandURL cytobandPath
aliasURL aliasPath

For Jupyter servers (Notebook and Lab), local files can be also be loaded via the url property if the file is in the Jupyter startup directory tree. This will usually yield better performance than using path properties. URL paths that begin with a "/" are relative to the Jupyter server startup directory, i.e. the directory from where you started Jupyter Notebook or JupyterLab. For Jupyter Notebook, 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 "download url" for the file, obtainable through the JupyterLab UI, as the URL for igv.

Tracks

To load a track, pass a track configuration object to igv_browser.load_track(). Track configuration objects are described in the igv.js documentation, however see the note on URLs and paths above. The configuration object will be converted to JSON and passed to the igv.js browser instance.

Data for the track can be loaded by URL, file path, or passed directly as an array of JSON objects.

Examples:

Local file - Jupyter. URL relative to the location of the notebook

igv_browser.load_track(
    {
        "name": "Local BAM",
        "url": "data/gstt1_sample.bam",
        "indexURL": "data/gstt1_sample.bam.bai",
        "format": "bam",
        "type": "alignment"
    })

Local file - Jupyter. URL relative to root of Jupyter file tree

igv_browser.load_track(
    {
        "name": "Local BAM",
        "url": "/examples/data/gstt1_sample.bam",
        "indexURL": "/examples/data/gstt1_sample.bam.bai",
        "format": "bam",
        "type": "alignment"
    })

Local file - Jupyter. Absolute file path, potentially outside the Jupyter file tree. Note the use of path and indexPath.

igv_browser.load_track(
    {
        "name": "Local BAM",
        "path": "/any_path_you_like/data/gstt1_sample.bam",
        "indexPath": "/any_path_you_like/data/gstt1_sample.bam.bai",
        "format": "bam",
        "type": "alignment"
    })

Local file - Colab. In Colab files are loaded by file path.

igv_browser.load_track(
    {
        "name": "Local BAM",
        "path": "/content/igv-notebook/examples/data/gstt1_sample.bam",
        "indexPath": "/content/igv-notebook/examples/data/gstt1_sample.bam.bai",
        "format": "bam",
        "type": "alignment"
    })

Remote file - Jupyter.

igv_browser.load_track(
    {
        "name": "BAM",
        "url": "https://s3.amazonaws.com/igv.org.demo/gstt1_sample.bam",
        "indexURL": "https://s3.amazonaws.com/igv.org.demo/gstt1_sample.bam.bai",
        "format": "bam",
        "type": "alignment"
    })

API

Most IGV options can be specified in the initial browser configuration, including specifying genome, locus, tracks, and regions-of-interest. Additional methods are provided to perform actions on the IGV browser post-creation. These are described below

Load a track**

To load a track

igv_browser.load_track(track_config)

See example track configurations above. Also igv.js wiki

Example:

igv_browser.load_track(
    {
        "name": "Local BAM",
        "url": "data/gstt1_sample.bam",
        "indexURL": "data/gstt1_sample.bam.bai",
        "format": "bam",
        "type": "alignment"
    })

Load regions of interest** (version >= 0.4.0)

Regions-of-interest are overlays marking genomic ranges of interest. They are defined by track configurations, often backed by a "bed" file, and usually with a translucent color. These can be specified at browser creation with the "roi" property, or loaded afterwards with the ```loadROIs`` function. This function takes an array of track configuration objects. See the notebook examples/ROI.ipynb for example usage.

igv_browser.loadROIs([roi_configs])

Navigation

Jump to a specific genomic range

igv_browser.search('chr1:3000-4000')

Jump to a specific gene. This uses the IGV search web service, which currently supports a limited number of genomes. To extend or customize the search, load a non-indexed annotation track with the "searchable" property set to true (see igv.js documentation).

igv_browser.search('myc')

Zoom in by a factor of 2

igv_browser.zoom_in()

Zoom out by a factor of 2

igv_browser.zoom_out()

SVG conversion - Jupyter Notebook only

To convert the current igv view to a static SVG image

igv_browser.to_svg()

This action can also be invoked with the "To SVG" button on the igv.js command bar. This is useful when converting the notebook to formats such as HTML and PDF. Note: This action is not reversible.

Version

To verify the currently installed igv-notebook version (versions >= 0.3.1 only)

igv_notebook.version()

To verify the current version of igv.js (igv-notebook versions >= 0.4.0 only)

igv_notebook.igv_version()

Development

requires python >= 3.9.1

Development install

pip install -e .

Build

python setup.py build  

Updating igv.js version

  1. Edit VERSION_IGV - enter igv.js version with no line feed. Visit npmjs.com to find latest version
  2. Run python updateIGV.py

Release Notes

0.5.2

  • Bug fix -- igv undefined

0.5.1

  • Update igv.js version to 2.15.7

0.5.0

  • Add support for loading an igv session
  • Generate links to igv-web

0.4.5

  • Fix path/url problems when using JupyterLab

0.4.4

  • Add missing requirements to setup.py
  • Update igv.js version to 2.13.10

0.4.3

  • Fix file-not-found error with version() and igv_version() functions

0.4.1

  • Update documentation

0.4.0

  • Add support for regions-of-interest
  • Add igv_notebook.igv_version() function.

0.3.1

  • Update browser.to_svg() function to support Python 3.6.
  • Add igv_notebook.version() function.

0.3.0

  • Add browser.to_svg() function to convert igv instance to static SVG image (Jupyter Notebook only).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

igv-notebook-0.6.0.tar.gz (391.6 kB view details)

Uploaded Source

Built Distribution

igv_notebook-0.6.0-py3-none-any.whl (390.3 kB view details)

Uploaded Python 3

File details

Details for the file igv-notebook-0.6.0.tar.gz.

File metadata

  • Download URL: igv-notebook-0.6.0.tar.gz
  • Upload date:
  • Size: 391.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.1

File hashes

Hashes for igv-notebook-0.6.0.tar.gz
Algorithm Hash digest
SHA256 136ce41ad4433ed6ab2a142fc7bbbc4d7f14d88b37d39359fc26f105e8d445cd
MD5 5a6fee693a6f8beab368c8ab43e97515
BLAKE2b-256 27f5b58b9a00376ff5ccaa9b46112f720cb8902b69be17273f8f8dca9610fb8d

See more details on using hashes here.

File details

Details for the file igv_notebook-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: igv_notebook-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 390.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.1

File hashes

Hashes for igv_notebook-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 493fafdea5a9a2b9ce6e4cd5230dcb9d9b88d067905693cab10bf27ecfed1429
MD5 f7c4592fd0d18e46004ba07335069f85
BLAKE2b-256 55e485c29feb0366635dfbeebca2e8b3f3fe3aee5ffff63e0f461676c607c4b4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page