Skip to content

Instantly share code, notes, and snippets.

View akhanf's full-sized avatar

Ali Khan akhanf

  • London, Ontario
View GitHub Profile
@akhanf
akhanf / add_to_napari.py
Created April 30, 2025 16:30
napari ome zarr cvpl_tools
import zarr
group = zarr.open_group('/home/UWO/akhan488/graham/lightsheet/test_eed/SPIMprep/bids/sub-M1A1Te3/micr/sub-M1A1Te3_sample-brain_acq-imaris_SPIM.ome.zarr.zip',mode='r')
from cvpl_tools.ome_zarr.napari.add import group as add_group
add_group(viewer=viewer,zarr_group=group,merge_channels=False)
@akhanf
akhanf / osfplus.sh
Created April 28, 2025 01:38
enhancement wrapper for osfcli
#!/usr/bin/env bash
set -euo pipefail
shopt -s expand_aliases
alias osf='uvx --from osfclient osf'
CACHE_DIR=".osfcli.cache"
CACHE_FILE="${CACHE_DIR}/filelist.txt"
CACHE_TTL=3600
@akhanf
akhanf / native_surf.smk
Created March 6, 2025 18:12
unfold screenshot hippunfold
rule screenshot_unfold:
input:
surf_gii=bids(
root=work,
datatype="surf",
suffix="midthickness.surf.gii",
desc="nostruct",
space="unfold",
hemi="{hemi}",
@akhanf
akhanf / Snakefile
Created September 23, 2023 14:56
Simple Snakefile for turning QC snapshots into GIF animations and PDF flipbooks - this example is for snakeanat but can be easily customized by changing the input paths.
subjects,=glob_wildcards('sub-{subject}/qc.html')
print(subjects)
snaps,=glob_wildcards(f'sub-{subjects[0]}/{{snap}}.png')
print(snaps)
rule all:
input:
expand('{ext}s/{snap}.{ext}',ext=['gif','pdf'],snap=snaps)
@akhanf
akhanf / example_calc_surf_metrics.py
Created September 28, 2022 21:07
Hippunfold - calculating mean surface metrics over subfields
import nibabel as nib
subjects = ['01']
hemis = ['L','R']
subfield_labels={1:'Sub',2:'CA1',3:'CA2',4:'CA3',5:'CA4'}
hipp_metrics = ['thickness','gyrification']
dentate_metrics = ['gyrification']
with open('table.csv','w') as f:
@akhanf
akhanf / Snakefile
Created May 3, 2022 16:43
simple snakebids with glob_wildcards
from snakebids.utils.snakemake_io import glob_wildcards
configfile: 'config.yml'
subject,session,task = glob_wildcards(config['bold'])
print(subject)
print(session)
print(task)
@akhanf
akhanf / Snakefile
Created November 19, 2021 19:55
snakebids-batch
bids_dir: '/path/to/bids_dir'
output_dir: '/path/to/output_dir'
#enable printing debug statements during parsing -- disable if generating dag visualization
debug: False
derivatives: False #will search in bids/derivatives if True; can also be path(s) to derivatives datasets
#list of analysis levels in the bids app
analysis_levels: &analysis_levels
@akhanf
akhanf / bids.smk
Created June 24, 2020 14:55
Helper function for generating bids paths for snakemake workflows
def bids (root=None, prefix=None, suffix=None, subject=None, session=None,include_subject_dir=True,include_session_dir=True,**entities):
"""Helper function for generating bids paths for snakemake workflows
File path is of the form:
[root]/[sub-{subject}]/[ses-{session]/[prefix]_[sub-{subject}]_[ses-{session}]_[{key}-{val}_ ... ]_[suffix]
root -- root folder to include in the path (e.g. 'results'))
prefix -- string to prepend to the file name (typically not defined, unless you want tpl-{tpl}, or a subfolder)
suffix -- bids suffix including extension (e.g. 'T1w.nii.gz')
@akhanf
akhanf / Snakefile
Created May 21, 2020 12:42
Sample Snakefile for MDT
from os.path import join
configfile: 'config.yml'
container: config['container']
rule create_protocol:
input:
bvec = join(config['in_dir'],config['bvec']),
@akhanf
akhanf / snakemake_iterative_template
Last active October 2, 2020 23:52
Example of recipe for iteratively building a template using recursion (view graph with: snakemake -np --dag | dot | display)
input_images = ['A','B','C']
shell('touch {input_images}')
max_iters = 4
#need this to make sure iterations don't go below 0!
wildcard_constraints:
iteration="[0-9]+"