Skip to content

Instantly share code, notes, and snippets.

View ivirshup's full-sized avatar
💭
🫠

Isaac Virshup ivirshup

💭
🫠
View GitHub Profile
@ivirshup
ivirshup / simple_ooc_concat.py
Created March 9, 2023 15:21
Simple OOC concat for anndata
import zarr
import pandas as pd, numpy as np
from anndata.experimental import read_elem, write_elem
from anndata._core.sparse_dataset import SparseDataset
def _df_index(df: zarr.Group) -> np.ndarray:
index_key = df.attrs["_index"]
return read_elem(df[index_key])
@ivirshup
ivirshup / virtual_concatenate.py
Last active March 2, 2023 18:40
h5py virtual dataset with uneven chunk size
# Docs: https://docs.h5py.org/en/stable/vds.html
import h5py
import numpy as np
def virtual_concatenate(datasets: list[h5py.Dataset]) -> h5py.VirtualLayout:
"""Concatenate datasets along the first axis."""
vds = h5py.VirtualLayout(shape=sum(d.shape[0] for d in datasets), dtype=datasets[0].dtype)
offset = 0
for d in datasets:
@ivirshup
ivirshup / polygons_on_points.py
Last active February 24, 2023 12:26
spatial aggregations w polygons
import pandas as pd
import geopandas as gpd
import numpy as np
from scipy import sparse
import anndata as ad
def aggregate_polygons_on_points(
polygons: gpd.GeoDataFrame,
points: gpd.GeoDataFrame,
point_id_column: str,
@ivirshup
ivirshup / transcript_models.py
Last active February 13, 2023 15:55
Getting the transcript models out of the bioconductor ensdb tables and turning them into an awkward array
import ibis
import awkward as ak
!wget https://bioconductorhubs.blob.core.windows.net/annotationhub/AHEnsDbs/v108/EnsDb.Hsapiens.v108.sqlite
connection = ibis.sqlite.connect("EnsDb.Hsapiens.v108.sqlite")
gene = connection.table("gene")
tx = connection.table("tx")
tx2exon = connection.table("tx2exon")
@ivirshup
ivirshup / mmap_csr_sparse.ipynb
Last active November 8, 2022 10:50
Example code for reading from a memory mapped sparse array
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivirshup
ivirshup / scverse-core_github-dependents.ipynb
Last active October 10, 2022 18:22
Notebook for getting scverse core packages dependents from github
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivirshup
ivirshup / scverse-core_pypi-dependents.ipynb
Created October 10, 2022 17:56
Notebook for getting scverse core packages pypi dependents from wheelodex
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivirshup
ivirshup / anndata_dask_df.py
Created September 2, 2022 14:07
anndata dataframe -> dask with columnar support
import copy
import dask.dataframe as dd
import dask.array as da
import dask
from dask.base import tokenize
from dask.dataframe.io.io import from_map
import pandas as pd, numpy as np, zarr
@ivirshup
ivirshup / jsscatter-citeseq.ipynb
Created May 24, 2022 13:29
jupyter-scatter + citeseq example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ivirshup
ivirshup / dependents.ipynb
Created May 11, 2022 14:27
Dependents of scverse packages
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.