Generate Masks from cortical labels, subcortical aseg, or atlases


In [1]:
import os.path as op

Create subject masks from fsaverage label


In [ ]:
%%bash 
sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt

for hemi in lh rh
    do
    make_masks.py -s $sub_list -roi $hemi.17Networks_5 \
    -label 17Networks_5 -sample graymid -hemi $hemi -debug -unsmoothed
    done

Create masks from aseg ROI


In [7]:
%%bash 
sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt

for hemi in lh rh
    do
    make_masks.py -s $sub_list -roi $hemi.perirhinal \
    -aseg -id 222 -native -hemi $hemi -debug -unsmoothed
    done


Process is terminated.

Create subject maks from label & contrast


In [10]:
%%bash 
sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt

for hemi in lh rh
    do
    make_masks.py -s $sub_list -roi $hemi.spl-hit-miss \
    -native -label superiorparietal -sample graymid -hemi $hemi -debug -smoothed \
    -exp objfam-submem -contrast hit-miss -thresh 2
    done


Processing type: fsaverage_label
Setting up for 1 subjects
Experiment name: objfam-studyrep_hpf256
ROI name: lh.fusiform-study_rep
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-studyrep_hpf256/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-studyrep_hpf256/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/lh.fusiform-study_rep.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpZINWJ9
Processing type: fsaverage_label
Setting up for 1 subjects
Experiment name: objfam-studyrep_hpf256
ROI name: rh.fusiform-study_rep
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-studyrep_hpf256/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-studyrep_hpf256/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/rh.fusiform-study_rep.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpDBESyQ

In [5]:
%%bash 
sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt

for hemi in lh rh
    do
    make_masks.py -s $sub_list -roi $hemi.hit-miss \
    -label 17Networks_5 \
    -sample graymid -hemi $hemi -debug -unsmoothed \
    -exp objfam-submem_nuisance_comb -contrast hit-miss -thresh 2
    done


Processing type: fsaverage_label
Setting up for 1 subjects
Experiment name: objfam-submem_nuisance_comb
ROI name: lh.hit-miss
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-submem_nuisance_comb/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-submem_nuisance_comb/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/lh.hit-miss.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpfKyj2f
Processing type: fsaverage_label
Setting up for 1 subjects
Experiment name: objfam-submem_nuisance_comb
ROI name: rh.hit-miss
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-submem_nuisance_comb/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-submem_nuisance_comb/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/rh.hit-miss.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpgnpPG0

Make labels from annot


In [2]:
%%bash 

for subjid in 150; do

mri_annotation2label --subject ap$subjid --hemi rh --outdir /Volumes/group/awagner/sgagnon/AP/data/ap$subjid/label
mri_annotation2label --subject ap$subjid --hemi lh --outdir /Volumes/group/awagner/sgagnon/AP/data/ap$subjid/label

done


subject = ap150
annotation = aparc
hemi = rh
outdir = /Volumes/group/awagner/sgagnon/AP/data/ap150/label
surface   = white

Reading surface 
 /Volumes/group/awagner/sgagnon/AP/data/ap150/surf/rh.white
Loading annotations from /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.aparc.annot
Seg base 2000
max index = 35
  1   1357 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.bankssts.label
  2   1560 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.caudalanteriorcingulate.label
  3   3643 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.caudalmiddlefrontal.label
  5   2543 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.cuneus.label
  6    562 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.entorhinal.label
  7   5141 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.fusiform.label
  8  10095 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.inferiorparietal.label
  9   5090 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.inferiortemporal.label
 10   1810 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.isthmuscingulate.label
 11   8793 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.lateraloccipital.label
 12   4412 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.lateralorbitofrontal.label
 13   4564 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.lingual.label
 14   2825 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.medialorbitofrontal.label
 15   6000 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.middletemporal.label
 16    941 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.parahippocampal.label
 17   2291 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.paracentral.label
 18   2477 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.parsopercularis.label
 19   1356 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.parsorbitalis.label
 20   2819 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.parstriangularis.label
 21   2266 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.pericalcarine.label
 22   6771 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.postcentral.label
 23   1947 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.posteriorcingulate.label
 24   8054 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.precentral.label
 25   6359 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.precuneus.label
 26   1428 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.rostralanteriorcingulate.label
 27   9485 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.rostralmiddlefrontal.label
 28  11965 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.superiorfrontal.label
 29   8965 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.superiorparietal.label
 30   6430 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.superiortemporal.label
 31   7266 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.supramarginal.label
 32    469 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.frontalpole.label
 33    454 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.temporalpole.label
 34    479 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.transversetemporal.label
 35   3489 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/rh.insula.label
