Skip to content

Instantly share code, notes, and snippets.

@czarrar
czarrar / landmarker.py
Created February 4, 2017 18:20
Converting Landmarker JSON <=> PTS
from menpo.shape import PointCloud
from menpo.shape import PointDirectedGraph
from menpo.shape import bounding_box
import json
def read_landmarker_pts(fname):
# Note: It's in this order!
#old_order = ['chin', 'left-eye', 'right-eye', 'left-eyebrow', 'nose', 'right-eyebrow', 'outer-mouth', 'inner-mouth']
face_parts = {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@czarrar
czarrar / write_gav2csv.m
Last active August 29, 2015 14:19
Convert grand average file generated by mipgav4 into multiple csv files. Please note that you will also need the `csvwrite_with_headers` (if you don't already have it). It can be found here: http://www.mathworks.com/matlabcentral/fileexchange/29933-csv-with-column-headers/content/csvwrite_with_headers.m.
function write_gav2csv(infile, outprefix, smoothOn)
% WRITE_GAV2CSV Write the grand-average file as a CSV
% write_gav2csv(infile, outfile)
%
% infile : Input grand average file name (e.g., 'myfile.gav')
% outprefix : Prefix to output (e.g., 'myfile'). A separate file will be created corresponding to each bin.
% smoothOn : 0 means no smoothing. 1 [default] = single smoothing. 2 = double smoothing, etc.
%
% Created by Zarrar Shehzad on 2015-04-23.
@czarrar
czarrar / parcel_steps.R
Last active August 29, 2015 14:16
These are the steps to use the rparcellate scripts for spatially constrained parcellation of the brain.
# This script assumes that you have https://github.com/czarrar/rparcellate
# 1. Make sure to create a group mask (in some standard space)
# -- I would recommend using `fslmaths -Tstd -bin` or `fslmaths -Tmin -bin`
# -- Then make sure to mask your group mask by `rparcellate/rois/ho_maxprob25.nii.gz`. This is a special grey-matter mask.
# read in your group mask
suppressMessages(library(niftir))
mask_file <- "/path/to/group_mask.nii.gz"
grp_mask <- read.mask(mask_file)
@czarrar
czarrar / install.R
Last active August 29, 2015 14:15
Guide to loading brain imaging (nifti) data into R
# Installing the niftir package from github
# note: if you have a mac, this package has some open issues so I might recommend using another package (see below)
## Various Dependencies
cat("Installing various dependencies\n")
install.packages(
c("codetools", "foreach", "doMC", "multicore", "getopt", "optparse",
"bigmemory", "biganalytics", "bigmemory.sri")
, repos="http://cran.us.r-project.org")
install.packages(
c("plyr", "Rcpp", "RcppArmadillo", "inline", "devtools"),
@czarrar
czarrar / inline_connectir.R
Last active September 8, 2016 19:22
Runs cluster correction on the output from MDMR analysis using connectir (http://github.com/czarrar/connectir). This can also convert ROI data to voxelwise data.
# This file will be called the `le_correcter.R` file shown below
# and both files must be in the same directory.
# This file contains the low-level functions to find the clusters
# as well as convert ROIs to voxelwise data.
suppressPackageStartupMessages(library(connectir))
suppressPackageStartupMessages(library(inline))
plugin_bigmemory <- function() {
l <- getPlugin("RcppArmadillo")
@czarrar
czarrar / demo.py
Last active August 29, 2015 14:11
Running CWAS with Python
# To use, please install CPAC (CWAS branch) or clone and add this to your path
# git clone https://github.com/FCP-INDI/C-PAC.git
# cd C-PAC
# git checkout cwas
# also see: https://github.com/FCP-INDI/C-PAC/tree/cwas
from CPAC.cwas import calc_cwas
# Load your data
## Create the (`S`,`T`,`V`) dataset to hold everything: `S` subjects, `T` timepoints, `V` voxels
@czarrar
czarrar / mindboggle101_labels.csv
Created August 14, 2014 02:40
CSV file with label ids and names for the mindboggle 101 anatomical atlas.
id group name
1002 cortex left caudal anterior cingulate
1003 cortex left caudal middle frontal
1005 cortex left cuneus
1006 cortex left entorhinal
1007 cortex left fusiform
1008 cortex left inferior parietal
1009 cortex left inferior temporal
1010 cortex left isthmus cingulate
1011 cortex left lateral occipital
@czarrar
czarrar / cpac_centrality.py
Last active August 29, 2015 14:01
Calculates degree centrality using CPAC code
#!/usr/bin/env python
import argparse
import os
from os import path
from CPAC.network_centrality import calc_centrality
###
@czarrar
czarrar / easy_functional_density.py
Last active January 3, 2016 22:29
Do some quick functional density mapping for a sample voxel. Note this code assumes you are running off rocky.
import numpy as np
import os
#from CPAC.network_centrality import load
#from CPAC.cwas.subdist import norm_cols
import nibabel as nib
from scipy.sparse import coo_matrix, cs_graph_components
def load(datafile, template):