Streamlit - Gosling
A Streamlit component to display Genomic Visualization using Gosling.
An online demo is host at Streamlit Clound.
Checkout the code of the demo
Install
pip install streamlit-gosling streamlit
also need to install its dependencies gosling and streamlit
pip install gosling
pip install streamlit
Usage
This library provides 2 functions to display gosling visualization :
from_gosto display visualization from a gosling instances. Make sure you havegoslinginstalled viapip install gosling.from_jsonto display visualization from Golsing spec in the form Python dict.
using from_gos
import streamlit as st
import gosling as gos
import streamlit_gosling as st_gos
size = 500
# create visualization using gosling
@st.cache
def chart():
data = gos.matrix("https://server.gosling-lang.org/api/v1/tileset_info/?d=leung2015-hg38")
return gos.Track(data).mark_bar().encode(
x=gos.X("xs:G", axis="bottom"),
xe="xe:G",
y=gos.Y("ys:G", axis="left"),
ye="ye:G",
color=gos.Color("value:Q", range="hot", legend=True),
).properties(width=size, height=size).view()
# wrap gosling visualization as a streamlit component
st_gos.from_gos(
spec=chart(),
id='id',
height=size+ 100
)
using from_json
import streamlit_gosling as st_gos
spec = {
"title": "Basic Marks: bar",
"subtitle": "Tutorial Examples",
"tracks": [
{
"layout": "linear",
"width": 800,
"height": 180,
"data": {
"url": "https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",
"type": "multivec",
"row": "sample",
"column": "position",
"value": "peak",
"categories": ["sample 1"],
"binSize": 5
},
"mark": "bar",
"x": {"field": "start", "type": "genomic", "axis": "bottom"},
"xe": {"field": "end", "type": "genomic"},
"y": {"field": "peak", "type": "quantitative", "axis": "right"},
"size": {"value": 5}
}
]
}
st_gos.from_gos(
spec=spec,
id='gos_bar',
height= 200
)
API
streamlit-gosling API
from_gos(id: string,
spec: a gosling visualization object,
height: number,
exportButton: boolean,
eventType?: 'mouseOver' | 'click' | 'rangeSelect',
api?
)
from_json(id: string,
spec: a gosling JSON spec as python dicts
height: number,
exportButton: boolean,
eventType?: 'mouseOver' | 'click' | 'rangeSelect',
api?
)
-
id:
string -
spec: a visualization object created using Gosling or a gosling JSON spec as python dicts
-
height:
number -
exportButton:
boolean, whether to include the export button in the gosling component -
eventType:
string, one of 'mouseOver', 'click', and 'rangeSelect'. If specified, the event data of the specified mouse event will be returned by the streamlit-gosling component. -
api: Call an api function of the gosling visualization. Three types of api actions are currently supported.
{ action: "zoomTo", viewId: string, position: string, padding?: number, duration?: number }{ action: "zoomToExtent", viewId: string, duration?: number}{ action: "zoomToGene", viewId: string, gene: string, padding?: number, duration?: number }
example
import streamlit as st from streamlit_gosling as st_gos # user select a chromosome using streamlit select box chr = st.select('zoom to a chromosome', [str(i) for i in range(1, 20)]) # the visaulization will zoom to different chromosome based on users' selection above st_gos.from_gos( spec=/****/, id='id', height=350, api={'action': 'zoomTo','viewId': 'track-1', 'position': f'chr{chr}'} )
Development
Make sure _RELEASE = False in streamlit_gosling/init.py
Install
- JS side
cd streamlit_gosling/frontend
npm install
- Python side
conda create -n streamlit-gosling python=3.9
conda activate streamlit-gosling
pip install -e .
Run
You need to run both the JS side and the Python side for development mode.
- JS side
cd frontend
npm run start
- Python side
streamlit run streamlit_gosling/__init__.py
Test Before Publish to PYPI
-
set
_RELEASE = Truein init.py -
check the version number in setup.py
-
run
. publish-script.sh -
answer
yesfor uploading to test.pypi for testing.twinewill prompt you for a username and password. For the username, use__token__. For the password, use API token. -
download and test
pip install --index-url https://test.pypi.org/simple/ --no-deps streamlit-gosling
Metadata
Release files for streamlit-gosling 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit-gosling-0.1.4.tar.gz | 5.5 MB | Without provenance | Details for streamlit-gosling-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_gosling-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for streamlit_gosling-0.1.4-py3-none-any.whl |
Total release size: 11.0 MB
Release files / streamlit-gosling-0.1.4.tar.gz
| Download URL | streamlit-gosling-0.1.4.tar.gz |
|---|---|
| Size | 5.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f1fce89524b6566b931174be52d01afdfa7c33b40665023d7493507312d7367
|
|
BLAKE2b-256 checksum How to use checksums |
b14d07f870fd7d4ed882399defeb64c564b8fdf85c492125860fae9338f8d151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / streamlit_gosling-0.1.4-py3-none-any.whl
| Download URL | streamlit_gosling-0.1.4-py3-none-any.whl |
|---|---|
| Size | 5.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa5984e327c358c38098a51ed98da1572e40356b5ab11ef1e1378c64a4adadeb
|
|
BLAKE2b-256 checksum How to use checksums |
4e002a3fa629afe4c4779ceacc4dfe29f60864aeb1f5861464365ca02f66801a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for streamlit-gosling 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.