Skip to main content

Jupyter extension for embedding the igv.js genome visualization in a notebook

Project description

igv Jupyter Extension

Binder

igv-jupyter is an extension for Jupyter Notebook which wraps igv.js. With this extension you can render igv.js in a cell and call its API from the notebook. The extension exposes a python API that mimics the igv.js Browser creation and control APIs. Dictionaries are used for browser and track configuration objects. Track data can be loaded from local or remote URLs, or supplied directly as lists of objects.

Installation

Requirements:

  • python >= 3.6.4
  • jupyterlab >= 3.0
pip install igv-jupyter

# To install to configuration in your home directory
jupyter serverextension enable --py igv
jupyter labextension enable --py igv
jupyter nbextension install --py igv
jupyter nbextension enable --py igv


# If using a virtual environment
jupyter serverextension enable --py igv --sys-prefix
jupyter labextension enable --py igv --sys-prefix
jupyter nbextension install --py igv --sys-prefix
jupyter nbextension enable --py igv --sys-prefix

Usage

Examples

Example notebooks are available in the github repository. To download without cloning the repository use this link. Notebooks are available in the "examples" directory.

Initialization

To insert an IGV instance into a cell:

(1) create an igv.Browser object,and (2) call showBrowser on the instance.

Example:

import igv

b = igv.Browser({"genome": "hg19"})

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

To instantiate the client side IGV instance in a cell call show()

b.show()

Tracks

To load a track pass a track configuration object to load_track(). Track configuration objects are described in the igv.js documentation. 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 or passed directly as an array of JSON objects.

Remote URL

b.load_track(
    {
        "name": "Segmented CN",
        "url": "https://data.broadinstitute.org/igvdata/test/igv-web/segmented_data_080520.seg.gz",
        "format": "seg",
        "indexed": False
    })

Local File

b.load_track(
    {
        "name": "Local VCF",
        "url": "data/example.vcf",
        "format": "vcf",
        "type": "variant",
        "indexed": False
    })

Embedded Features

Features can also be passed directly to tracks.

b.load_track({
    "name": "Copy number",
    "type": "seg",
    "displayMode": "EXPANDED",
    "height": 100,
    "isLog": True,
    "features": [
        {
            "chr": "chr20",
            "start": 1233820,
            "end": 1235000,
            "value": 0.8239,
            "sample": "TCGA-OR-A5J2-01"
        },
        {
            "chr": "chr20",
            "start": 1234500,
            "end": 1235180,
            "value": -0.8391,
            "sample": "TCGA-OR-A5J3-01"
        }
    ]
})

Navigation

Zoom in by a factor of 2

b.zoom_in()

Zoom out by a factor of 2

b.zoom_out()

Jump to a specific locus

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

Jump to a specific gene. This uses the IGV search web service, which currently supports a limited number of genomes: hg38, hg19, and mm10. To configure a custom search service see the igv.js documentation

b.search('myc')

SVG output

Saving the current IGV view as an SVG image requires two calls.

b.get_svg()

b.display_svg()

Events

Note: This is an experimental feature.

def locuschange(data):
    b.locus = data

    b.on("locuschange", locuschange)

    b.zoom_in()

    return b.locus

Development

To build and install from source:

python setup.py build
pip install -e .
jupyter labextension develop . --overwrite
jupyter nbextension install --py igv --symlink
jupyter nbextension enable --py igv

After source changes, the extension can be rebuilt using:

jupyter labextension build .

Creating a conda environment

conda create -n test python=3.7.1
conda activate test
conda install pip
conda install jupyter

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-jupyter-0.10.0b0.tar.gz (3.6 MB view details)

Uploaded Source

Built Distribution

igv_jupyter-0.10.0b0-py3-none-any.whl (7.5 MB view details)

Uploaded Python 3

File details

Details for the file igv-jupyter-0.10.0b0.tar.gz.

File metadata

  • Download URL: igv-jupyter-0.10.0b0.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for igv-jupyter-0.10.0b0.tar.gz
Algorithm Hash digest
SHA256 ce32feb362b7ff019044323275367ce2b4154ee1e99a1398eaa6920c31366217
MD5 ee6659315b6c68c51479f600cc053a15
BLAKE2b-256 d3837974d7fd9924a2c2d60828f8682361ec68c85009f9f9496a3d11952229fc

See more details on using hashes here.

File details

Details for the file igv_jupyter-0.10.0b0-py3-none-any.whl.

File metadata

  • Download URL: igv_jupyter-0.10.0b0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for igv_jupyter-0.10.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8e3b6d652f72d2fb0a0335194d042da78887fa4374873e28338e5ac970e96bc
MD5 4e3b585af5e092bfcec0d6ec0c651225
BLAKE2b-256 31f200164962df4a17d4e7ba4643cd2913285556b76dfdecd839c33943eff2e5

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