{"id":1658,"date":"2014-05-22T23:29:50","date_gmt":"2014-05-22T22:29:50","guid":{"rendered":"http:\/\/pkmital.com\/home\/?p=1658"},"modified":"2023-07-24T13:35:46","modified_gmt":"2023-07-24T20:35:46","slug":"extracting-automatically-labeled-volumetric-rois-from-mri","status":"publish","type":"post","link":"https:\/\/pkmital.com\/home\/extracting-automatically-labeled-volumetric-rois-from-mri\/","title":{"rendered":"Extracting Automatically Labeled Volumetric ROIs from MRI"},"content":{"rendered":"<p>Performing a region of interest analysis on MRI requires knowing where the regions are in your subject data. Typically, this has been done using hand-drawn masks in a 3d viewer. However, recent research has made the process mostly automatic and the open-source community has implemented everything you will need to automatically create labeled volumetric regions of interest [1-3]. With FreeSurfer 5.3, we have the option of performing <a href=\"http:\/\/freesurfer.net\/fswiki\/CorticalParcellation\" target=\"_blank\" rel=\"noopener\">cortical parcellation<\/a> using 4 different atlases:<\/p>\n<p>Destrieux atlas: aparc.a2009s<br \/>\nDesikan-Killiany atlas: aparc<br \/>\nMindboggle: aparc.DKTatlas40<br \/>\nBrodman areas: BA and BA.thresh<\/p>\n<p>We&#8217;ll first use <a href=\"http:\/\/freesurfer.net\/\" target=\"_blank\" rel=\"noopener\">freesurfer&#8217;s<\/a> <a href=\"http:\/\/surfer.nmr.mgh.harvard.edu\/fswiki\/recon-all\"><code>recon-all<\/code><\/a> tool to perform a cortical reconstruction of our anatomical scans. Download freesurfer and <a href=\"https:\/\/surfer.nmr.mgh.harvard.edu\/registration.html\" target=\"_blank\" rel=\"noopener\">register<\/a> your copy. You&#8217;ll be sent an e-mail with a license. Follow the instructions and create the license file &#8220;.license&#8221; inside your freesurfer home directory (check the environment variable, FREESURFER_HOME, e.g., &#8220;<code>$ echo $FREESURFER_HOME\"<\/code>). Then run the script, &#8220;$FREESURFER_HOME\/FreeSurferEnv.sh&#8221; to setup necessary paths.<\/p>\n<p>Next make sure you have set the environment variable for SUBJECTS_DIR to where you&#8217;d like your analysis to go (e.g., &#8220;<code>$ export SUBJECTS_DIR=\/some\/directory<\/code>&#8220;). For our example, we&#8217;ll keep this to a directory called &#8220;freesurfer&#8221; in our home directory, &#8220;~\/&#8221;. Each subject we analyze will have its own folder insider SUBJECTS_DIR (i.e., &#8220;~\/freesurfer&#8221;, for our example), with the name specified by recon-all&#8217;s &#8220;subjid&#8221; parameter. We&#8217;ll come back to that if it doesn&#8217;t make sense yet.<\/p>\n<p>We&#8217;re ready to run <code>recon-all<\/code> now. It can take up to 12 hours on a new machine. Since we have a few subjects, we used our computing cluster to perform the analysis. The cluster we use requires us to submit jobs to a queue using <code>qsub<\/code>. This bash script file will loop through all our subjects and run <code>recon-all<\/code> on each of them using a new &#8220;job&#8221; submitted through <code>qsub<\/code>. Our subject&#8217;s anatomical data is stored in a Nifti file format, &#8220;.nii&#8221;, in the directory ~\/anatomical.<\/p>\n<pre><pre class=\"brush: bash; title: run_freesurfer.sh; notranslate\" title=\"run_freesurfer.sh\">\n# set the environment variable to where our subject data will be stored\nexport SUBJECTS_DIR=~\/freesurfer\n\n# these are the names of the subjects for which we have high-res scans for\ndeclare -a arr=(\"15jul13rr\" \"16jul13ad\" \"17jul13bs\" \"18jul13ys\")\n\n# we are going to use this temporary directory while processing data\nmkdir \/global\/scratch\/pkm\n\n# loop through our subjects\nfor i in \"${arr&#x5B;@]}\"\ndo\n   echo \"$i\"\n\n   # copy the scan to the temp directory\n   datasetlocation=\/global\/scratch\/pkm\/\"$i\"_anat.nii\n   cp ..\/anatomical\/\"$i\"_anat.nii $datasetlocation\n\n   # subject a job with the current subject's file\n   qsub -v subject=$i,location=$datasetlocation run_freesurfer.pbs\ndone\n<\/pre>\n<p>This pbs file is our job script which takes one subject&#8217;s mri data and runs <code>recon-all<\/code> on it.<\/p>\n<pre><pre class=\"brush: bash; title: run_freesurfer.pbs; notranslate\" title=\"run_freesurfer.pbs\">\n#!\/bin\/bash -l\n\n# Name your job (used in the PBS output file names)\n#PBS -N $subject\n\n# request the queue (enter the possible names, if omitted, serial is the default)\n#PBS -q default\n\n# request 1 node and  request 1 processor per node\n#PBS -l nodes=1:ppn=1\n\n# Specify how much time you think the job will run\n#PBS -l walltime=36:00:00\n\n# By default, PBS scripts execute in your home directory, not the\n# directory from which they were submitted. The following line\n# places you in the directory from which the job was submitted.\ncd $PBS_O_WORKDIR\n\n# Set the environment variable again as this is on another machine\nexport SUBJECTS_DIR=~\/freesurfer\n\n# Filename for logging\nfilename=\"$LOGID\"_`date +%Y%m%d-%H%M%S`_freesurfer.log\n\n# Run recon-all\nrecon-all -i $location -subjid $subject -all &amp;amp;amp;amp;&amp;amp;amp;gt; logs\/$filename\n<\/pre>\n<p>If you don&#8217;t have a cluster, the line to perform is simply:<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nrecon-all -i YOUR_NIFTI_DATA.nii -subjid SOME_IDENTIFIER -all\n<\/pre>\n<p>where YOUR_NIFTI_DATA may be something like &#8217;15julrr_anat.nii&#8217;, and SOME_IDENTIFIER could be &#8217;15julrr&#8217;. This identifier is the directory which will be created inside SUBJECTS_HOME.<\/p>\n<p><!---\nThe next step is to run <code>mri_annotation2label<\/code> on our subjects.  This is a pretty fast operation so we don't use the cluster for it:\n\n\n<pre>[code lang=\"bash\" title=\"run_annotation.sh\"]\n#!\/bin\/bash -l\n\n# these are the names of the subjects for which we have high-res scans for\ndeclare -a arr=(&amp;amp;amp;quot;15jul13rr&amp;amp;amp;quot; &amp;amp;amp;quot;16jul13ad&amp;amp;amp;quot; &amp;amp;amp;quot;17jul13bs&amp;amp;amp;quot; &amp;amp;amp;quot;18jul13ys&amp;amp;amp;quot;)\n\n# loop through our subjects\nfor i in &amp;amp;amp;quot;${arr[@]}&amp;amp;amp;quot;\ndo\n   echo &amp;amp;amp;quot;$i&amp;amp;amp;quot;\n   echo outputting to &amp;amp;amp;quot;$SUBJECTS_DIR&amp;amp;amp;quot;\/&amp;amp;amp;quot;$i&amp;amp;amp;quot;\/labels\n\n   # perform labeling on each hemisphere\n   mri_annotation2label --subject $i --hemi lh --outdir &amp;amp;amp;quot;$SUBJECTS_DIR&amp;amp;amp;quot;\/&amp;amp;amp;quot;$i&amp;amp;amp;quot;\/labels\n   mri_annotation2label --subject $i --hemi rh --outdir &amp;amp;amp;quot;$SUBJECTS_DIR&amp;amp;amp;quot;\/&amp;amp;amp;quot;$i&amp;amp;amp;quot;\/labels\ndone\n[\/code]<\/pre>\n\n\n--><\/p>\n<p>Next we&#8217;ll make use of AFNI&#8217;s toolset (free download <a href=\"http:\/\/afni.nimh.nih.gov\/afni\/download\/afni\/releases\/latest\" target=\"_blank\" rel=\"noopener\">here<\/a>). The first is <a href=\"http:\/\/afni.nimh.nih.gov\/pub\/dist\/doc\/program_help\/@SUMA_Make_Spec_FS.html\" target=\"_blank\" rel=\"noopener\">@SUMA_Make_Spec_FS<\/a>, which will prepare analysis for <code>suma<\/code> and store the results inside the subject&#8217;s surf directory in its own folder, SUMA. This process takes about 15-30 minutes. We then use <code>@SUMA_AlignToExperiment<\/code> to re-align our data and labels.<\/p>\n<p>Finally, we are ready to extract VOIs. We&#8217;ll use <code>whereami<\/code> to do this. We first find what the name of our region is within our atlas code:<\/p>\n<pre><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ whereami -show_atlases\n$ whereami -show_atlas_code -atlas ATLAS_CODE\n<\/pre>\n<p>where ATLAS_CODE is an atlas identifier from the output of show_atlases. If we use, &#8220;aparc.a2009s+aseg_rank&#8221;, then we are using the Destrieux&#8217;s Atlas (see <a href=\"http:\/\/freesurfer.net\/fswiki\/CorticalParcellation\" target=\"_blank\" rel=\"noopener\">here<\/a>), and we can see the codes for our atlas like so:<\/p>\n<pre><pre class=\"brush: bash; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\">\n$ whereami -show_atlas_code -atlas aparc.a2009s+aseg_rank\n++ Input coordinates orientation set by default rules to RAI\n\nAtlas aparc.a2009s+aseg_rank,      194 regions\n----------- Begin regions for aparc.a2009s+aseg_rank atlas-----------\nl:Left-Cerebellum-White-Matter:4\nl:Left-Hippocampus:13\nr:Right-choroid-plexus:34\nu:ctx_lh_G_cingul-Post-ventral:55\nu:ctx_lh_G_rectus:76\nu:ctx_lh_S_front_inf:97\nu:ctx_lh_S_oc_sup_and_transversal:103\nu:ctx_rh_G_and_S_transv_frontopol:124\nu:ctx_rh_G_pariet_inf-Supramar:145\nu:ctx_rh_S_circular_insula_ant:166\nu:ctx_rh_S_precentral-inf-part:187\nl:Left-Cerebellum-Cortex:5\nl:Left-Amygdala:14\nu:5th-Ventricle:35\nu:ctx_lh_G_cuneus:56\nu:ctx_lh_G_subcallosal:77\nu:ctx_lh_S_front_middle:98\nu:ctx_lh_S_occipital_ant:104\nu:ctx_rh_G_and_S_cingul-Ant:125\nu:ctx_rh_G_parietal_sup:146\nu:ctx_rh_S_circular_insula_inf:167\nu:ctx_rh_S_precentral-sup-part:188\nl:Left-Thalamus-Proper:6\nu:CSF:15\nu:WM-hypointensities:36\nu:ctx_lh_G_front_inf-Opercular:57\nu:ctx_lh_G_temp_sup-G_T_transv:78\nu:ctx_lh_S_front_sup:99\nu:ctx_lh_S_oc-temp_lat:105\nu:ctx_rh_G_and_S_cingul-Mid-Ant:126\nu:ctx_rh_G_postcentral:147\nu:ctx_rh_S_circular_insula_sup:168\nu:ctx_rh_S_suborbital:189\nl:Left-Caudate:7\nl:Left-Accumbens-area:16\nu:non-WM-hypointensities:37\nu:ctx_lh_G_front_inf-Orbital:58\nu:ctx_lh_G_temp_sup-Lateral:79\nu:ctx_lh_S_oc-temp_med_and_Lingual:106\nu:ctx_rh_G_and_S_cingul-Mid-Post:127\nu:ctx_rh_G_precentral:148\nu:ctx_rh_S_collat_transv_ant:169\nu:ctx_rh_S_subparietal:190\nl:Left-Putamen:8\nl:Left-VentralDC:17\nu:Optic-Chiasm:38\nu:ctx_lh_G_front_inf-Triangul:59\nu:ctx_lh_G_temp_sup-Plan_polar:80\nu:ctx_lh_S_orbital_lateral:107\nu:ctx_rh_G_cingul-Post-dorsal:128\nu:ctx_rh_G_precuneus:149\nu:ctx_rh_S_collat_transv_post:170\nu:ctx_rh_S_temporal_inf:191\nl:Left-Pallidum:9\nl:Left-vessel:18\nu:CC_Posterior:39\nu:ctx_lh_G_front_middle:60\nu:ctx_lh_G_temp_sup-Plan_tempo:81\nu:ctx_lh_S_orbital_med-olfact:108\nu:ctx_rh_G_cingul-Post-ventral:129\nu:ctx_rh_G_rectus:150\nu:ctx_rh_S_front_inf:171\nu:ctx_rh_S_temporal_sup:192\nl:Left-choroid-plexus:19\nu:CC_Mid_Posterior:40\nu:ctx_lh_G_front_sup:61\nu:ctx_lh_G_temporal_inf:82\nu:ctx_lh_S_orbital-H_Shaped:109\nu:ctx_rh_G_cuneus:130\nu:ctx_rh_G_subcallosal:151\nu:ctx_rh_S_front_middle:172\nu:ctx_rh_S_temporal_transverse:193\nr:Right-Cerebral-White-Matter:20\nu:CC_Central:41\nu:ctx_lh_G_Ins_lg_and_S_cent_ins:62\nu:ctx_lh_G_temporal_middle:83\nu:ctx_lh_S_parieto_occipital:110\nu:ctx_rh_G_front_inf-Opercular:131\nu:ctx_rh_G_temp_sup-G_T_transv:152\nu:ctx_rh_S_front_sup:173\nr:Right-Lateral-Ventricle:21\nu:CC_Mid_Anterior:42\nu:ctx_lh_G_insular_short:63\nu:ctx_lh_Lat_Fis-ant-Horizont:84\nu:ctx_lh_S_pericallosal:111\nu:ctx_rh_G_front_inf-Orbital:132\nu:ctx_rh_G_temp_sup-Lateral:153\nu:ctx_rh_S_interm_prim-Jensen:174\nr:Right-Inf-Lat-Vent:22\nu:CC_Anterior:43\nu:ctx_lh_G_occipital_middle:64\nu:ctx_lh_Lat_Fis-ant-Vertical:85\nu:ctx_lh_S_postcentral:112\nu:ctx_rh_G_front_inf-Triangul:133\nu:ctx_rh_G_temp_sup-Plan_polar:154\nu:ctx_rh_S_intrapariet_and_P_trans:175\nr:Right-Cerebellum-White-Matter:23\nu:ctx-lh-unknown:44\nu:ctx_lh_G_occipital_sup:65\nu:ctx_lh_Lat_Fis-post:86\nu:ctx_lh_S_precentral-inf-part:113\nu:ctx_rh_G_front_middle:134\nu:ctx_rh_G_temp_sup-Plan_tempo:155\nu:ctx_rh_S_oc_middle_and_Lunatus:176\nr:Right-Cerebellum-Cortex:24\nu:ctx-rh-unknown:45\nu:ctx_lh_G_oc-temp_lat-fusifor:66\nu:ctx_lh_Pole_occipital:87\nu:ctx_lh_S_precentral-sup-part:114\nu:ctx_rh_G_front_sup:135\nu:ctx_rh_G_temporal_inf:156\nu:ctx_rh_S_oc_sup_and_transversal:177\nr:Right-Thalamus-Proper:25\nu:ctx_lh_G_and_S_frontomargin:46\nu:ctx_lh_G_oc-temp_med-Lingual:67\nu:ctx_lh_Pole_temporal:88\nu:ctx_lh_S_suborbital:115\nu:ctx_rh_G_Ins_lg_and_S_cent_ins:136\nu:ctx_rh_G_temporal_middle:157\nu:ctx_rh_S_occipital_ant:178\nr:Right-Caudate:26\nu:ctx_lh_G_and_S_occipital_inf:47\nu:ctx_lh_G_oc-temp_med-Parahip:68\nu:ctx_lh_S_calcarine:89\nu:ctx_lh_S_subparietal:116\nu:ctx_rh_G_insular_short:137\nu:ctx_rh_Lat_Fis-ant-Horizont:158\nu:ctx_rh_S_oc-temp_lat:179\nr:Right-Putamen:27\nu:ctx_lh_G_and_S_paracentral:48\nu:ctx_lh_G_orbital:69\nu:ctx_lh_S_central:90\nu:ctx_lh_S_temporal_inf:117\nu:ctx_rh_G_occipital_middle:138\nu:ctx_rh_Lat_Fis-ant-Vertical:159\nu:ctx_rh_S_oc-temp_med_and_Lingual:180\nr:Right-Pallidum:28\nu:ctx_lh_G_and_S_subcentral:49\nu:ctx_lh_G_pariet_inf-Angular:70\nu:ctx_lh_S_cingul-Marginalis:91\nu:ctx_lh_S_temporal_sup:118\nu:ctx_rh_G_occipital_sup:139\nu:ctx_rh_Lat_Fis-post:160\nu:ctx_rh_S_orbital_lateral:181\nr:Right-Hippocampus:29\nu:ctx_lh_G_and_S_transv_frontopol:50\nu:ctx_lh_G_pariet_inf-Supramar:71\nu:ctx_lh_S_circular_insula_ant:92\nu:ctx_lh_S_temporal_transverse:119\nu:ctx_rh_G_oc-temp_lat-fusifor:140\nu:ctx_rh_Pole_occipital:161\nu:ctx_rh_S_orbital_med-olfact:182\nu:Unknown:0\nr:Right-Amygdala:30\nu:ctx_lh_G_and_S_cingul-Ant:51\nu:ctx_lh_G_parietal_sup:72\nu:ctx_lh_S_circular_insula_inf:93\nu:ctx_rh_G_and_S_frontomargin:120\nu:ctx_rh_G_oc-temp_med-Lingual:141\nu:ctx_rh_Pole_temporal:162\nu:ctx_rh_S_orbital-H_Shaped:183\nl:Left-Cerebral-White-Matter:1\nu:3rd-Ventricle:10\nr:Right-Accumbens-area:31\nu:ctx_lh_G_and_S_cingul-Mid-Ant:52\nu:ctx_lh_G_postcentral:73\nu:ctx_lh_S_circular_insula_sup:94\nu:ctx_lh_S_interm_prim-Jensen:100\nu:ctx_rh_G_and_S_occipital_inf:121\nu:ctx_rh_G_oc-temp_med-Parahip:142\nu:ctx_rh_S_calcarine:163\nu:ctx_rh_S_parieto_occipital:184\nl:Left-Lateral-Ventricle:2\nu:4th-Ventricle:11\nr:Right-VentralDC:32\nu:ctx_lh_G_and_S_cingul-Mid-Post:53\nu:ctx_lh_G_precentral:74\nu:ctx_lh_S_collat_transv_ant:95\nu:ctx_lh_S_intrapariet_and_P_trans:101\nu:ctx_rh_G_and_S_paracentral:122\nu:ctx_rh_G_orbital:143\nu:ctx_rh_S_central:164\nu:ctx_rh_S_pericallosal:185\nl:Left-Inf-Lat-Vent:3\nu:Brain-Stem:12\nr:Right-vessel:33\nu:ctx_lh_G_cingul-Post-dorsal:54\nu:ctx_lh_G_precuneus:75\nu:ctx_lh_S_collat_transv_post:96\nu:ctx_lh_S_oc_middle_and_Lunatus:102\nu:ctx_rh_G_and_S_subcentral:123\nu:ctx_rh_G_pariet_inf-Angular:144\nu:ctx_rh_S_cingul-Marginalis:165\nu:ctx_rh_S_postcentral:186\n----------- End regions for aparc.a2009s+aseg_rank atlas --------------\n<\/pre>\n<p>To extract one of these regions as a mask, we can use whereami:<\/p>\n<pre><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ whereami -atlas aparc.a2009s+aseg_rank_Alnd_Exp\n           -mask_atlas_region aparc.a2009s+aseg_rank_Alnd_Exp::ctx_lh_G_temporal_middle\n           -prefix lh.mtg.al+orig\n<\/pre>\n<p>More reading:<br \/>\n<a href=\"http:\/\/brainybehavior.com\/neuroimaging\/2010\/05\/converting-cortical-labels-from-freesurfer-to-volumetric-masks\/\">http:\/\/brainybehavior.com\/neuroimaging\/2010\/05\/converting-cortical-labels-from-freesurfer-to-volumetric-masks\/<\/a><br \/>\n<a href=\"http:\/\/blog.cogneurostats.com\/?p=268\" target=\"_blank\" rel=\"noopener\">http:\/\/blog.cogneurostats.com\/?p=268<\/a><br \/>\n<a href=\"http:\/\/blog.cogneurostats.com\/?p=217\" target=\"_blank\" rel=\"noopener\">http:\/\/blog.cogneurostats.com\/?p=217<\/a><br \/>\n<a href=\"http:\/\/neuroimage.usc.edu\/brainstorm\/Tutorials\/LabelFreeSurfer\">http:\/\/neuroimage.usc.edu\/brainstorm\/Tutorials\/LabelFreeSurfer<\/a><\/p>\n<p>References:<br \/>\n[1]. Destrieux, C., Fischl, B., Dale, A., &amp; Halgren, E. (2010). Automatic parcellation of human cortical gyri and sulci using standard anatomical nomenclature. Neuroimage, 53(1), 1\u201315. doi:10.1016\/j.neuroimage.2010.06.010.Automatic<\/p>\n<p>[2]. Fischl et al. (2004). Automatically Parcellating the Human Cerebral Cortex. Cerebral Cortex, 14:11-22.<\/p>\n<p>[3]. Desikan et al. (2006). An automated labeling system for subdividing the human cerebral cortex on MRI scans into gyral based regions of interest. NeuroImage, 31(3):968-80.<\/p>\n<p>Notes:<br \/>\nMany thanks to <a href=\"http:\/\/beausievers.com\/\" target=\"_blank\" rel=\"noopener\">Beau Sievers<\/a> and Carolyn Parkinson for their help in this process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Performing a region of interest analysis on MRI requires knowing where the regions are in your subject data. Typically, this has been done using hand-drawn masks in a 3d viewer.&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[23,42,113,150,156,252,274,299,369],"class_list":["post-1658","post","type-post","status-publish","format-standard","hentry","category-neuroscience","tag-afni","tag-atlas","tag-destrieux","tag-fmri","tag-freesurfer","tag-neuroscience","tag-parcellation","tag-roi","tag-volumetric"],"acf":[],"_links":{"self":[{"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/posts\/1658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/comments?post=1658"}],"version-history":[{"count":3,"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/posts\/1658\/revisions"}],"predecessor-version":[{"id":2444,"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/posts\/1658\/revisions\/2444"}],"wp:attachment":[{"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/media?parent=1658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/categories?post=1658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pkmital.com\/home\/wp-json\/wp\/v2\/tags?post=1658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}