subject = ap150
annotation = aparc
hemi = lh
outdir = /Volumes/group/awagner/sgagnon/AP/data/ap150/label
surface   = white

Reading surface 
 /Volumes/group/awagner/sgagnon/AP/data/ap150/surf/lh.white
Loading annotations from /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.aparc.annot
Seg base 1000
max index = 35
  1   1579 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.bankssts.label
  2   1632 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.caudalanteriorcingulate.label
  3   4229 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.caudalmiddlefrontal.label
  5   2481 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.cuneus.label
  6    622 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.entorhinal.label
  7   5337 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.fusiform.label
  8   8261 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.inferiorparietal.label
  9   5666 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.inferiortemporal.label
 10   1639 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.isthmuscingulate.label
 11   8645 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.lateraloccipital.label
 12   3927 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.lateralorbitofrontal.label
 13   4109 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.lingual.label
 14   2946 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.medialorbitofrontal.label
 15   5147 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.middletemporal.label
 16    833 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.parahippocampal.label
 17   2315 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.paracentral.label
 18   3222 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.parsopercularis.label
 19   1011 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.parsorbitalis.label
 20   2596 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.parstriangularis.label
 21   2037 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.pericalcarine.label
 22   6324 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.postcentral.label
 23   1677 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.posteriorcingulate.label
 24   7429 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.precentral.label
 25   5759 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.precuneus.label
 26   1625 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.rostralanteriorcingulate.label
 27   9025 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.rostralmiddlefrontal.label
 28  11775 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.superiorfrontal.label
 29   9815 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.superiorparietal.label
 30   6962 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.superiortemporal.label
 31   6349 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.supramarginal.label
 32    305 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.frontalpole.label
 33    732 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.temporalpole.label
 34    727 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.transversetemporal.label
 35   3532 /Volumes/group/awagner/sgagnon/AP/data/ap150/label/lh.insula.label
reading colortable from annotation file...
colortable with 36 entries read (originally /autofs/space/terrier_001/users/nicks/freesurfer/average/colortable_desikan_killiany.txt)
reading colortable from annotation file...
colortable with 36 entries read (originally /autofs/space/terrier_001/users/nicks/freesurfer/average/colortable_desikan_killiany.txt)

Make masks from subject label

Both hemis separately


In [2]:
%%bash 
sub_list=/Volumes/group/awagner/sgagnon/AP/scripts/subjects.txt

for hemi in lh rh
    do
    make_masks.py -s $sub_list -roi $hemi.parahippocampal -exp mvpa \
    -label parahippocampal -native -sample graymid -hemi $hemi -debug -unsmoothed
    done


Processing type: native_label
Setting up for 1 subjects
Experiment name: mvpa
ROI name: lh.parahippocampal
Set to run in serial
EPI template: /Volumes/group/awagner/sgagnon/AP/analysis/mvpa/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Volumes/group/awagner/sgagnon/AP/analysis/mvpa/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Volumes/group/awagner/sgagnon/AP/data/%(subj)s/masks/lh.parahippocampal.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpdZvHMC
Processing type: native_label
Setting up for 1 subjects
Experiment name: mvpa
ROI name: rh.parahippocampal
Set to run in serial
EPI template: /Volumes/group/awagner/sgagnon/AP/analysis/mvpa/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Volumes/group/awagner/sgagnon/AP/analysis/mvpa/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Volumes/group/awagner/sgagnon/AP/data/%(subj)s/masks/rh.parahippocampal.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpdrgbTR

Bilateral


In [5]:
%%bash 
#sub_list=/Volumes/group/awagner/sgagnon/AP/scripts/subjects.txt
sub_list=ap150

make_masks.py -s $sub_list -roi bilat-fusiform -exp mvpa \
    -label fusiform -native -sample graymid -debug -unsmoothed


