Skip to content

Instantly share code, notes, and snippets.

View ilkayisik's full-sized avatar

Ilkay Isik ilkayisik

View GitHub Profile
@ilkayisik
ilkayisik / fsleyes_visualize_map
Last active March 16, 2020 14:25
fsleyes command to overlay statistical maps and anatomical with defined threshold and colormap
root=xxx
subj=01
path_to_anatomical=${root}/fmriprep/sub-${subj}/anat/sub-${subj}_T1w_preproc.nii.gz
path_to_1stmap=${root}/analysis/sub-${subj}/video/betaseries/inT1/level_2.gfeat_old/cope1.feat/stats/zstat2.nii.gz
path_to_2nd_map=${root}/analysis/sub-${subj}/video/betaseries/inT1/level_2.gfeat/cope1.feat/stats/zstat2.nii.gz
fsleyes ${path_to_anatomical} \
${path_to_1stmap} -dr 3 8 -cm blue \
${path_to_2nd_map} -dr 3 8 -cm red
@ilkayisik
ilkayisik / tksurfer_visualize_maps.sh
Last active April 16, 2019 10:19
freesurfer command to visualize surface and statistical maps using tksurfer with defined thresholds
sub=sub-01
hemi=rh
tksurfer ${sub} ${hemi} inflated -gray \
-overlay path_to_map.mgh \
-overlay path_to_2nd_map.mgh \
-fthresh 2.3 -truncphaseflag 1 -fmid 3.3 -fslope 1 -annot aparc.annot &
@ilkayisik
ilkayisik / freeview_visualize_output.sh
Last active April 30, 2019 13:05
freesurfer command to visualize the surface and the volume with defined edge colors
root=path/to/root
cd $root
sub=sub-01
freeview -v \
$sub/mri/T1.mgz \
$sub/mri/wm.mgz \
$sub/mri/brainmask.mgz \
$sub/mri/aseg.mgz:colormap=lut:opacity=0.2 \
-f \
$sub/surf/lh.white:edgecolor=blue \
@ilkayisik
ilkayisik / nibabel_extract_one_volume.py
Created April 16, 2019 09:36
extract the first volume of nifti file for every participant
from glob import glob
import nibabel as nib
import numpy as np
root='path'
subject_ids = [s[-6:] for s in sorted(glob(root + 'sub-*'))] # to get subject ids in format sub-01
# load the functional files for every participant
funcs = sorted(glob(root+'fmriprep/sub-*/func/sub-*_task-x_run-01_bold_space-MNI152NLin2009cAsym_preproc.nii.gz'))
@ilkayisik
ilkayisik / apply_ants_transform.py
Created April 16, 2019 15:48
T1w to MNI transformation with ANTS apply transforms
from nipype.interfaces.ants import ApplyTransforms
# necessary files
norm_template = root + '/derivatives/mni152_bet.nii'
ants_transforms = sorted(glob(root + 'derivatives/fmriprep/sub-*/anat/sub-*_T1w_target-MNI152NLin2009cAsym_warp.h5'))
# files to transform from T1w to MNI
copes = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/cope1.nii.gz'))
# loop and transform files for all participants
@ilkayisik
ilkayisik / volume2surface.sh
Last active May 9, 2019 13:49
Map volume (.nii) files to surface (.mgh) using mrivol2surf command from freesurfer
bash_root=/Users/ilkay.isik/project_folder_temp/fc_content/MRI_data/lscp_data/derivatives
# simple version
for hemi in lh rh; do
src_file=${bash_root}/analysis/video/odata_prmtc_inMNI/level_2.gfeat/cope3.feat/thresh_zstat1.nii.gz
src_name=${src_file##*/} # take everything after the last /
out_file=${bash_root}/analysis/video/odata_prmtc_inMNI/level_2.gfeat/cope3.feat/${hemi}_${src_name%.nii*}.mgh #remove .nii.gz
echo ${src_file} ${out_file}
@ilkayisik
ilkayisik / find_text_pattern.sh
Created April 21, 2019 11:56
search a directory with subdirectories and find if a pattern exists in listed files
for FILENAME in $(find /Users/ilkay.isik/git/ilkayisik.github.io -type f) ; do
echo $FILENAME
if grep -q isik "$FILENAME"; then
echo "isik is found"
fi
done
@ilkayisik
ilkayisik / label2vol.sh
Created April 23, 2019 13:48
transform labels drawn on the surface to volume space
# if temp is mgz then use --identity as the reg method
bash_root=/Users/ilkay.isik/project_folder_temp/fc_content/MRI_data/lscp_data/derivatives
mri_label2vol --subject sub-01 --hemi rh \
--identity \
--label ${bash_root}/path/ffa.label \
--temp ${bash_root}/freesurfer/sub-01/mri/orig.mgz \
--fillthresh .3 --proj frac 0 1 .2 \
--o ${bash_root}/path/ffa_label.nii
# if temp is t1w then use -reg and provide reg file as the reg method
@ilkayisik
ilkayisik / nibabel_basic_operations.py
Created April 27, 2019 18:32
load, create and save nifti image with nibabel
from nibabel import load, save, Nifti1Image
# load main image
nii_path = path_to_nii_file
zmap = load(nii_path)
img_data = zmap.get_data()
# load anothor image to mask
mask_path = path_to_mask
mask = load(mask_path)
for s in range(nr_sub):
sub = 'sub-{}'.format(str(s+1).zfill(2))