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 / 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]+"
@akhanf
akhanf / snakemake_remotebatch
Created April 21, 2020 13:06
batch submission script
#!/bin/bash
hours=6
mem=128000
gpus=1
cpus=32
if [ "$#" -lt 2 ]
then
echo "Usage $0 RULE_NAME NUM_BATCHES <optional snakemake args>"