Git Product home page Git Product logo

hg's Introduction

Note [2023-03-14] hg has a new home (and an official release!) under higlass/higlass-python. This repo is now read-only ๐Ÿš€

hg ๐Ÿ”Ž

a fresh python library for higlass built on top of higlass-schema and higlass-widget.

License Open In Colab

development

pip install -e .
jupyter notebook notebooks/Examples.ipynb

usage

import hg

# Remote data source (tileset)
tileset1 = hg.remote(
    uid="CQMd6V_cRw6iCI_-Unl3PQ",
    server="https://higlass.io/api/v1/",
    name="Rao et al. (2014) GM12878 MboI (allreps) 1kb",
)

# Local tileset
tileset2 = hg.cooler("../data/dataset.mcool")

# Create a `hg.HeatmapTrack` for each tileset
track1 = tileset1.track("heatmap")
track2 = tileset2.track("heatmap")

# Create two independent `hg.View`s, one for each heatmap
view1 = hg.view(track1, width=6)
view2 = hg.view(track2, width=6)

# Lock zoom & location for each `View`
view_lock = hg.lock(view1, view2)

# Concatenate views horizontally and apply synchronization lock
(view1 | view2).locks(view_lock)

Side-by-side Hi-C heatmaps, linked by pan and zoom

hg's People

Contributors

manzt avatar agalitsyna avatar

Stargazers

Nikolai Bykov avatar Alexander Lenail avatar Roshni Biswas avatar Sunil Nahata avatar Sergey Venev avatar Dmitry Mylarshchikov avatar  avatar Jennifer Melot avatar Nils Gehlenborg avatar Nezar Abdennur avatar Peter Kerpedjiev avatar

Watchers

 avatar

Forkers

agalitsyna

hg's Issues

refactor fuse functionality

Currently the API for setting up fuse is kind of clunky and requires setup/teardown by the user. Additionally, there could be some issues where multiple users try to setup setup/teardown fuse in the same target directory.

Current

import hg
hg.fuse.start('/path/to/dir')
path = hg.fuse.path('https://example.com/data.bigwig') # /path/to/dir/mnt/https/example.com/data.bigwig..

Proposal

Setting up FUSE should happen in the command line if possible

python -m hg.fuse path/to/dir # sets environment variable
import hg
path = hg.fuse_path('https://example.com/data.bigwig') # just a utility that looks up the global fuse process and returns the correct path

Thoughts on CLI

At a minimum, something like:

python -m hg.view ./data/data.mcool ./data/data.bigwig # opens web browser with view

inferring tilesets, tracks, and track types. But this API falls apart quickly for more complicated views.

Perhaps more useful would just be to have a nice way to open an hg view in the browser (rather than jupyter notebook). Then users can just write python scripts that create the configurations and end with hg.open(viewconf)..

bug: Plugins broken

ugh #30 breaks the higlass plugin support since higlass is no longer loaded as a global....

Support remote Jupyter/MyBinder notebooks

Motivation

The background server in hg runs on a separate port. This works fine when notebooks are local because notebooks are located on localhost:XXXX and are able to make requests to another local port.

An issue arrises when using remote notebooks because the JS client needs to make requests to a separate port on the remote server. (read: HiGlass client gets a url for http://localhost:12345 in user browser but it's for the remote server port 12345)

Solution

The good news is that there are solutions to this within notebooks. In Jupyter/MyBinder we can use jupyter-server-proxy, but we want to avoid this with Google Colab and locally. The strategy is just to modify the server url based on the context of the notebook. For the following URL, here's what needs to happen:

http://localhost:12345

  • Local Jupyter - no-op, should just
  • Remote Jupyter/MyBinder (running on localhost:8888) http://localhost:8888/proxy/12345
  • Google Colab - no-op! Colab uses a service worker to proxy authenticated requests from the client and fixes this issue for us!

Alternatives

The last solution from Colab is really elegant (using a service worker), but I couldn't inline a service worker of my own into hg/display.py to inspect the rendering context and transform URLs.

__truediv__ for divided tracks?

Current

import hg

t1 = hg.track(...)
t2 = hg.track(...)
t3 = hg.divide(t1, t2)

Proposed

import hg

t1 = hg.track(...)
t2 = hg.track(...)
t3 = t1 / t2

Pros - currently implemented in higlass-python. More concise
Cons - could get confusing with the view composition API

Top-level tileset helpers

Currently API usage looks like this:

import hg
import hg.tilesets

ts = hg.tilesets.bigwig('data.bigwig') # create tileset
ts = hg.server.add(ts) # returns a TilesetResource

hg.viewconf(hg.view(track))

This makes adding resources to the server explicitly, but is a bit verbose and will be repeated for every tileset.

Alternatively, we could just export hg.<tileset>: convenience methods for adding tilesets to the server:

import hg

ts = hg.bigwig('data.bigwig') # create tileset and add to server, creates uid based on path
hg.viewconf(hg.view(ts.track()))

composition API for views

The current API is pretty clunky for arranging multiple views. I really don't like the View.move API. The challenge is the each view contains a layout which is describes how it is positioned in the global context. This means that users must understand and be explicit about the grid system.

Current

import hg

view1 = hg.view(...)
view2 = hg.view(...).move(x=6) # positioning of views is explicit, and requires users to understand grid

hg.viewconf(view1, view2)

I think the most desirable API is one where a view can be defined in isolation, just width and height, and then we provide utilities for stacking views. e.g.

Proposed API

import hg

view1 = hg.view(...)
view2 = hg.view(...)

hg.viewconf(view1 / view2) # change y for view2 by view1
hg.viewconf(view1 | view2) # change x for view2 by view1

hg with remote notebook loading remote file

Running a remote notebook that loads remote file works for me with a couple of additional actions:

  1. Run jupyter with specifying --ip, it should be the same as how you access the notebook:
    jupyter notebook --no-browser --port=9998 --ip=localhost

  2. Enable proxy right after import:

import hg
hg.server.enable_proxy()

It will be great to have that explained in the docs!

Directional locks

The HiGlass UI allows more sophisticated configuration of locks. These configurations aren't currently expressed via the hg.lock API:

image

Perhaps something like:

hg.lock(view1, with=view2)
hg.lock(view1, view2)

I think the challenge is that locks are context specific, so defining them as independent objects is challenging.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.