Processing type: native_label
Setting up for 1 subjects
Experiment name: mvpa
ROI name: bilat-fusiform
Set to run in serial
EPI template: /Volumes/group/awagner/sgagnon/AP/analysis/mvpa/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Volumes/group/awagner/sgagnon/AP/analysis/mvpa/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Volumes/group/awagner/sgagnon/AP/data/%(subj)s/masks/bilat-fusiform.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpKbWqKW

Combine masks


In [7]:
%%bash
sub_list=/Volumes/group/awagner/sgagnon/AP/scripts/subjects.txt
fs_dir=/Volumes/group/awagner/sgagnon/AP/data

IFS=, 
while read subid
do
    echo $subid
    
    mask_path=$fs_dir/$subid/masks
    
    fslmaths $mask_path/bilat-parahippocampal.nii.gz \
    -add $mask_path/bilat-fusiform.nii.gz \
    -add $mask_path/bilat-inferiortemporal.nii.gz \
    -bin $mask_path/bilat-parahipp_fusi_inftemp.nii.gz
    
done < $sub_list


ap100
ap101
ap102
ap103
ap104
ap150

In [ ]:

Create subject masks from fsaverage label


In [9]:
%%bash 
sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt

for hemi in lh rh
    do
    make_masks.py -s $sub_list -hemi $hemi -roi $hemi.perirhinal -label perirhinal -sample graymid -debug -unsmoothed
    done


Processing type: fsaverage_label
Setting up for 1 subjects
Experiment name: None
ROI name: lh.perirhinal
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/lh.perirhinal.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmp67x9bt
Processing type: fsaverage_label
Setting up for 1 subjects
Experiment name: None
ROI name: rh.perirhinal
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/rh.perirhinal.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpiATNWC

Convert fsaverage annotations to fsaverage labels


In [49]:
%%bash

mri_annotation2label --annotation aparc --hemi rh --subject fsaverage --outdir $SUBJECTS_DIR/fsaverage/label
mri_annotation2label --annotation aparc --hemi lh --subject fsaverage --outdir $SUBJECTS_DIR/fsaverage/label


subject = fsaverage
annotation = aparc
hemi = rh
outdir = /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label
surface   = white

Reading surface 
 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/surf/rh.white
Loading annotations from /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.aparc.annot
Seg base 2000
max index = 35
  1   2196 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.bankssts.label
  2   1608 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.caudalanteriorcingulate.label
  3   3494 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.caudalmiddlefrontal.label
  5   1638 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.cuneus.label
  6    902 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.entorhinal.label
  7   4661 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.fusiform.label
  8   9676 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.inferiorparietal.label
  9   4198 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.inferiortemporal.label
 10   2388 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.isthmuscingulate.label
 11   5963 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.lateraloccipital.label
 12   4354 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.lateralorbitofrontal.label
 13   3894 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.lingual.label
 14   2801 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.medialorbitofrontal.label
 15   5057 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.middletemporal.label
 16   1742 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.parahippocampal.label
 17   3831 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.paracentral.label
 18   2472 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.parsopercularis.label
 19    946 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.parsorbitalis.label
 20   2380 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.parstriangularis.label
 21   1823 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.pericalcarine.label
 22   9138 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.postcentral.label
 23   2994 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.posteriorcingulate.label
 24  10705 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.precentral.label
 25   7975 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.precuneus.label
 26   1051 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.rostralanteriorcingulate.label
 27   7864 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.rostralmiddlefrontal.label
 28  11878 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.superiorfrontal.label
 29  10222 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.superiorparietal.label
 30   6868 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.superiortemporal.label
 31   8150 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.supramarginal.label
 32    369 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.frontalpole.label
 33    817 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.temporalpole.label
 34    781 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.transversetemporal.label
 35   5090 /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label/rh.insula.label
reading colortable from annotation file...
colortable with 36 entries read (originally /autofs/space/terrier_001/users/nicks/freesurfer/average/colortable_desikan_killiany.txt)

Bilateral Hippocampal ROI


In [55]:
%%bash 
sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt

make_masks.py -s $sub_list -roi Bilat-Hippocampus \
    -aseg -id 17 53 -debug -unsmoothed


