diff --git a/.gitignore b/.gitignore index 0a520cc8..3d4e000d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,11 @@ test/data/derivatives/.snakemake/ test/data/derivatives/config/ test/data/derivatives/.snakebids + +# Tar files +*.tar + +# Ignore files that are available in tar +**/zona_bb_subcortex/MNI152 +**/zona_bb_subcortex/MNI2009b +**/zona_bb_subcortex/transforms diff --git a/dbsc/config/snakebids.yml b/dbsc/config/snakebids.yml index b3e50a1f..a40c43ff 100644 --- a/dbsc/config/snakebids.yml +++ b/dbsc/config/snakebids.yml @@ -153,23 +153,21 @@ parse_args: # Workflow specific config # Spaces available (MNI152, MNINlin2009bAsym) -Space: MNI152 +Space: MNI152NLin6Asym zona_bb_subcortex: - MNI152: - dir: 'resources/MNI152' - T1w: 'resources/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_T1w.nii.gz' - seg: 'resources/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_ZonaBBSubCorSeg.nii.gz' - exclude: 'resources/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_desc-exclude_ROI.nii.gz' - MNI2009: - dir: 'resources/MNI2009b' - T1w: 'resources/MNI2009b/sub-SNSX32NLin2020Asym_space-MNI152_T1w.nii.gz' - seg: 'resources/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_ZonaBBSubCorSeg.nii.gz' - exclude: 'resources/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_desc-exclude_ROI.nii.gz' + tsv: 'resources/zona_bb_subcortex/desc-ZonaBBSubcor_dseg.tsv' + MNI152NLin6Asym: + dir: 'resources/zona_bb_subcortex/MNI152NLin6Asym/' + T1w: 'tpl-MNI152NLin6Asym_res-04_desc-brain_T1w.nii.gz' + seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBBSubcor_dseg.nii.gz' + MNI152NLin2009bAsym: + dir: 'resources/zona_bb_subcortex/MNI152NLin2009bAsym/' + seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBBSubcor_dseg.nii.gz' # NOTE: This may not be needed with labelmerge freesurfer: - labels: 'resources/freesurfer/fs_labels.csv' + tsv: 'resources/freesurfer/desc-FreesurferThal_dseg.tsv' # Containers # NOTE: Update from latest to use specific tags @@ -177,5 +175,6 @@ singularity: freesurfer: "docker://pwighton/freesurfer:7.2.0" neuroglia-core: "docker://khanlab/neuroglia-core:latest" mrtrix: "docker://brainlife/mrtrix:3.0.3" + labelmerge: "docker://kaitj/labelmerge:v0.1.0" fs_license: /path/to/fs/license diff --git a/dbsc/resources/freesurfer/desc-FreesurferThal_dseg.tsv b/dbsc/resources/freesurfer/desc-FreesurferThal_dseg.tsv new file mode 100644 index 00000000..707b7517 --- /dev/null +++ b/dbsc/resources/freesurfer/desc-FreesurferThal_dseg.tsv @@ -0,0 +1,53 @@ +index name +8108 Left LD +8208 Right LD +8109 Left LGN +8209 Right LGN +8115 Left MGN +8215 Right MGN +8121 Left PuI +8221 Right PuI +8123 Left PuM +8223 Right PuM +8111 Left L-Sg +8211 Right L-Sg +8133 Left VPL +8233 Right VPL +8106 Left CM +8206 Right CM +8128 Left VLa +8228 Right VLa +8120 Left PuA +8220 Right PuA +8113 Left MDm +8213 Right MDm +8118 Left Pf +8218 Right Pf +8127 Left VAmc +8227 Right VAmc +8112 Left MDl +8212 Right MDl +8104 Left CeM +8204 Right CeM +8126 Left VA +8226 Right VA +8116 Left MV(Re) +8216 Right MV(Re) +8125 Left R +8225 Right R +8130 Left VM +8230 Right VM +8105 Left CL +8205 Right CL +8122 Left PuL +8222 Right PuL +8119 Left Pt +8219 Right Pt +8103 Left AV +8203 Right AV +8117 Left Pc +8217 Right Pc +8129 Left VLp +8229 Right VLp +8110 Left LP +8210 Right LP diff --git a/dbsc/resources/freesurfer/fs_labels.csv b/dbsc/resources/freesurfer/fs_labels.csv deleted file mode 100644 index ccad61e0..00000000 --- a/dbsc/resources/freesurfer/fs_labels.csv +++ /dev/null @@ -1,51 +0,0 @@ -# Label, Hemi, Nuclei -8109, Left, LGN -8209, Right, LGN -8115, Left, MGN -8215, Right, MGN -8121, Left, PuI -8221, Right, PuI -8123, Left, PuM -8223, Right, PuM -8111, Left, L-Sg -8211, Right, L-Sg -8133, Left, VPL -8233, Right, VPL -8106, Left, CM -8206, Right, CM -8128, Left, VLa -8228, Right, VLa -8120, Left, PuA -8220, Right, PuA -8113, Left, MDm -8213, Right, MDm -8118, Left, Pf -8218, Right, Pf -8127, Left, VAmc -8227, Right, VAmc -8112, Left, MDl -8212, Right, MDl -8104, Left, CeM -8204, Right, CeM -8126, Left, VA -8226, Right, VA -8116, Left, MV(Re) -8216, Right, MV(Re) -8125, Left, R -8225, Right, R -8130, Left, VM -8230, Right, VM -8105, Left, CL -8205, Right, CL -8122, Left, PuL -8222, Right, PuL -8119, Left, Pt -8219, Right, Pt -8103, Left, AV -8203, Right, AV -8117, Left, Pc -8217, Right, Pc -8129, Left, VLp -8229, Right, VLp -8110, Left, LP -8210, Right, LP \ No newline at end of file diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_desc-exclude_ROI.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_desc-exclude_ROI.nii.gz deleted file mode 100644 index 8da866e6..00000000 Binary files a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_desc-exclude_ROI.nii.gz and /dev/null differ diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_ZonaBBSubCorSeg.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBBSubcor_dseg.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_ZonaBBSubCorSeg.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBBSubcor_dseg.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-fct_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-fct_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-fct_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-fct_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-fl_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-fl_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-fl_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-fl_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-ft_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-ft_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-ft_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-ft_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-hfields_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-hfields_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-L_desc-hfields_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-L_desc-hfields_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-fct_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-fct_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-fct_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-fct_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-fl_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-fl_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-fl_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-fl_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-ft_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-ft_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-ft_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-ft_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-hfields_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-hfields_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_hemi-R_desc-hfields_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_hemi-R_desc-hfields_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_ZonaBBSubCorSeg.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBBSubcor_dseg.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_ZonaBBSubCorSeg.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBBSubcor_dseg.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_hemi-L_desc-fct_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-fct_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32NLin2020Asym_space-MNI152_hemi-L_desc-fct_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-fct_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-L_desc-fl_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-fl_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-L_desc-fl_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-fl_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-L_desc-ft_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-ft_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-L_desc-ft_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-ft_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-L_desc-hfields_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-hfields_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-L_desc-hfields_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-L_desc-hfields_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-fct_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-fct_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-fct_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-fct_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-fl_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-fl_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-fl_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-fl_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-ft_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-ft_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-ft_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-ft_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-hfields_mask.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-hfields_mask.nii.gz similarity index 100% rename from dbsc/resources/zona_bb_subcortex/MNI152/sub-SNSX32Nlin2020Asym_space-MNI152_hemi-R_desc-hfields_mask.nii.gz rename to dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_hemi-R_desc-hfields_mask.nii.gz diff --git a/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-04_desc-brain_T1w.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-04_desc-brain_T1w.nii.gz new file mode 100644 index 00000000..c2628b86 Binary files /dev/null and b/dbsc/resources/zona_bb_subcortex/MNI152NLin6Asym/tpl-MNI152NLin6Asym_res-04_desc-brain_T1w.nii.gz differ diff --git a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_desc-exclude_ROI.nii.gz b/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_desc-exclude_ROI.nii.gz deleted file mode 100644 index ef7f4e9a..00000000 Binary files a/dbsc/resources/zona_bb_subcortex/MNI2009b/sub-SNSX32NLin2020Asym_space-MNINlin2009bAsym_desc-exclude_ROI.nii.gz and /dev/null differ diff --git a/dbsc/resources/zona_bb_subcortex/desc-ZonaBBSubcor_dseg.tsv b/dbsc/resources/zona_bb_subcortex/desc-ZonaBBSubcor_dseg.tsv new file mode 100644 index 00000000..a7391497 --- /dev/null +++ b/dbsc/resources/zona_bb_subcortex/desc-ZonaBBSubcor_dseg.tsv @@ -0,0 +1,25 @@ +index name +1 Left RN +2 Right RN +3 Left SN +4 Right SN +5 Left STn +6 Right STn +7 Left Caudate +8 Right Caudate +9 Left Putamen +10 Right Putamen +11 Left GPe +12 Right GPe +13 Left GPi +14 Right GPi +15 Left Thalamus +16 Right Thalalmus +17 Left Hippocampus +18 Right Hippocampus +19 Left NAc +20 Right NAc +21 Left Amygdala +22 Right Amygdala +23 Left ZI +24 Right ZI diff --git a/dbsc/resources/zona_bb_subcortex/subcortical-labels.csv b/dbsc/resources/zona_bb_subcortex/subcortical-labels.csv deleted file mode 100644 index 196f7a94..00000000 --- a/dbsc/resources/zona_bb_subcortex/subcortical-labels.csv +++ /dev/null @@ -1,73 +0,0 @@ -Label,Hemi,Nuclei,Abbrev -1,left,left red nucleus,L RN -2,right,right red nucleus,R RN -3,left,left substantia nigra,L SN -4,right,right substantia nigra,R SN -5,left,left subthalamic nucleus,L STN -6,right,right subthalamic nucleus,R STN -7,left,left caudate,L Cau -8,right,right caudate,R Cau -9,left,left putamen,L Put -10,right,right putamen,R Put -11,left,left globus pallidus externa,L GPe -12,right,right globus pallidus externa,R GPe -13,left,left globus pallidus interna,L GPi -14,right,right globus pallidus Interna,R GPi -15,left,left hippocampus,L Hipp -16,right,right hippocampus,R Hipp -17,left,left nucleus accumbens,L NAc -18,right,right nucleus accumbens,R NAc -19,left,left amygdala,L Amy -20,right,right amygdala,R Amy -21,left,left zona incerta,L ZI -22,right,right zona incerta,R ZI -23,left,left thalamus lateral geniculate,L Thal LGN -24,right,right thalamus lateral geniculate,R Thal LGN -25,left,left thalamus medial geniculate,R Thal MGN -26,right,right thalamus medial geniculate,R Thal MGN -27,left,left thalamus pulvinar inferior,L Thal PuI -28,right,right thalamus pulvinar inferior,R Thal PuI -29,left,left thalamus pulvinar medial,L Thal PuM -30,right,right thalamus pulvinar medial,R Thal PuM -31,left,left thalamus limitans suprageniculate,L Thal L-Sg -32,right,right thalamus limitans suprageniculate,R Thal L-Sg -33,left,left thalamus ventral posterolateral,L Thal VPL -34,right,right thalamus ventral posterolateral,R Thal VPL -35,left,left thalamus centromedian,L Thal CM -36,right,right thalamus centromedian,R Thal CM -37,left,left thalamus ventral lateral anterior,L Thal VLa -38,right,right thalamus ventral lateral anterior,R Thal VLa -39,left,left thalamus pulvinar anterior,L Thal PuA -40,right,right thalamus pulvinar anterior,R Thal PuA -41,left,left thalamus mediodorsal medial magnocellular,L Thal MDm -42,right,right thalamus mediodorsal medial magnocellular,R Thal MDm -43,left,left thalamus parafascicular,L Thal Pf -44,right,right thalamus parafascicular,R Thal Pf -45,left,left thalamus ventral anterior magnocellular,L Thal VAmc -46,right,right thalamus ventral anterior magnocellular,R Thal VAmc -47,left,left thalamus mediodorsal lateral parvocellular,L Thal MDl -48,right,right thalamus mediodorsal lateral parvocellular,R Thal MDl -49,left,left thalamus central medial,L Thal CeM -50,right,right thalamus central medial,R Thal CeM -51,left,left thalamus ventral anterior,L Thal VA -52,right,right thalamus ventral anterior,R Thal VA -53,left,left thalamus reuniiens medial ventral,L Thal MV(Re) -54,right,right thalamus reuniens medial ventral,R Thal MV(Re) -55,left,left thalamus reticular,L Thal R -56,right,right thalamus reticular,R Thal R -57,left,left thalamus ventromedial,L Thal VM -58,right,right thalamus ventromedial,R Thal VM -59,left,left thalamus central lateral,L Thal CL -60,right,right thalamus central lateral,R Thal CL -61,left,left thalamus pulvinar lateral,L Thal PuL -62,right,right thalamus pulvinar lateral,R Thal PuL -63,left,left thalamus paratenial,L Thal Pt -64,right,right thalamus paratenial,R Thal Pt -65,left,left thalamus anteroventral,L Thal AV -66,right,right thalamus anteroventral,R Thal AV -67,left,left thalamus paracentral,L Thal Pc -68,right,right thalamus paracentral,R Thal Pc -69,left,left thalamus ventral lateral posterior,L Thal VLp -70,right,right thalamus ventral lateral posterior,R Thal VLp -71,left,left thalamus lateral posterior,L Thal LP -72,right,right thalamus lateral posterior,R Thal LP diff --git a/dbsc/workflow/Snakefile b/dbsc/workflow/Snakefile index c7122b8c..477936d5 100644 --- a/dbsc/workflow/Snakefile +++ b/dbsc/workflow/Snakefile @@ -42,7 +42,9 @@ include: "rules/mrtpipelines.smk" rule all: input: - expand( + files=expand( rules.filtered_tck2connectome.output.sl_assignment, subject=config["input_lists"]["T1w"]["subject"], ), + fs_tsv=rules.cp_fs_tsv.output.fs_tsv, + zona_tsv=rules.cp_zona_tsv.output.zona_tsv, diff --git a/dbsc/workflow/rules/freesurfer.smk b/dbsc/workflow/rules/freesurfer.smk index c490976f..b35a1460 100644 --- a/dbsc/workflow/rules/freesurfer.smk +++ b/dbsc/workflow/rules/freesurfer.smk @@ -15,6 +15,22 @@ bids_fs_out = partial( # B. Fischl, A. van der Kouwe, C. Destrieux, E. Halgren, F. Ségonne, D.H. Salat, E. Busa, L.J. Seidman, J. Goldstein, D. Kennedy, V. Caviness, N. Makris, B. Rosen, A.M. Dale. Automatically parcellating the human cerebral cortex. Cereb. Cortex, 14 (2004), pp. 11-22, 10.1093/cercor/bhg087 +rule cp_fs_tsv: + """Copy tsv to freesurfer dir + """ + input: + fs_tsv=str( + Path(workflow.basedir).parent / Path(config["freesurfer"]["tsv"]) + ), + output: + fs_tsv=expand( + "{freesurfer_dir}/desc-FreesurferThal_dseg.tsv", + freesurfer_dir=freesurfer_dir, + ), + shell: + "cp -v {input.fs_tsv} {output.fs_tsv}" + + rule thalamic_segmentation: """Perform thalamus segmentation diff --git a/dbsc/workflow/rules/mrtpipelines.smk b/dbsc/workflow/rules/mrtpipelines.smk index f3f4b274..ce406366 100644 --- a/dbsc/workflow/rules/mrtpipelines.smk +++ b/dbsc/workflow/rules/mrtpipelines.smk @@ -140,6 +140,7 @@ rule dwi2response: rule responsemean: """Compute average response function""" + # DOUBLE CHECK input: subject_rf=expand( bids_response_out( @@ -317,7 +318,7 @@ rule tckgen: mask=rules.nii2mif.output.mask, cortical_ribbon=rules.fs_xfm_to_native.output.ribbon, convex_hull=rules.create_convex_hull.output.convex_hull, - subcortical_seg=rules.add_brainstem_new_seg.output.seg, + subcortical_seg=rules.add_brainstem.output.mask, params: step=config["step"], sl=config["sl_count"], @@ -367,7 +368,7 @@ rule tck2connectome: input: weights=rules.tcksift2.output.weights, tck=rules.tckgen.output.tck, - subcortical_seg=rules.add_brainstem_new_seg.output.seg, + subcortical_seg=rules.add_brainstem.output.mask, params: radius=config["radial_search"], output: @@ -417,11 +418,9 @@ rule connectome2tck: "connectome2tck -nthreads {threads} -nodes {params.nodes} -exclusive -filters_per_edge -tck_weights_in {input.node_weights} -prefix_tck_weights_out {output.edge_weight} {input.tck} {input.sl_assignment} {output.edge_tck} " -# NOTE: Use labelmerge split segs here? rule create_roi_mask: - # EXPAND OVER NODE1 IN RULE ALL input: - subcortical_seg=rules.add_brainstem_new_seg.output.seg, + subcortical_seg=rules.add_brainstem.output.mask, output: roi_mask=temp( bids_anat_out( @@ -450,7 +449,7 @@ rule create_exclude_mask: ), lZI=bids_anat_out(desc="21", suffix="mask.mif"), rZI=bids_anat_out(desc="22", suffix="mask.mif"), - subcortical_seg=rules.add_brainstem_new_seg.output.seg, + subcortical_seg=rules.add_brainstem.output.mask, output: filter_mask=temp( bids_anat_out( @@ -472,7 +471,7 @@ rule filter_tck: filter_mask=rules.create_exclude_mask.output.filter_mask, tck=rules.connectome2tck.output.edge_tck, weights=rules.tck2connectome.output.node_weights, - subcortical_seg=rules.add_brainstem_new_seg.output.seg, + subcortical_seg=rules.add_brainstem.output.mask, output: filtered_tck=temp( bids_tractography_out( @@ -537,7 +536,7 @@ rule filtered_tck2connectome: input: weights=rules.combine_filtered.output.combined_weights, tck=rules.combine_filtered.output.combined_tck, - subcortical_seg=rules.add_brainstem_new_seg.output.seg, + subcortical_seg=rules.add_brainstem.output.mask, params: radius=config["radial_search"], output: diff --git a/dbsc/workflow/rules/zona_bb_subcortex.smk b/dbsc/workflow/rules/zona_bb_subcortex.smk index 7bb161e8..1b9f80c8 100644 --- a/dbsc/workflow/rules/zona_bb_subcortex.smk +++ b/dbsc/workflow/rules/zona_bb_subcortex.smk @@ -1,5 +1,6 @@ # Directories zona_dir = str(Path(config["output_dir"]) / "zona_bb_subcortex") +labelmerge_dir = str(Path(config["output_dir"]) / "labelmerge") # Make directory if it doesn't exist Path(zona_dir).mkdir(parents=True, exist_ok=True) @@ -7,7 +8,17 @@ Path(zona_dir).mkdir(parents=True, exist_ok=True) # BIDS partials bids_anat = partial( - bids, root=zona_dir, datatype="anat", **config["subj_wildcards"] + bids, + root=zona_dir, + datatype="anat", + **config["subj_wildcards"], +) + +bids_labelmerge = partial( + bids, + root=labelmerge_dir, + datatype="anat", + **config["subj_wildcards"], ) # References: @@ -16,15 +27,30 @@ bids_anat = partial( # Y. Xiao, J.C. Lau, T. Anderson, J. DeKraker, D.L. Collins, T. Peters, A.R. Khan. An accurate registration of the BigBrain dataset with the MNI PD25 and ICBM152 atlases. Sci. Data, 6 (2019), p. 210, 10.1038/s41597-019-0217-0 +rule cp_zona_tsv: + """Copy tsv to zona dir""" + input: + zona_tsv=str( + Path(workflow.basedir).parent + / Path(config["zona_bb_subcortex"]["tsv"]) + ), + output: + zona_tsv=f"{zona_dir}/desc-ZonaBBSubcor_dseg.tsv", + shell: + "cp -v {input.zona_tsv} {output.zona_tsv}" + + rule xfm2native: - """Transform from Zona template space to subject native space""" + """Transform from subcortical parcellations from chosen template space to subject native space""" input: seg=str( Path(workflow.basedir).parent + / Path(config["zona_bb_subcortex"][config["Space"]]["dir"]) / Path(config["zona_bb_subcortex"][config["Space"]]["seg"]) ), seg_anat=str( Path(workflow.basedir).parent + / Path(config["zona_bb_subcortex"][config["Space"]]["dir"]) / Path(config["zona_bb_subcortex"][config["Space"]]["T1w"]) ), ref=config["input_path"]["T1w"], @@ -45,193 +71,152 @@ rule xfm2native: "applywarp --rel --interp=nn -i {input.seg} -r {input.ref} -w {output.xfm} -o {output.nii}" -rule binarize: - input: - nii=rules.xfm2native.output.nii, - output: - mask=bids_anat( - space="T1w", - desc="ZonaBB", - suffix="mask.nii.gz", - ), - container: - config["singularity"]["neuroglia-core"] - shell: - "fslmaths {input.nii} -bin {output.mask}" - - -rule add_brainstem: - input: - binarize=rules.binarize.output.mask, - aparcaseg=rules.fs_xfm_to_native.output.aparcaseg, - output: - binarize=bids_anat( - space="T1w", - desc="ZonaBBStem", - suffix="mask.nii.gz", - ), - container: - config["singularity"]["neuroglia-core"] - shell: - "fslmaths {input.aparcaseg} -thr 16 -uthr 16 -bin -max {input.binarize} {output.binarize}" +# TODO: Add back later on +# rule xfm_zona_rois: +# input: +# mask=str( +# Path(config["zona_bb_subcortex"][config["Space"]]["dir"]) +# / f'sub-SNSX32Nlin2020Asym_space-{config["Space"]}_hemi-{{hemi}}_desc-{{struct}}_mask.nii.gz' +# ), +# ref=rules.xfm2native.input.ref, +# xfm=rules.xfm2native.output.xfm, +# output: +# mask=bids( +# root=zona_dir, +# datatype="anat", +# space="T1w", +# hemi="{{hemi,(L|R)}}", +# desc="{{struct,(fct|ft|fl|hfields)}}", +# suffix="mask.nii.gz", +# ), +# container: +# config["singularity"]["neuroglia-core"] +# shell: +# "applywarp --rel --interp=nn -i {input.mask} -r {input.ref} -w {input.xfm} -o {output.mask}" -rule xfm_zona_rois: - input: - mask=str( - Path(config["zona_bb_subcortex"][config["Space"]]["dir"]) - / f'sub-SNSX32Nlin2020Asym_space-{config["Space"]}_hemi-{{hemi}}_desc-{{struct}}_mask.nii.gz' - ), - ref=rules.xfm2native.input.ref, - xfm=rules.xfm2native.output.xfm, - output: - mask=bids( - root=zona_dir, - datatype="anat", - space="T1w", - hemi="{{hemi,(L|R)}}", - desc="{{struct,(fct|ft|fl|hfields)}}", - suffix="mask.nii.gz", - ), - container: - config["singularity"]["neuroglia-core"] - shell: - "applywarp --rel --interp=nn -i {input.mask} -r {input.ref} -w {input.xfm} -o {output.mask}" - - -# Everything in the block below should be replaced by labelmerge -###################################################################### rule rm_bb_thal: - """Removes existing thalamus""" + """Removes thalamus from existing parcellation + + 1. Grab labels following thalamus ROI + 2. Remove existing thalamus from segmentation + 3. Add labels following thalamus ROI back to segmentation + """ input: - seg=rules.fs_xfm_to_native.output.thal, + seg=rules.xfm2native.output.nii, output: - seg=bids( - root=zona_dir, - datatype="anat", + seg=bids_anat( space="T1w", - desc="ZonaBBNoThal", - suffix="seg.nii.gz", - **config["subj_wildcards"], + desc="ZonaBBSubcor", + suffix="dseg.nii.gz", ), non_thal=temp( - bids( - root=zona_dir, - datatype="anat", + bids_anat( space="T1w", desc="NonThal", - suffix="seg.nii.gz", - **config["subj_wildcards"], + suffix="dseg.nii.gz", ) ), rm_seg=temp( - bids( - root=zona_dir, - datatype="anat", + bids_anat( space="T1w", - desc="rm", - suffix="seg.nii.gz", - **config["subj_wildcards"], + desc="ThalPost", + suffix="dseg.nii.gz", ) ), container: config["singularity"]["neuroglia-core"] shell: - "fslmaths {input.seg} -sub 2 {output.non_thal} " - "fslmaths {output.non_thal} -thr 15 {output.non_thal} " - "fslmaths {input.seg} -thr 15 {output.rm_seg} " - "fslmaths {input.seg} -sub {output.rm_seg} {output.seg}" + "fslmaths {input.seg} -sub 2 {output.non_thal} && " + "fslmaths {output.non_thal} -thr 15 {output.non_thal} && " + "fslmaths {input.seg} -thr 15 {output.rm_seg} && " + "fslmaths {input.seg} -sub {output.rm_seg} {output.seg} && " "fslmaths {output.seg} -add {output.non_thal} {output.seg}" -rule add_new_thal: +rule labelmerge: input: - aparcaseg=rules.add_brainstem.input.aparcaseg, - labels=str( - Path(workflow.basedir).parent - / Path(config["freesurfer"]["labels"]) - ), - thal=rules.fs_xfm_to_native.output.thal, - seg=rules.rm_bb_thal.output.rm_seg, + seg=expand( + bids_anat( + subject="{subject}", + space="T1w", + desc="ZonaBBSubcor", + suffix="dseg.nii.gz", + ), + subject=config["input_lists"]["dwi"]["subject"], + ), + params: + zona_dir=zona_dir, + fs_dir=str(Path(config["output_dir"]) / "freesurfer"), + zona_desc="ZonaBBSubcor", + fs_desc="FreesurferThal", + labelmerge_dir=directory(labelmerge_dir), + labelmerge_container=config["singularity"]["labelmerge"], output: - seg=bids( - root=zona_dir, - datatype="anat", - space="T1w", - desc="ZonaBBFSThal", - suffix="seg.nii.gz", - **config["subj_wildcards"], - ), - label=temp( - bids( - root=zona_dir, - datatype="anat", + seg=expand( + bids_labelmerge( + subject="{subject}", space="T1w", - suffix="label.nii.gz", - **config["subj_wildcards"], - ) + desc="combined", + suffix="dseg.nii.gz", + ), + subject=config["input_lists"]["dwi"]["subject"], + ), + tsv=expand( + bids_labelmerge( + subject="{subject}", + space="T1w", + desc="combined", + suffix="dseg.tsv", + ), + subject=config["input_lists"]["dwi"]["subject"], ), - container: - config["singularity"]["neuroglia-core"] shell: - "labelIdx=23 " - "cp {input.seg} {output.seg} " - 'while IFS=, read -r label hemi nuclei || [ -n "$label" ]; do ' - ' if [ "$label" = "# Label" ]; then ' - " continue " - " fi " - " fslmaths {input.thal} -thr $label -uthr $label -bin {output.label} " - " fslmaths {output.label} -mul $labelIdx {output.label} " - " fslmaths {output.seg} -max {output.label} {output.seg} " - " labelIdx=$((labelIdx+1)) " - " done < {input.labels}" - - -rule bin_new_seg: + "singularity run {params.labelmerge_container} {params.zona_dir} {params.labelmerge_dir} --base_desc {params.zona_desc} --overlay_bids_dir {params.fs_dir} --overlay_desc {params.fs_desc} -c1" + + +rule binarize: input: - seg=rules.add_new_thal.output.seg, + seg=bids_labelmerge( + space="T1w", + desc="combined", + suffix="dseg.nii.gz", + ), output: - seg=bids( - root=zona_dir, - datatype="anat", + mask=bids_labelmerge( space="T1w", - desc="ZonaBBFSThal", - suffix="seg_bin.nii.gz", - **config["subj_wildcards"], + desc="combined", + suffix="mask.nii.gz", ), container: config["singularity"]["neuroglia-core"] shell: - "fslmaths {input.seg} -bin {output.seg}" + "fslmaths {input.seg} -bin {output.mask}" -rule add_brainstem_new_seg: +rule add_brainstem: input: - seg=rules.bin_new_seg.output.seg, - aparcaseg=rules.add_brainstem.input.aparcaseg, + mask=rules.binarize.output.mask, + aparcaseg=rules.fs_xfm_to_native.output.aparcaseg, output: - seg=bids( - root=zona_dir, - datatype="anat", + mask=bids_anat( + root=labelmerge_dir, space="T1w", - desc="ZonaBBFSThalStem", - suffix="seg_bin.nii.gz", - **config["subj_wildcards"], + desc="labelmergeStem", + suffix="mask.nii.gz", ), container: config["singularity"]["neuroglia-core"] shell: - "fslmaths {input.aparcaseg} -thr 16 -uthr 16 -bin -max {input.seg} {output.seg}" - - -###################BLOCK TO REPLACE WITH LABELMERGE############################ + "fslmaths {input.aparcaseg} -thr 16 -uthr 16 -bin -max {input.mask} {output.mask}" rule create_convex_hull: input: - bin_seg=rules.add_brainstem_new_seg.output.seg, + bin_seg=rules.add_brainstem.output.mask, output: convex_hull=bids_anat( + root=labelmerge_dir, space="T1w", desc="ConvexHull", suffix="mask.nii.gz", diff --git a/dbsc/workflow/scripts/zona_bb_subcortex/convexHull_roi b/dbsc/workflow/scripts/zona_bb_subcortex/convexHull_roi deleted file mode 100755 index d025c059..00000000 --- a/dbsc/workflow/scripts/zona_bb_subcortex/convexHull_roi +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/env python -def get_parser(): - """ - Argument parser - """ - from argparse import ArgumentParser, RawTextHelpFormatter - - parser = ArgumentParser(description="Convex hull of nifti", - formatter_class=RawTextHelpFormatter) - - # Required args - g_req = parser.add_argument_group("Required arguments") - g_req.add_argument("subj", action="store", - help="Subject ID") - g_req.add_argument("in_dir", action="store", - help="Path to parent input directory (BIDS) containing binary image to create convex hull") - - return parser - -def main(): - """ - Entry point of code - """ - import os - import nibabel as nib - import numpy as np - import scipy.spatial - - args = get_parser().parse_args() - - # Data paths - in_file = f"{os.path.realpath(args.in_dir)}/{args.subj}/anat/{args.subj}_space-T1w_desc-ZonaBBSubCorSeg_bin.nii.gz" - out_file = f"{os.path.realpath(args.in_dir)}/{args.subj}/anat/{args.subj}_space-T1w_desc-ZonaBBSegHull_bin.nii.gz" - - # Load input - print("Loading data...") - in_img = nib.load(in_file) - in_affine = in_img.affine - in_data = in_img.get_fdata() - - # Compute convex hull - print("Computing convex hull...") - points = np.transpose(np.where(in_data)) - hull = scipy.spatial.ConvexHull(points) - deln = scipy.spatial.Delaunay(points[hull.vertices]) - idx = np.stack(np.indices(in_data.shape), axis=-1) - out_idx = np.nonzero(deln.find_simplex(idx) + 1) - out_img = np.ones(in_data.shape) - out_img[out_idx] = 0 - - # Save convex hull - print("Saving convex hull...") - out_hull = nib.Nifti1Image(out_img, in_affine) - nib.save(out_hull, out_file) - - -if __name__ == "__main__": - main() diff --git a/dbsc/resources/zona_bb_subcortex/convexHull_roi.py b/dbsc/workflow/scripts/zona_bb_subcortex/convexHull_roi.py old mode 100755 new mode 100644 similarity index 100% rename from dbsc/resources/zona_bb_subcortex/convexHull_roi.py rename to dbsc/workflow/scripts/zona_bb_subcortex/convexHull_roi.py