Skip to content

manzt/pygv

Repository files navigation

pygv

a minimal, scriptable genome browser for python built with anywidget

installation

Here be dragons 🐉

pip install pygv

usage

import pygv

# set the reference genome
pygv.ref("mm10")

# set the locus
pygv.locus("chr17:31,531,100-31,531,259")

# create a browser instance
pygv.browse("fragments.bed", "10x_cov.bw")

igv.js in Jupyter Notebook

That's it. By default, pygv infers the track and data-types by file extension. If a file format has an index file, it must be specified as a tuple (remote URLs also work):

pygv.browse(
  (
    "https://example.com/example.bam",     # data file
    "https://example.com/example.bam.bai"  # index file
  )
)

You can use track to adjust track properties beyond the defaults:

pygv.browse(
  pygv.track("10x_cov.bw", name="10x coverage", autoscale=True),
)

Multiple tracks are supported by adding to the browse call:

pygv.browse(
  # track 1
  (
      "https://example.com/example.bam",
      "https://example.com/example.bam.bai"
  ),
  # track 2
  pygv.track("10x_cov.bw", name="10x coverage", autoscale=True),
  # track 3
  pygv.track("genes.bed", name="Genes", color="blue"),
)

development

development requires uv

uv run jupyter lab # open notebook with editable install
uv run pytest      # testing
uv run ruff check  # linting
uv run ruff format # formatting