Skip to content

Instantly share code, notes, and snippets.

View grst's full-sized avatar

Gregor Sturm grst

View GitHub Profile
@grst
grst / pl.py
Created September 6, 2023 14:37
from functools import partial
import math
from typing import Literal
from datashader.mpl_ext import dsshow, alpha_colormap
import datashader as ds
from joblib import parallel_backend
from mpl_toolkits.axes_grid1 import ImageGrid
import matplotlib.pyplot as plt
import pandas as pd
import scanpy as sc
@grst
grst / squidpy_get_bbox.py
Created August 2, 2023 13:31
Get bounding box for squidpy spatial plot to be equivalent to the scanpy.pl.spatial
def get_bbox(adata, library_id, *, library_key="sample", img_key="hires", margin=50):
adata = adata[adata.obs[library_key] == library_id, :]
coords = adata.obsm["spatial"]
scale_factor = adata.uns["spatial"][library_id]["scalefactors"][f"tissue_{img_key}_scalef"]
return tuple(
np.array(
[
np.min(coords[:, 0]) - margin,
np.min(coords[:, 1]) - margin,
np.max(coords[:, 0]) + margin,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
"""
Query GitHub API for the status of the GitHub actions runs associated
with a commit.
Requirements: `pygithub`, the rest is standard lib.
"""
from github import Github
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@grst
grst / jupyter-nextflow-plugin.md
Created October 26, 2020 13:32
draft of nextflow/notebook integration

jupyter nextflow plugin

It would be great to have a tighter integration with jupyter notebooks/Rmd notebooks.

See also Reportsrender v2 / Executable book project Reportsrender v2.

Parametrization with papermill/rmarkdown works, but is quite a bit of overhead. It should be possible to execute the notebooks from outside the pipeline (for development) and from within the pipeline using the results from the previous processes (in production)

@grst
grst / zettlr-multi-instance.md
Last active June 23, 2020 14:58
Run multiple instances of zettlr

It is currently not possible to run multiple instances of Zettlr (Zettlr/Zettlr#243).

As a workaround, I managed to run multiple instances of zettlr side-by-side by running them as different users.

For me this seems to work reasonably well, but this can lead to corruption of your settings or your notes -- Use at own risk.

Setup

# create a new user
@grst
grst / layout.py
Last active March 26, 2020 07:36
Layout graphs with many disconnected components using python-igraph. - Adapted from https://stackoverflow.com/questions/53120739/lots-of-edges-on-a-graph-plot-in-python
import igraph as ig
import numpy as np
from itertools import combinations
def layout_components(
graph: ig.Graph,
component_layout: str = "fr",
arrange_boxes: str = "dense",
pad_x: float = 1.0,
pad_y: float = 1.0,
@grst
grst / ipynb.html
Last active October 16, 2019 09:32
pandoc toc from ipynb example files
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>test</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}