Skip to content

Instantly share code, notes, and snippets.

View jmuhlich's full-sized avatar

Jeremy Muhlich jmuhlich

  • Harvard Medical School Laboratory of Systems Pharmacology
  • Boston, MA
View GitHub Profile
# requires libtiff command line tools to be installed (tiffinfo/tiffset)
# this is only intended to be run on SVS files from Versa scanners which display as bright pink
# ideally this should be run before importing to OMERO
# the recommended pre-import workflow is:
# 1. Make sure Bio-Formats command line tools are available.
# See https://docs.openmicroscopy.org/bio-formats/latest/users/comlinetools/index.html
# 2. Use "showinf -crop 0,0,512,512" on the SVS file to verify that it is bright pink.
# 3. Back up the SVS file.
# 4. Run this script to update the file in-place ("./svs-fix-colors.sh /path/to/file.svs").
@jmuhlich
jmuhlich / stitch_ashlar.py
Created February 19, 2024 22:16
Example for stitching a fileseries with Ashlar
from ashlar.fileseries import FileSeriesReader
from ashlar.reg import EdgeAligner, Mosaic, PyramidWriter
import numpy as np
import pandas as pd
import skimage.exposure, skimage.filters, skimage.io
import sys
import tifffile
input_tif_path = sys.argv[1]
pattern = "20231124_203726_S1_C902_P99_N99_F{series}.TIF"
@jmuhlich
jmuhlich / o2.conf
Created November 1, 2023 16:08
Nextflow config for O2 (WIP for nf-core shared config)
params {
config_profile_description = 'HMS O2 profile.'
config_profile_contact = 'Jeremy Muhlich'
config_profile_url = 'https://...'
singularity_cache_dir = '/n/groups/lsp/mcmicro/singularity'
}
process {
executor = "slurm"
queue = { task.time < 12.h ? 'short' : task.time < 5.d ? 'medium' : 'long' }
@jmuhlich
jmuhlich / ashlar_strict_stage_path.py
Created October 18, 2023 16:41
Ashlar - stitch a single image, only aligning tiles along the stage path (ignoring other overlaps)
import argparse
from ashlar.reg import EdgeAligner, Mosaic, PyramidWriter
from ashlar.scripts.ashlar import build_reader, HelpFormatter
import networkx as nx
parser = argparse.ArgumentParser(
description='Stitch one multi-tile image with strict stage path following',
formatter_class=HelpFormatter,
)
parser.add_argument(
import argparse
from ashlar import reg, transform
import ashlar.scripts.ashlar as ascript
from magicgui import magicgui
import napari
import numpy as np
import skimage
import sys
from typing import List
@jmuhlich
jmuhlich / bib2yaml.py
Created October 27, 2022 15:25
Quick script to convert .bib bibtex to yaml (in no particular schema)
import bibtexparser
from pylatexenc.latex2text import LatexNodes2Text
import sys
import yaml
lt = LatexNodes2Text()
with open(sys.argv[1]) as f:
db = bibtexparser.load(f)
for e in db.entries:
@jmuhlich
jmuhlich / ome-tiff-set-resolution.py
Created September 12, 2022 17:01
Set physical pixel dimensions in an OME-TIFF
# usage: ome-tiff-set-resolution.py [-h] image size
#
# Set physical pixel dimensions in an OME-TIFF
#
# positional arguments:
# image OME-TIFF file to modify
# size pixel width in microns
#
# optional arguments:
# -h, --help show this help message and exit
import sys
import re
import importlib
import time
from pysb.simulator import ScipyOdeSimulator
import pysb.bng
import numpy as np
def benchmark(model, sim_kwargs):
@jmuhlich
jmuhlich / blocker.sh
Created August 25, 2020 17:37
PySB asyncio solution for communicating with BNG
#!/bin/bash
echo "start"
for ((i=1; i<=32000; i++)); do
echo "STDERR $i" >&2
done
echo "normal 1"
sleep 1
for ((i=1; i<=32000; i++)); do
echo "STDERR $i" >&2
@jmuhlich
jmuhlich / ometiff-channel-names.py
Created April 22, 2020 21:42
ometiff-channel-names.py
import sys
import io
import warnings
import xml.etree.ElementTree
import tifffile
if len(sys.argv) != 2:
print(f"Usage: ometiff-channel-names.py input.ome.tif")
print("Print the channel names for the first image in an OME-TIFF file.")
sys.exit(1)