No project description provided
Project description
chromospyce
This is an anywidget-powered version of the chromospace library intended for use in computational notebooks, such as Jupyter Notebook.
Basic usage
The available functionality is pretty limited at this moment. We will stabilize the API as we go. At this point, you can display 3D chromatin models.
import random
import chromospyce
import numpy as np
import pyarrow as pa
BINS_NUM = 1000
def make_random_3D_chromatin_structure(n):
position = np.array([0.0, 0.0, 0.0])
positions = [position.copy()]
x_arr = []
y_arr = []
z_arr = []
for _ in range(n):
step = np.random.choice([-1.0, 0.0, 1.0], size=3) # Randomly choose to move left, right, up, down, forward, or backward
position += step
positions.append(position.copy())
x_arr.append(position[0])
y_arr.append(position[1])
z_arr.append(position[2])
return [x_arr, y_arr, z_arr]
# Step 1: Generate random structure and convert from arrays to
# Apache Arrow table with 3 columns: 'x', 'y', 'z'
random_structure = make_random_3D_chromatin_structure(BINS_NUM)
table = pa.Table.from_arrays(random_structure, names=["x", "y", "z"])
# Convert the Table to bytes
output_stream = pa.BufferOutputStream()
with pa.ipc.RecordBatchStreamWriter(output_stream, table.schema) as writer:
writer.write_table(table)
table_bytes = output_stream.getvalue().to_pybytes()
# Step 2: Display the structure in a chromospyce widget
numbers = list(range(1, BINS_NUM+1))
vc = {
"color": {
"values": numbers,
"min": 1,
"max": BINS_NUM,
"colorScale": "Spectral"
},
# "color": "#6600ff", # alternatively
"scale": 0.01,
"links": True,
"mark": "sphere"
}
chromospyce.Widget(structure=table_bytes, viewconfig=vc)
This example is currently a bit verbose to showcase the code for converting data from Python arrays to an Apache Arrow table. Read more about why Apache Arrow is the only format supported by chromospace/chromospyce.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file chromospyce-0.0.5.tar.gz
.
File metadata
- Download URL: chromospyce-0.0.5.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ed530e82cbb5035cba3949de4ddc3d771941f5143456d9953cbe9724f6ceead |
|
MD5 | 2ab0e7fccec267dc5383940162ad1408 |
|
BLAKE2b-256 | 489e7295106aac7202854d114d3e7944aefcfc7c25c30db140a68b8ce831c095 |
File details
Details for the file chromospyce-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: chromospyce-0.0.5-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd28c89be6b3268095c3230293c335c2c1cc139baed85584bfc25290fd645487 |
|
MD5 | 79a316075e6594de9cc8dd30426a1198 |
|
BLAKE2b-256 | 5235b87a2c53c338b1e62d7bf78c95927bce611bb0485e8b50d21d73cbae2c7f |