Processing type: index_volume
Setting up for 1 subjects
Experiment name: None
ROI name: Bilat-Hippocampus
Set to run in serial
EPI template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam/%(subj)s/preproc/run_1/mean_func.nii.gz
Reg template: /Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam/%(subj)s/preproc/run_1/func2anat_tkreg.dat
Output template: /Users/steph-backup/Experiments/ObjFam/data/%(subj)s/masks/Bilat-Hippocampus.nii.gz
Debug mode: not removing output directory:
/var/folders/xp/71y4c8j51293syxqsgb7qsz40000gp/T/tmpRP3kD9

Atlas-based ROIs


In [36]:
jeulich_locations = dict(hIP1_lh=1,
                         hIP1_rh=2,
                         hIP2_lh=3,
                         hIP2_rh=4,
                         hIP3_lh=5,
                         hIP3_rh=6)

atlas_path = '/usr/local/fsl/data/atlases/Juelich'

In [37]:
op.join(atlas_path, 'Juelich-maxprob-thr0-2mm.nii.gz')


Out[37]:
'/usr/local/fsl/data/atlases/Juelich/Juelich-maxprob-thr0-2mm.nii.gz'

In [9]:
atlas_path = '/usr/local/fsl/data/atlases/HarvardOxford'
harvardoxford_locations = dict(SMG_ant = 19, 
                               SMG_post = 20,
                               LO_supp = 22,
                               parahipp_post = 35,
                               parahipp_ant = 34,
                               occ_fusiform = 40,
                               temp_occ_fusiform = 39,
                               temp_fusiform_ant = 37,
                               temp_fusiform_post = 38)

In [12]:
harvardoxford_locations['parahipp_ant']


Out[12]:
34

In [16]:
op.join(atlas_path, 'HarvardOxford-cort-maxprob-thr0-2mm.nii.gz')


Out[16]:
'/usr/local/fsl/data/atlases/HarvardOxford/HarvardOxford-cort-maxprob-thr0-2mm.nii.gz'

Create mask from atlas


In [43]:
%%bash 

fslmaths '/usr/local/fsl/data/atlases/Juelich/Juelich-maxprob-thr0-2mm.nii.gz' -thr 6 -uthr 6 '/Users/steph-backup/Experiments/ObjFam/data/fsaverage/masks/hIP3_rh'

Intersection of 2 masks


In [25]:
%%bash 

sub_list=~/Experiments/ObjFam/data/subids_subset_no23or19.txt
mask1=17Networks_5.nii.gz
mask2=lateraloccipital.nii.gz
output=17Networks_5_LO.nii.gz

while read sub; do
    subj_mask_dir='/Users/steph-backup/Experiments/ObjFam/data/'$sub'/masks/'
    echo $subj_mask_dir
    
    for hemi in lh rh; do
        fslmaths $subj_mask_dir$hemi.$mask2 -mas $subj_mask_dir$hemi.$mask1 $subj_mask_dir$hemi.$output
    done
    
done < $sub_list


/Users/steph-backup/Experiments/ObjFam/data/subj03/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj04/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj05/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj06/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj07/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj08/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj09/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj10/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj11/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj12/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj13/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj15/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj16/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj17/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj20/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj21/masks/
/Users/steph-backup/Experiments/ObjFam/data/subj24/masks/

In [26]:
%%bash 

sub=subj25
mask1=17Networks_5.nii.gz
mask2=lateraloccipital.nii.gz
output=17Networks_5_LO.nii.gz

subj_mask_dir='/Users/steph-backup/Experiments/ObjFam/data/'$sub'/masks/'
echo $subj_mask_dir

for hemi in lh rh; do
    fslmaths $subj_mask_dir$hemi.$mask2 -mas $subj_mask_dir$hemi.$mask1 $subj_mask_dir$hemi.$output
done


/Users/steph-backup/Experiments/ObjFam/data/subj25/masks/

Create mask from group contrast (MNI space)


In [44]:
experiment = 'objfam-studyrep'
contrast_name = 'linear-study'
filepath = op.join('/Users/steph-backup/Experiments/ObjFam/scripts/analysis/', 
                   experiment, 'group', 'mni', contrast_name, 
                   'zstat1_threshold.nii.gz')
print filepath

