Skip to main content

Python bindings to generate gosling schema.

Project description

gos 🦆

gos is a declarative (epi)genomics visualization library for Python. It is built on top of the Gosling JSON specification, providing an simplified interface for authoring interactive genomic visualizations.

Installation

Here be dragons 🐉

The API is experimental and under active development. Feedback is much appreciated and most welcomed.

pip install gosling

Example

import gosling as gos
from gosling.data import multivec

data = multivec(
    url="https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",
    row="sample",
    column="position",
    value="peak",
    categories=["sample 1", "sample 2", "sample 3", "sample 4"],
    binSize=5,
)

base_track = gos.Track(data, width=800, height=100)

heatmap = base_track.mark_rect().encode(
    x=gos.Channel("start:G", axis="top"),
    xe="end:G",
    row=gos.Channel("sample:N", legend=True),
    color=gos.Channel("peak:Q", legend=True),
)

bars = base_track.mark_bar().encode(
    x=gos.Channel("position:G", axis="top"),
    y="peak:Q",
    row="sample:N",
    color=gos.Channel("sample:N", legend=True),
)

lines = base_track.mark_line().encode(
    x=gos.Channel("position:G", axis="top"),
    y="peak:Q",
    row="sample:N",
    color=gos.Channel("sample:N", legend=True),
)

gos.vertical(heatmap, bars, lines).properties(
    title="Visual Encoding",
    subtitle="Gosling provides diverse visual encoding methods",
    layout="linear",
    centerRadius=0.8,
    xDomain=gos.Domain(chromosome="1", interval=[1, 3000500]),
)
Gosling visualization

Local data

Data sources for the Gosling specification are expected to be accessible via HTTP. Loading a local dataset can be challenging since it requires starting a web-server and/or a Higlass server for some pre-aggregated datasets. gos provides an experimental module that transparently serves data via a background ASGI server. The various data utilites are imported from the gosling.experimental.data module.

import gosling as gos
from gosling.experimental.data import bam, csv, bigwig # file resources
from gosling.experimental.data import beddb, vector, matrix, multivec # higlass tile resources

In order to use these utilities, you will need to install additional dependencies via:

pip install "gosling[all]"
pip install clodius # optional, required for higlass tile resources

In the example above, we can replace the remote Higlass server URL with a local path to the corresponding cistrome multivec file (https://s3.amazonaws.com/gosling-lang.org/data/cistrome.multires.mv5, 4GB). gos automatically detects the local file and will starts a background Higlass server to power the visualization.

import gosling as gos
from gosling.experimental.data import multivec

data = multivec(
-   url="https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",
+   url='../data/cistrome.multires.mv5', # path to local multivec
    row="sample",
    column="position",
    value="peak",
    categories=["sample 1", "sample 2", "sample 3", "sample 4"],
    binSize=4,
)

base_track = gos.Track(data, width=800, height=100)

Note that the visualizations will only render as long as your Python session is active.

Example Gallery

We have started a gallery of community examples in example/. If you are intereseted in contributing, please feel free to submit a PR! Checkout the existing JSON examples if you are looking for inspiration.

Development

pip install -e .

The schema bindings (gosling/schema/) and JS static assets (gosling/static/) are automatically generated using the following scripts. Please do not edit these files directly.

# generate gosling/schema/*
python tools/generate_schema_wrapper.py

# generate gosling/static/{widget.js,index.js} from src/{widget.ts,index.ts}
yarn install && yarn build:js

# Only run this if editing/using gos.GoslingWidget
jupyter nbextension install --py --symlink --overwrite --sys-prefix gosling
jupyter nbextension enable gosling --py --sys-prefix

Design & implemenation

gos is inspired by and borrows heavily from Altair both in project philosophy and implementation. The internal Python API is auto-generated from the Gosling specification using code adapted directly from Altair to generate Vega-Lite bindings. This design choice gaurentees that visualizations are type-checked in complete concordance with the Gosling specification, and that the Python API remains consitent with the evolving schema over time. Special thanks to Jake Vanderplas and others on schemapi.

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

gosling-0.0.2.tar.gz (12.4 MB view details)

Uploaded Source

Built Distribution

gosling-0.0.2-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file gosling-0.0.2.tar.gz.

File metadata

  • Download URL: gosling-0.0.2.tar.gz
  • Upload date:
  • Size: 12.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for gosling-0.0.2.tar.gz
Algorithm Hash digest
SHA256 cd7ea386b6b3468f45714bb41dbfb4a591260a2cce83ca4f18573647ebe349a4
MD5 c22315682eb3e865157ee717cf1b0033
BLAKE2b-256 6222708586b1b3ff53e678ddfe3229930badb63aef708e61db8c849357d617c3

See more details on using hashes here.

File details

Details for the file gosling-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gosling-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for gosling-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3169c5c9275796e550331ac0a3594c75b465f8169a05b8be68c7a12a5172f93b
MD5 bfcb9ac24f15b291f3bbb36b1a2eb3c1
BLAKE2b-256 2dc3a81283af74d15dfe198698108695603cdb308ace3223371bd4fffc7d7624

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