outpath = op.join('/Users/steph-backup/Experiments/ObjFam/data/fsaverage/masks/',
                  'studyrep_linear-study')
print outpath


/Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-studyrep/group/mni/linear-study/zstat1_threshold.nii.gz
/Users/steph-backup/Experiments/ObjFam/data/fsaverage/masks/studyrep_linear-study

In [46]:
%%bash

fslmaths '/Users/steph-backup/Experiments/ObjFam/scripts/analysis/objfam-studyrep/group/mni/linear-study/zstat1_threshold.nii.gz' -thr 0 '/Users/steph-backup/Experiments/ObjFam/data/fsaverage/masks/studyrep_linear-study'

Reverse a mask


In [55]:
%%bash
mask_input=$SUBJECTS_DIR/fsaverage/masks/ventral_topdown.nii.gz
mask_output=$SUBJECTS_DIR/fsaverage/masks/ventral_topdown_inv.nii.gz

fslmaths $mask_input -mul -1 -add 1 $mask_output

Convert ALE map to FSL MNI space

Intersection of 2 masks


In [56]:
%%bash
mask1=$SUBJECTS_DIR/fsaverage/masks/topdown_ALE_pN05.nii
mask2=$SUBJECTS_DIR/fsaverage/masks/ventral_topdown_inv.nii.gz
intersect_mask=$SUBJECTS_DIR/fsaverage/masks/topdown_ALE_ventral_inv.nii.gz

fslmaths $mask1 -mas $mask2 $intersect_mask

SPM MNI to FSL fsaverage space


In [57]:
%%bash
mask_toconvert=$SUBJECTS_DIR/fsaverage/masks/topdown_ALE_ventral_inv.nii.gz
mask_output=$SUBJECTS_DIR/fsaverage/masks/topdownALEventral_inv_fslMNI.nii
#mask_toconvert=$SUBJECTS_DIR/fsaverage/masks/topdown_ALE_pN05.nii

flirt -in $mask_toconvert -ref $FSLDIR/data/standard/MNI152_T1_2mm -applyxfm -usesqform -out $mask_output

Threshold mask


In [58]:
%%bash
#input=$SUBJECTS_DIR/fsaverage/masks/topdownALEventral_fslMNI.nii
#output=$SUBJECTS_DIR/fsaverage/masks/topdownALEventral_fslMNI_thresh.nii.gz
input=$SUBJECTS_DIR/fsaverage/masks/topdownALEventral_inv_fslMNI.nii
output=$SUBJECTS_DIR/fsaverage/masks/topdownALEventral_inv_fslMNI_thresh.nii

fslmaths $input -thr 0 -bin $output

Fsaverage mask to native space


In [ ]:
%%bash

mystruct=fsl.Info.standard_image("avg152T1_brain.nii.gz")
warps_into_MNI_space=warpfield.nii.gz
warp_mni2native=warp_mni2native.nii.gz
file_to_invwarp=topdown.nii.gz
outfile=topdown_native.nii.gz


invwarp --ref=$my_struct --warp=$warps_into_MNI_space --out=$warp_mni2native
applywarp --ref=$my_struct --in=$file_to_invwarp --warp=$warp_mni2native --out=$outfile --interp=nn

In [ ]:

Group contrast threshold in fsaverage space


In [51]:
%%bash
input=~/Experiments/ObjFam/scripts/analysis/objfam-submem_nuisance_comb/group/mni/hit-miss/zstat1_threshold.nii.gz
output=$SUBJECTS_DIR/fsaverage/masks/hit-miss_thresh.nii.gz

fslmaths $input -thr 0 -bin $output

In [ ]:
%%bash
input=~/Experiments/ObjFam/scripts/analysis/objfam-submem_nuisance_comb/group/mni/hit-miss/zstat1_threshold.nii.gz
output=$SUBJECTS_DIR/fsaverage/masks/hit-miss_thresh.nii.gz

fslmaths $input -thr 0 -bin $output

Create union of 2 fsaverage labels


In [53]:
%%bash
curr_dir=`pwd`
cd /Users/steph-backup/Experiments/ObjFam/data/fsaverage/label

label1=rh.17Networks_5.label
label2=rh.superiorparietal.label
output=rh.Network5_SPL.label

./labels_union.sh $label1 $label2 $output

In [ ]: