<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Structural Neuroimaging With OS X</title>
	<atom:link href="http://brainybehavior.com/neuroimaging/feed/" rel="self" type="application/rss+xml" />
	<link>http://brainybehavior.com/neuroimaging</link>
	<description>Illuminating the processing of structural MRI data</description>
	<lastBuildDate>Sat, 19 Nov 2011 02:37:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using awk to truncate text files</title>
		<link>http://brainybehavior.com/neuroimaging/2011/11/awk-for-truncating-files/</link>
		<comments>http://brainybehavior.com/neuroimaging/2011/11/awk-for-truncating-files/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 04:32:24 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=235</guid>
		<description><![CDATA[With neuroimaging analyses we deal with a lot of text files. These are often the result of program or scripts running on the MRI data; they can be statistics, volumes, error logs, or any number of other outputs. Let&#8217;s say &#8230; <a href="http://brainybehavior.com/neuroimaging/2011/11/awk-for-truncating-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With neuroimaging analyses we deal with a lot of text files. These are often the result of program or scripts running on the MRI data; they can be statistics, volumes, error logs, or any number of other outputs. Let&#8217;s say that we have a large text file with a lot of data in it. Let&#8217;s suppose that it is at least organized neatly into rows and columns, which means it could easily be imported into Excel or another spreadsheet application. FreeSurfer&#8217;s aseg.stats is a good example of this.</p>
<p>For simplicity, let&#8217;s say that we have a 5&#215;5 matrix of data (it&#8217;s really a 6&#215;6 but we&#8217;ll just focus on the 25 numerical data values):</p>
<p><code>   X1 X2 X3 X4 X5<br />
Y1 3000 5000 745 122 875<br />
Y2 942 400 263 558 991<br />
Y3 325 584 775 381 545<br />
Y4 654 336 272 883 235<br />
Y5 241 154 782 754 899</code></p>
<p>Notice that the column headers do not always line up with the rest of the columns; this is nothing to worry about. If you have a file like this (or are creating one), it is helpful to have a blank new line at the end (i.e., a blank extra row). This can help with the display and processing of text files.</p>
<p>Say you want to display the contents of the text file. Any easy way to do this is with <code>cat {file}.txt</code>. This will quickly display the contents on the screen. If it&#8217;s a long text file, you should use <code>less {file}.txt</code> instead of <code>cat</code>.</p>
<p>Here&#8217;s what this looks like with our sample file.</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/cat_screenshot_bash.png"><img class="aligncenter size-medium wp-image-237" title="cat_screenshot_bash" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/cat_screenshot_bash-300x249.png" alt="" width="300" height="249" /></a>If you want to number the lines, you can run <code>cat -n {file}.txt</code>, which results in a display like this:</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/cat_bash_numbered.png"><img class="aligncenter size-medium wp-image-238" title="cat_bash_numbered" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/cat_bash_numbered-300x249.png" alt="" width="300" height="249" /></a>Or, you can use awk: <code>awk 'FNR==1{print ""}1' {file}.txt</code></p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_cat_bash.png"><img class="aligncenter size-medium wp-image-239" title="awk_cat_bash" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_cat_bash-300x249.png" alt="" width="300" height="249" /></a>Now, let&#8217;s say that instead of the entire file, you just want a row of values or a single value. Here&#8217;s a way to display just one row: <code>awk 'BEGIN { RS = "" ; FS = "\n" } ; { print $2 }' {file}.txt</code></p>
<p>The <code>{print $2}</code> specifies the second row in the file. This could be changed to $3, $5, $8, or whatever you want, if it&#8217;s a valid row number in the file.</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_single_row.png"><img class="aligncenter size-medium wp-image-240" title="awk_single_row" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_single_row-300x249.png" alt="" width="300" height="249" /></a>You could also write that line to a new file with <code>&gt;</code> or the pipe <code>|.</code></p>
<p>Now, what if you want a column from the file?</p>
<p><code>awk '{ print $3 }' {file}.txt</code></p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_print_column.png"><img class="aligncenter size-medium wp-image-241" title="awk_print_column" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_print_column-300x249.png" alt="" width="300" height="249" /></a>Now, what if you want only a single value from the text file. I know there are shorter ways of doing this but one way is to do a two-step awk command by combining the column and row commands I already demonstrated:<br />
<code></code></p>
<p><code>awk 'BEGIN { RS = "" ; FS = "\n" } ; { print $2 }' {file}.txt | tee -a file_tmp.txt;<br />
awk '{ print $3; exit }' file_tmp.txt | tee -a subject_volume.txt;<br />
rm file_tmp.txt</code></p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_column_row_value.png"><img class="aligncenter size-medium wp-image-242" title="awk_column_row_value" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/11/awk_column_row_value-300x249.png" alt="" width="300" height="249" /></a></p>
<p>This displays the second row in the file and writes it to a temporary file; then it reads and displays and saves the value from the 3rd column in the temp file. The &#8220;exit&#8221; part of the second command will limit the print command to a single value, should there be multiple values in the column (or row). Lastly, it deletes the temp file. In the screenshot above, I am showing the value in the second row, third column (this includes the row and coumn labels). You could also run this with the column command first, if that&#8217;s easier.</p>
<p>This can save you a lot of time if you have to pull out values from a lot of text files (e.g., aseg.stats) by using a for or while loop. I recently did this to pull values out of some text files. It would have taken hours to pull out the correct values from every participant by hand. With a script (series of &#8220;for&#8221; loops) it ran in seconds. Then, I had a file with all the values for all the participants, which was then imported into Excel.</p>
<p>I am a novice user of awk so specific questions about it are best directed elsewhere. This is just what I&#8217;ve figured out by reading various guides online.</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2011/11/awk-for-truncating-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using FreeSurfer&#8217;s bbregister for Image Registration</title>
		<link>http://brainybehavior.com/neuroimaging/2011/04/using-freesurfers-bbregister-for-image-registration/</link>
		<comments>http://brainybehavior.com/neuroimaging/2011/04/using-freesurfers-bbregister-for-image-registration/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 13:47:20 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Conversions]]></category>
		<category><![CDATA[FreeSurfer]]></category>
		<category><![CDATA[FSL]]></category>
		<category><![CDATA[bbregister]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[flirt]]></category>
		<category><![CDATA[fnirt]]></category>
		<category><![CDATA[labels]]></category>
		<category><![CDATA[registration]]></category>
		<category><![CDATA[rois]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=205</guid>
		<description><![CDATA[I know I post a lot about registration (see here and here) but I believe that image registration is one of the most important components of an MRI processing pipeline. Thankfully, there are some good tools available. FLIRT, FNIRT, bbregister, &#8230; <a href="http://brainybehavior.com/neuroimaging/2011/04/using-freesurfers-bbregister-for-image-registration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I know I post a lot about registration (see <a href="http://brainybehavior.com/neuroimaging/2010/08/flirt-fnirt-and-syn-image-registration/">here</a> and <a href="http://brainybehavior.com/neuroimaging/2010/06/converting-freesurfer-labels-to-masks/">here</a>) but I believe that image registration is one of the most important components of an MRI processing pipeline. Thankfully, there are some good tools available. <a href="http://www.fmrib.ox.ac.uk/fsl/flirt/index.html" onclick="pageTracker._trackPageview('/outgoing/www.fmrib.ox.ac.uk/fsl/flirt/index.html?referer=');">FLIRT</a>, <a href="http://www.fmrib.ox.ac.uk/fsl/fnirt/index.html" onclick="pageTracker._trackPageview('/outgoing/www.fmrib.ox.ac.uk/fsl/fnirt/index.html?referer=');">FNIRT</a>, <a href="http://surfer.nmr.mgh.harvard.edu/fswiki/bbregister" onclick="pageTracker._trackPageview('/outgoing/surfer.nmr.mgh.harvard.edu/fswiki/bbregister?referer=');">bbregister</a>, and <a href="http://picsl.upenn.edu/ANTS/" onclick="pageTracker._trackPageview('/outgoing/picsl.upenn.edu/ANTS/?referer=');">ANTS</a> are just a few of the registration tools I&#8217;ve used. I&#8217;ve found that for intra-individual inter-modal (diffusion to T1 or vice versa) registration, rigid body or even affine (linear) is usually sufficient if the registered scans were acquired at the same scanning session. Even if they were not, linear registrations should be good enough for intra-individual work. Why is this?</p>
<p>Part of the difficulty with the flexibility of nonlinear registrations is that they can be too flexible. This is a problem when you are trying to align diffusion weighted scans to T1 scans, for example. Here are a couple images showing some distortion. This distortion is mostly due to proximity to the air filled sinuses.</p>
<p style="text-align: center;"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/b0_frontal_distortion.png"><img class="aligncenter size-full wp-image-206" title="b0_frontal_distortion" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/b0_frontal_distortion.png" alt="" width="347" height="401" /></a>A b0 image (no diffusion weighting applied) showing frontal distortion.</p>
<p style="text-align: center;"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/64_dir_dwi_temporal_distortion.png"><img class="aligncenter size-medium wp-image-207" title="64_dir_dwi_temporal_distortion" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/64_dir_dwi_temporal_distortion-270x300.png" alt="" width="270" height="300" /></a>One direction from a 64 direction dwi sequence showing temporal distortion.</p>
<p style="text-align: left;">With very flexible nonlinear registration methods on a skull-stripped brain, the tools try to stretch brain regions to fit; if there is warping or other distortion, we do not get good results. Using a non-skull-stripped brain sometimes fixes the problem but in some cases (intra-individual inter-modal) nonlinear methods are likely overkill.</p>
<p style="text-align: left;">I&#8217;ve been doing trial runs with FreeSurfer&#8217;s bbregister in order to see how well it works. It&#8217;s relatively simple.</p>
<p style="text-align: left;">First, the T1(s) of a subject should be processed through the recon-all Freesurfer script. Next, if you want you can use FreeSurfer&#8217;s script <a href="http://surfer.nmr.mgh.harvard.edu/fswiki/dt_recon" onclick="pageTracker._trackPageview('/outgoing/surfer.nmr.mgh.harvard.edu/fswiki/dt_recon?referer=');">dt_recon</a> to do preliminary processing of diffusion data. That&#8217;s actually the easiest pathway because it will register your diffusion data to your structural data in the process. The matrix file you will need is called register.dat (see screenshot).</p>
<p style="text-align: left;"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/dti_recon_outdir.png"><img class="aligncenter size-full wp-image-208" title="dti_recon_outdir" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/dti_recon_outdir.png" alt="" width="171" height="781" /></a>If you did not or do not want to run dt_recon (it uses a number of FSL&#8217;s diffusion tools), you can create that registration file by hand using bbregister. To do this type a command like this:</p>
<p><code>bbregister --s sub001 --mov /<span style="color: #ff0000;">{path to b0 image}</span>/lowb.nii.gz --reg /<span style="color: #ff0000;">{path to where you will save the matrix file}</span>/lowb2orig.dat --dti --init-fsl</code></p>
<p>What this does is create a .dat (matrix) file that tells an image how to get from diffusion space to FreeSurfer&#8217;s conformed space (i.e., the 256x256x256 1x1x1mm space that orig.mgz is in). You could set your <code>--mov</code> as the orig.mgz and add a <code>--target</code> with it set to your b0 (lowb or nodif or whatever the file is called) image. Without a <code>--targ</code> a conformed image (e.g., orig.mgz) is the implied target. I typically make the diffusion image the movable one and then apply the inverse matrix to files in conformed space that I want to be in diffusion space. It seems a little backward but it works well. [Note: I could be mistaken about this but I believe it is the case].</p>
<p>You&#8217;ll see something like this in your Terminal:</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/bbregister_terminal_flow.png"><img class="aligncenter size-medium wp-image-209" title="bbregister_terminal_flow" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/bbregister_terminal_flow-300x246.png" alt="" width="300" height="246" /></a>You can check your results with tkregister2: <code>tkregister2 --mov /{path to b0 image}/lowb.nii.gz --reg /{path to where you will save the matrix file}/lowb2orig.dat --surf</code></p>
<p>You&#8217;ll see something like this in tkregister2:</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/bbregister_tkregister_results.png"><img class="aligncenter size-medium wp-image-210" title="bbregister_tkregister_results" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2011/04/bbregister_tkregister_results-170x300.png" alt="" width="170" height="300" /></a></p>
<p>I&#8217;ve yet to get a bad result but we have good MRI data.</p>
<p>Now you can use this registration matrix to get ROIs from FreeSurfer&#8217;s conformed space (this example was made up with an occipital ROI that could have been created in ITK-SNAP; you could also change all of aseg.mgz into diffusion space this way) into diffusion space with mri_vol2vol:</p>
<p><code>mri_vol2vol --mov /Users/Shared/DWI_MAS/sub001/DATA/nodif.nii.gz --targ /Users/Shared/DWI_MAS/sub001/ROIS/sub001_r_occipital_roi.nii.gz --o /Users/Shared/DWI_MAS/sub001/ROIS/sub001_r_occipital_roi2dwi.nii.gz --reg /Users/Shared/DWI_MAS/sub001/DATA/orig2nodif.dat --inv –-nearest</code></p>
<p>Note the <code>--inv</code> that specifies to apply the inverse of the matrix (conformed &#8211;&gt; diffusion rather than diffusion &#8211;&gt; conformed).</p>
<p>It also works for getting FreeSurfer cortical labels into diffusion space with mri_label2vol (note: you&#8217;ll want to play around with the <code>--proj</code> option to see what works for you):</p>
<p><code>mri_label2vol --label /Applications/freesurfer/subjects/sub001/label/lh.entorhinal_exvivo.label --reg /Users/Shared/DWI_MAS/sub001/DATA/nodif2orig.dat --fillthresh .3 --hemi lh --subject sub001 --o /Users/Shared/DWI_MAS/sub001/rois/sub001_l_exvivo_erc.nii.gz --temp /Users/Shared/DWI_MAS/sub001/data/nodif.nii.gz --proj frac 0 1 .1</code></p>
<p style="text-align: center;"><a href="https://img.skitch.com/20110420-1r94awf6i9c4cccpjf544gq2nd.png" onclick="pageTracker._trackPageview('/outgoing/img.skitch.com/20110420-1r94awf6i9c4cccpjf544gq2nd.png?referer=');"><img class="aligncenter" title="l_erc_in_dwi_space" src="https://img.skitch.com/20110420-1r94awf6i9c4cccpjf544gq2nd.png" alt="" width="508" height="330" /></a></p>
<p style="text-align: left;">There you go! Using bbregister, you can end up with good intra-individual, inter-modal registrations. I went beyond a simple registration but registrations are only really useful as one very important step in a broader imaging process.</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2011/04/using-freesurfers-bbregister-for-image-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NeuroDebian</title>
		<link>http://brainybehavior.com/neuroimaging/2011/04/neurodebian/</link>
		<comments>http://brainybehavior.com/neuroimaging/2011/04/neurodebian/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 21:12:05 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Neuroscience]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[neuroscience]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=196</guid>
		<description><![CDATA[I recently came across a great resource for people involved in neuroscience research. It&#8217;s called NeuroDebian; it&#8217;s a Debian neuroscience repository. Debian is a popular Linux distro; what is likely the most popular consumer Linux distro &#8211; Ubuntu &#8211; is &#8230; <a href="http://brainybehavior.com/neuroimaging/2011/04/neurodebian/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently came across a great resource for people involved in neuroscience research. It&#8217;s called <a href="http://neuro.debian.net/" onclick="pageTracker._trackPageview('/outgoing/neuro.debian.net/?referer=');">NeuroDebian</a>; it&#8217;s a Debian neuroscience repository. <a href="http://www.debian.org/" onclick="pageTracker._trackPageview('/outgoing/www.debian.org/?referer=');">Debian</a> is a popular Linux distro; what is likely the most popular consumer Linux distro &#8211; Ubuntu &#8211; is an offshoot of Debian. Those comfortable with one likely will be comfortable with the other. I know that this does not directly apply to the Mac but you will deal with Linux at some point if you do enough neuroimaging (although most of the software are available as Mac native packages) so it&#8217;s worth becoming familiar with it. If you are comfortable with the command line in OS X, you will be comfortable in Linux.</p>
<p>The repository includes a number of neuroscience packages (programs) for easy installation and update (e.g., FSL, MRIcron, AFNI, 3d Slicer, ITK-SNAP). You can add the repositories to your <a href="http://neuro.debian.net/#how-to-use-this-repository" onclick="pageTracker._trackPageview('/outgoing/neuro.debian.net/_how-to-use-this-repository?referer=');">existing Linux installation</a> (Debian or Ubuntu) or you can download a <a href="http://neuro.debian.net/vm.html#chap-vm" onclick="pageTracker._trackPageview('/outgoing/neuro.debian.net/vm.html_chap-vm?referer=');">Debian virtual machine</a>, which allows you to try out Debian and the repository without altering your current system. To use this virtual machine you need to install <a href="http://www.virtualbox.org/" onclick="pageTracker._trackPageview('/outgoing/www.virtualbox.org/?referer=');">VirtualBox</a> (a free download for Windows, Linux, Mac, or Solaris). The setup is easy and explained on the neurodebian website.</p>
<p>Here&#8217;s what it looks like running on my Mac (or you can visit <a href="https://img.skitch.com/20110415-jkmahdyknqjb92tcmd3jfsx4wc.png" onclick="pageTracker._trackPageview('/outgoing/img.skitch.com/20110415-jkmahdyknqjb92tcmd3jfsx4wc.png?referer=');">this link</a> for a full-size screenshot):</p>
<p style="text-align: center;"><img class="aligncenter" title="NeuroDebian" src="https://img.skitch.com/20110415-jkmahdyknqjb92tcmd3jfsx4wc.png" alt="" width="554" height="349" /></p>
<p style="text-align: left;">I haven&#8217;t had an opportunity to use it much yet but I wanted to spread the word about this service. I&#8217;ll post more about it once I have an opportunity to use it more. It makes the installation and management of many popular neuroscience programs easy (for example, it can be as easy as: <code>sudo apt-get install ants</code>). Unless you are doing very graphics heavy 3D imaging work, virtualizing many neurodebian will have plenty of performance on modern computer systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2011/04/neurodebian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Great Resource for Advanced Bash Scripting</title>
		<link>http://brainybehavior.com/neuroimaging/2011/04/a-great-resource-for-advanced-bash-scripting/</link>
		<comments>http://brainybehavior.com/neuroimaging/2011/04/a-great-resource-for-advanced-bash-scripting/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 20:40:18 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=190</guid>
		<description><![CDATA[I&#8217;ve written about shell scripting before (see here and here). Scripting is necessary for efficient neuroimage processing. At the very least, it can provide a way to keep track of how you did something. While there are a number of &#8230; <a href="http://brainybehavior.com/neuroimaging/2011/04/a-great-resource-for-advanced-bash-scripting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written about shell scripting before (see <a href="http://brainybehavior.com/neuroimaging/2010/08/bash-scripting-for-neuroimaging/">here</a> and <a href="http://brainybehavior.com/neuroimaging/2010/09/bash-for-loops-plus-a-little-scripting/">here</a>). Scripting is necessary for efficient neuroimage processing. At the very least, it can provide a way to keep track of how you did something. While there are a number of ways to script &#8211; Bash, Perl, or Python, for example &#8211; I&#8217;ve done most of my scripting in Bash so far. I&#8217;m currently branching out to Perl and Python but I haven&#8217;t re-written any of my Bash scripts in Perl or Python yet.</p>
<p><a href="http://www.tldp.org/LDP/abs/" onclick="pageTracker._trackPageview('/outgoing/www.tldp.org/LDP/abs/?referer=');">Here</a> is a great, in-depth introduction to Bash scripting. That link takes you to a directory where you can select the format of the guide: <a href="http://www.tldp.org/LDP/abs/html/" onclick="pageTracker._trackPageview('/outgoing/www.tldp.org/LDP/abs/html/?referer=');">HTML</a>, <a href="http://www.tldp.org/LDP/abs/abs-guide.pdf" onclick="pageTracker._trackPageview('/outgoing/www.tldp.org/LDP/abs/abs-guide.pdf?referer=');">PDF</a>, or a few others. I did not create that guide or have any role in its creation. It was created by people affiliated with <a href="http://tldp.org/history.html" onclick="pageTracker._trackPageview('/outgoing/tldp.org/history.html?referer=');">The Linux Documentation Project</a>.</p>
<p>The guide might be more in-depth than you might need for your neuroimaging scripting needs but it is a great resource if you want to brush up on your scripting. Then, if you branch out to a language like Perl, it will likely be easier to learn.</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2011/04/a-great-resource-for-advanced-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How much computer do you need for MRI processing?</title>
		<link>http://brainybehavior.com/neuroimaging/2010/12/how-much-computer-do-you-need-for-mri-processing/</link>
		<comments>http://brainybehavior.com/neuroimaging/2010/12/how-much-computer-do-you-need-for-mri-processing/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 02:36:23 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[iMac]]></category>
		<category><![CDATA[Mac Pro]]></category>
		<category><![CDATA[neuroimaging]]></category>
		<category><![CDATA[RAM]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=181</guid>
		<description><![CDATA[I want to address how much computing power you need when imaging. The short answer is: as much as you can. RAM If you want to stick with a Mac environment, a Mac Pro would be ideal (although we use &#8230; <a href="http://brainybehavior.com/neuroimaging/2010/12/how-much-computer-do-you-need-for-mri-processing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I want to address how much computing power you need when imaging. The short answer is: as much as you can.</p>
<h2>RAM</h2>
<p>If you want to stick with a Mac environment, a Mac Pro would be ideal (although we use iMacs, which work wonderfully). If you plan on running a lot of processes in parallel or doing some intensive visualizations, put as much RAM in the computer as possible. The current generation of Mac Pros can accept 64 GB of RAM; the current iMacs accept 16 GB of RAM. However, if you are not going to do a lot of intensive visualization (if you are not going to use TrackVis, for example), 8 GB of RAM should be the minimum. Again, get as much RAM as possible but get at least 8 GB. I like at least 2 GB per processor/core.</p>
<p>As far as the quality of RAM is concerned, most RAM is pretty good quality now; you do not necessarily have to use really expensive RAM unless your system calls for it. It is a good idea to run a memory test though to check for any problems.</p>
<h2>CPU</h2>
<p><img class="alignright size-medium wp-image-182" title="macpro" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/12/macpro-300x290.png" alt="" width="300" height="290" /></p>
<p>The rule with the CPU is the same as with RAM &#8211; get as much as you can. Not all processes are parallelized but some are. Additionally, for something like FreeSurfer, if you have multiple processors (or just multiple cores), you can run multiple instances of the program concurrently. This is another reason why you want as much RAM as you can have &#8211; each process uses RAM so the more you run, the more RAM you need. As far as processors go, it doesn&#8217;t matter if you use Intel or AMD (or something else); I prefer Intel but I just built an AMD box and in the end, it doesn&#8217;t matter too much which company you choose. For imaging, I recommend at least 4 cores/processors but get as many as you can. In our lab we have iMacs with i7 hyperthreaded cores (4 real cores plus 4 virtual cores). You can get a <a href="http://www.apple.com/macpro/features/processor.html" onclick="pageTracker._trackPageview('/outgoing/www.apple.com/macpro/features/processor.html?referer=');">Mac Pro with 12 cores</a> (2 six core processors), which would be great for imaging work. Of course, you could build a Linux machine with similar specifications for cheaper than the Mac Pro but there are good reasons for choosing either path. If money is not an option (and you don&#8217;t need really high-end stuff), I&#8217;d recommend Macs. You could, alternatively, chain a number of Mac Minis together and build your own little processing farm. Mac Minis don&#8217;t have the best processors but if you can parallelize tasks, a stack of Mac Minis might do the trick. Of course, if you have access to a supercomputer, that can be even better (although, there are plenty of reasons to avoid supercomputers too).</p>
<h2>Conclusion</h2>
<p>In summary, you can never have too much RAM and too much processing power when it comes to neuroimaging. If you think that the costs up front are high, wait until you have to do work over and have to wait for your computers. The less time you spend processing, the more time you have to analyze and write. Generally time that you spend waiting for processes to finish is wasted time. That&#8217;s why you want the fastest computer with as much RAM as you can afford. I have to reiterate though that you only need buckets of RAM (&gt;8 GB or so) if you are doing a lot of visualization, otherwise, you don&#8217;t have to get too much RAM (&gt;16 GB).</p>
<p>I&#8217;ll address graphics cards in a future post, especially as they apply to imaging (e.g., CUDA and FreeSurfer).</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2010/12/how-much-computer-do-you-need-for-mri-processing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pitfalls in Analyzing Diffusion Data</title>
		<link>http://brainybehavior.com/neuroimaging/2010/11/pitfalls-in-analyzing-diffusion-data/</link>
		<comments>http://brainybehavior.com/neuroimaging/2010/11/pitfalls-in-analyzing-diffusion-data/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 04:01:59 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[critical thinking]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[mri]]></category>
		<category><![CDATA[science]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=178</guid>
		<description><![CDATA[Before anyone undertakes research where diffusion weighted MR imaging will be done, I think he or she should read a 2010 article by Derek K. Jones and Mara Cercignani. This article &#8211; Twenty-five pitfalls in the analysis of diffusion MRI data &#8230; <a href="http://brainybehavior.com/neuroimaging/2010/11/pitfalls-in-analyzing-diffusion-data/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Before anyone undertakes research where diffusion weighted MR imaging will be done, I think he or she should read a 2010 article by Derek K. Jones and Mara Cercignani. This article &#8211; <a href="http://onlinelibrary.wiley.com/doi/10.1002/nbm.1543/abstract" onclick="pageTracker._trackPageview('/outgoing/onlinelibrary.wiley.com/doi/10.1002/nbm.1543/abstract?referer=');">Twenty-five pitfalls in the analysis of diffusion MRI data</a> &#8211; was published in NMR in Biomedicine. Here&#8217;s the abstract:</p>
<blockquote><p>Obtaining reliable data and drawing meaningful and robust inferences from diffusion MRI can be challenging and is subject to many pitfalls. The process of quantifying diffusion indices and eventually comparing them between groups of subjects and/or correlating them with other parameters starts at the acquisition of the raw data, followed by a long pipeline of image processing steps. Each one of these steps is susceptible to sources of bias, which may not only limit the accuracy and precision, but can lead to substantial errors. This article provides a detailed review of the steps along the analysis pipeline and their associated pitfalls. These are grouped into 1 pre-processing of data; 2 estimation of the tensor; 3 derivation of voxelwise quantitative parameters; 4 strategies for extracting quantitative parameters; and finally 5 intra-subject and inter-subject comparison, including region of interest, histogram, tract-specific and voxel-based analyses. The article covers important aspects of diffusion MRI analysis, such as motion correction, susceptibility and eddy current distortion correction, model fitting, region of interest placement, histogram and voxel-based analysis. We have assembled 25 pitfalls (several previously unreported) into a single article, which should serve as a useful reference for those embarking on new diffusion MRI-based studies, and as a check for those who may already be running studies but may have overlooked some important confounds. While some of these problems are well known to diffusion experts, they might not be to other researchers wishing to undertake a clinical study based on diffusion MRI.</p></blockquote>
<p>I think this is a must-read article for anyone working with diffusion imaging. There are a lot of wonderful things that we can do with diffusion weighted images but we have to be conscious of the limitations and sources of bias in this type of imaging. The day we stop questioning and challenging our methods and results &#8211; thinking critically about our methods and personal biases &#8211; is the day our science really suffers. We as scientists have an obligation to do the best work possible because our research can have broad, applied implications that might affect a lot of people for good or ill. At the very least, scientists add to the general pool of knowledge and we want that pool as free from contaminants as possible. It is critical thinkers like Jones and Cercignani who help keep scientists honest with their (our) methods, even if we sometimes act out of innocence by using methods we do not really understand.</p>
<p>Here&#8217;s the reference: Jones and Cercignani. Twenty-five pitfalls in the analysis of diffusion MRI data. NMR in biomedicine (2010) vol. 23 (7) pp. 803-820.</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2010/11/pitfalls-in-analyzing-diffusion-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Art of Neuroimaging</title>
		<link>http://brainybehavior.com/neuroimaging/2010/11/the-art-of-neuroimaging/</link>
		<comments>http://brainybehavior.com/neuroimaging/2010/11/the-art-of-neuroimaging/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 15:03:32 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Fiber Tracking]]></category>
		<category><![CDATA[fiber tracking]]></category>
		<category><![CDATA[neuroimaging]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=167</guid>
		<description><![CDATA[Here are a few of my favorite fiber tracking images I&#8217;ve created (and one non-diffusion image). There is an art to neuroimaging. Sorry for the obnoxious watermarks; because all the images are funded by the grant NINDS K23NS060660 (Catherine Price, University &#8230; <a href="http://brainybehavior.com/neuroimaging/2010/11/the-art-of-neuroimaging/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here are a few of my favorite fiber tracking images I&#8217;ve created (and one non-diffusion image). There is an art to neuroimaging. Sorry for the obnoxious watermarks; because all the images are funded by the grant NINDS K23NS060660 (Catherine Price, University of Florida), you need to obtain my permission to use the images. I can provide non-watermarked images. All images are limited to non-commerical use (in part because of TrackVis licensing requirements).</p>
<div id="attachment_168" class="wp-caption aligncenter" style="width: 310px"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/brainstem_fibers-1024x7591.png"><img class="aligncenter size-medium wp-image-220" title="brainstem_fibers-1024x759" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/brainstem_fibers-1024x7591-300x222.png" alt="" width="300" height="222" /></a><br />
<p class="wp-caption-text">Fibers passing through the brainstem</p></div>
<div id="attachment_169" class="wp-caption aligncenter" style="width: 310px"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/frontal_caudate.png"><img class="aligncenter size-medium wp-image-224" title="frontal_caudate" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/frontal_caudate-300x209.png" alt="" width="300" height="209" /></a><br />
<p class="wp-caption-text">Frontal to caudate fibers</p></div>
<div id="attachment_170" class="wp-caption aligncenter" style="width: 310px"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/centrum_semiovale_water.png"><img class="aligncenter size-medium wp-image-225" title="centrum_semiovale_water" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/centrum_semiovale_water-300x162.png" alt="" width="300" height="162" /></a><br />
<p class="wp-caption-text">Centrum semiovale fibers</p></div>
<div id="attachment_171" class="wp-caption aligncenter" style="width: 310px"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/r_pontine_FA.png"><img class="aligncenter size-medium wp-image-226" title="r_pontine_FA" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/r_pontine_FA-300x196.png" alt="" width="300" height="196" /></a><br />
<p class="wp-caption-text">Fibers through brainstem colored by FA value</p></div>
<div id="attachment_172" class="wp-caption aligncenter" style="width: 310px"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/r_pontine_fibers1.png"><img class="aligncenter size-medium wp-image-227" title="r_pontine_fibers" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/r_pontine_fibers1-300x162.png" alt="" width="300" height="162" /></a><br />
<p class="wp-caption-text">Fibers in the pons</p></div>
<div id="attachment_173" class="wp-caption aligncenter" style="width: 310px"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/lh_thickness_inflated.png"><img class="size-medium wp-image-173" title="lh_thickness_inflated" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/11/lh_thickness_inflated-300x181.png" alt="" width="300" height="181" /></a><p class="wp-caption-text">Surface map of cortex showing thickness</p></div>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2010/11/the-art-of-neuroimaging/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FreeSurfer Tools for Mask Manipulation</title>
		<link>http://brainybehavior.com/neuroimaging/2010/10/freesurfer-tools-mask-manipulation/</link>
		<comments>http://brainybehavior.com/neuroimaging/2010/10/freesurfer-tools-mask-manipulation/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 21:11:00 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[FreeSurfer]]></category>
		<category><![CDATA[FSL]]></category>
		<category><![CDATA[ITK-SNAP]]></category>
		<category><![CDATA[binary mask]]></category>
		<category><![CDATA[fsl]]></category>
		<category><![CDATA[fslmaths]]></category>
		<category><![CDATA[FSLView]]></category>
		<category><![CDATA[mask]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=155</guid>
		<description><![CDATA[FreeSurfer includes a useful tool for manipulating mask files. Let&#8217;s say you wanted to pull the left caudate from the aseg.mgz file in order to use it for fiber tracking (that&#8217;s my default example in part because it&#8217;s salient for &#8230; <a href="http://brainybehavior.com/neuroimaging/2010/10/freesurfer-tools-mask-manipulation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>FreeSurfer includes a useful tool for manipulating mask files. Let&#8217;s say you wanted to pull the left caudate from the aseg.mgz file in order to use it for fiber tracking (that&#8217;s my default example in part because it&#8217;s salient for my research).</p>
<p>I want to be able to work with the FreeSurfer created files in other programs so I&#8217;ll convert to nii.gz.</p>
<p>mri_convert /Applications/freesurfer/subjects/{subjectID}/mri/orig.mgz /Applications/freesurfer/subjects/{subjectID}/mri/orig.nii.gz</p>
<p>Now I want to convert the aseg.mgz file over. I&#8217;ll use a different method than mri_convert or mri_binarize (although both could work).</p>
<p>mri_label2vol &#8211;subject {subjectID} &#8211;seg /Applications/freesurfer/subjects/{subjectID}/mri/aseg.mgz &#8211;fillthresh .8 &#8211;identity &#8211;temp /Applications/freesurfer/subjects/{subjectID}/mri/orig.mgz &#8211;o /Applications/freesurfer/subjects/{subjectID}/mri/aseg2vol.nii.gz</p>
<p>Technically, I didn&#8217;t need the &#8211;subject on there but I like to include it just as a redundancy.</p>
<p>Here&#8217;s the output in ITK-SNAP:</p>
<p style="text-align: center;"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/10/jt_itksnap_brain_aseg1.png"><img class="aligncenter size-medium wp-image-162" title="jt_itksnap_brain_aseg" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/10/jt_itksnap_brain_aseg1-300x160.png" alt="" width="300" height="160" /></a></p>
<p>But I don&#8217;t need all of the brain structures, I just want the left caudate (label 11).</p>
<p>mri_binarize &#8211;i /Applications/freesurfer/subjects/{subjectID}/mri/aseg2vol.nii.gz &#8211;match 11 &#8211;o /Applications/freesurfer/subjects/{subjectID}/mri/left_caudate.nii.gz</p>
<p>You actually can run that command with the basic aseg.mgz (and thus skip the mri_label2vol step above) but I wanted to show both. I&#8217;d recommend using mri_label2vol for binary mask creation but for subcortical structures it shouldn&#8217;t matter. Running this conversion both ways (mri_label2vol and mri_binarize) results in a perfect mask overlap (the blue and red caudates &#8211; one from each method &#8211; appear purple in this screenshot).</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/10/FSLView-3.1.8-Ortho-view.png"><img class="aligncenter size-medium wp-image-157" title="caudate_conversion_overlap" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/10/FSLView-3.1.8-Ortho-view-239x300.png" alt="" width="239" height="300" /></a></p>
<p>Now say you wanted to make a mask a little bit bigger or a little bit smaller (to either pick up surrounding voxels or to exclude part of a mask). You can use mri_binarize to do that (you could even do this with the step above, I&#8217;m separating it out for simplicity):</p>
<p>mri_binarize &#8211;i /Applications/freesurfer/subjects/{subjectID}/mri/left_caudate2.nii.gz &#8211;erode 1 &#8211;match 2 &#8211;o /Applications/freesurfer/subjects/{subjectID}/mri/left_caudate3.nii.gz</p>
<p>In that command I input (&#8211;i), erode 1 voxel in 3D (&#8211;erode 1) from the left caudate (&#8211;match 2; that is a 2 because I created this binary mask earlier and gave the left caudate a value of 2), and then specify an output (&#8211;o).</p>
<p>Here you can see the results (visualization in FSLView, which I&#8217;m not overly fond of but it makes viewing mask overlap very easy):</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/10/caudate_fslview.png"><img class="aligncenter size-medium wp-image-158" title="caudate_fslview" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/10/caudate_fslview-300x160.png" alt="" width="300" height="160" /></a></p>
<p>As you can see, the eroded caudate is one voxel smaller in 3D than the original caudate.</p>
<p>You can created a summed overlap file (or combine any mask files in the same space together) by using fslmaths (you can also do this with the mri_binarize &#8211;merge option but I&#8217;m just introducing a range of tools):</p>
<p>fslmaths {input file} -add {adding file} {output}</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2010/10/freesurfer-tools-mask-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash For Loops (Plus a Little Scripting)</title>
		<link>http://brainybehavior.com/neuroimaging/2010/09/bash-for-loops-plus-a-little-scripting/</link>
		<comments>http://brainybehavior.com/neuroimaging/2010/09/bash-for-loops-plus-a-little-scripting/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 02:00:15 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA["for loops"]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=134</guid>
		<description><![CDATA[I&#8217;ve written about Bash scripting previously, as it applies to neuroimaging. Scripting is extremely useful; it can save hours worth of work. But what if you want to do something that is repetitive but do not really need to create &#8230; <a href="http://brainybehavior.com/neuroimaging/2010/09/bash-for-loops-plus-a-little-scripting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written about <a href="http://brainybehavior.com/neuroimaging/2010/08/bash-scripting-for-neuroimaging/">Bash scripting previously</a>, as it applies to neuroimaging. Scripting is extremely useful; it can save hours worth of work. But what if you want to do something that is repetitive but do not really need to create a script? This is where the <em>for </em>loop is useful.</p>
<p>First I will start with a more complicated example before I get to the <em>for</em> loop. This one requires a little bash scripting. You have a problem, you want to create 400 subject directories (don&#8217;t ask me why, I&#8217;m just providing an example) but don&#8217;t want to create them one by one. A simple script could save a lot of time:</p>
<blockquote><p>#!/bin/sh</p>
<p>t=0 #this specifies a starting value</p>
<p>read -p &#8220;How many subject directories would you like to create? &#8221; SUBS ;</p>
<p>let SUBS1=${SUBS}+1 #creates a new variable (SUBS1) that is one value greater than the input</p>
<p>condition ()</p>
<p>{</p>
<p>((t++))</p>
<p>if [ $t -lt ${SUBS1} ]</p>
<p>then</p>
<p>return 0  # true</p>
<p>else</p>
<p>return 1  # false</p>
<p>fi</p>
<p>}</p>
<p>read -p &#8220;Enter the full path (no trailing /) to the directory where you would like to create the directories: &#8221; SUBSDIR</p>
<p>while condition</p>
<p>#     ^^^^^^^^^</p>
<p>#     Function call &#8212; ${SUBS1} loop iterations.</p>
<p>do</p>
<p>mkdir ${SUBSDIR}/sub${t} ; #The &#8220;sub&#8221; could be changed to whatever you want the prefix to be (e.g., blind, subject, con, exp).</p>
<p>done</p></blockquote>
<p>This script was modified from one on <a href="http://tldp.org/LDP/abs/html/loops1.html" onclick="pageTracker._trackPageview('/outgoing/tldp.org/LDP/abs/html/loops1.html?referer=');">this site</a> (about bash loops) with input from <a href="http://www.linuxconfig.org/Bash_scripting_Tutorial#17-1-bash-addition-calculator-example" onclick="pageTracker._trackPageview('/outgoing/www.linuxconfig.org/Bash_scripting_Tutorial_17-1-bash-addition-calculator-example?referer=');">this site</a> (about bash mathematics). I created that script even though you (or I) probably will not use it very much or at all; it is useful for showing a quick way to create a lot of consecutively numbered directories somewhere on your computer. This script also can be modified as needed in order to do similar functions. I actually only wrote the script so I would have a list of directories to use for this example. Here is the result of the script:</p>
<p style="text-align: center;"><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/09/subjects_dir_screen.png"><img class="aligncenter size-full wp-image-135" title="subjects_dir_screen" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/09/subjects_dir_screen.png" alt="" width="546" height="247" /></a></p>
<p>Now I will move on to the real purpose of this post: not scripting but <em>for</em> loops.</p>
<p>Let&#8217;s say that you want to create a <em>labels </em>directory within a series of subjects&#8217; FreeSurfer directories (or anywhere else). We can pretend that those subjects directories I created above are my FreeSurfer subjects. For this we do not need to write a whole script; a simple for loop will suffice.</p>
<p>First cd to your FreeSurfer subjects directory &#8211; e.g., <em>cd /Applications/freesurfer/subjects</em></p>
<p>Then create a text file with the list of subject directories you want to deal with: <em>ls &gt;&gt; blinds.txt</em></p>
<p>Next, open that file to remove any unwanted items: <em>open -a TextEdit blinds.txt</em></p>
<p>After it only contains a list of the subjects you are ready to save it, close it, and proceed.</p>
<p>Now we are ready to use a for loop to create a bunch of directories called <em>labels </em>(one within each FreeSurfer subjects directory):</p>
<p><em>for blind in `cat blinds.txt`; do mkdir /Applications/freesurfer/subjects/${blind}/labels; done</em></p>
<p>That&#8217;s it. Pretty simple! A <em>for</em> loop requires a <em>for</em>, a <em>do</em>, and a <em>done</em>. The semi-colons ( ; ) are required when running a multi-step command like this on a single line.</p>
<p>Here is a screenshot of what my subjects directory (pretend this is my FreeSurfer subjects directory) now looks like:</p>
<p><a href="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/09/labels_folders_subjects.png"><img class="aligncenter size-full wp-image-139" title="labels_folders_subjects" src="http://brainybehavior.com/neuroimaging/wp-content/uploads/2010/09/labels_folders_subjects.png" alt="" width="605" height="466" /></a>Also notice the blinds.txt file that I created by listing the subjects directory and saving that output to a text file (which I then edited).</p>
<p>That is one example of a simple <em>for</em> loop. Any repetitive task that we can use bash for can be put in a simple loop like that. Here is another example using a FreeSurfer command (all the dashes are double dashes): <code>for blind in `cat blinds.txt`; do mri_annotation2label --subject ${blind} --hemi lh --outdir labels; done</code></p>
<p>Or, you could copy a number of files from one location to another: <code>for blind in `cat blinds.txt` ; do mkdir /my_new_imaging_directory/${blind} ; cp ./${blind}/${blind}_T1.nii.gz /my_new_imaging_directory/${blind}/${blind}_T1.nii.gz ; done</code></p>
<p>That loop is slightly more complicated, it has a couple commands in the <em>do</em> part. First, I make a series of new target directories (you wouldn&#8217;t need to include that if the target directories exist already): mkdir&#8230; ; then, I copy images from one location to another: cp &#8230;. A command like this is useful in a script if you want to create temporary files to process further and then remove. I like to create copies of files so I do not accidentally and permanently alter the original images. Just make sure you remove the temp files when you are done or you will end up with a lot of redundant files.</p>
<p>Looping is one reason why it is important to be consistent in labeling files and directories. Name directories that make sense; keep all your images and files organized. If you are consistent, you can throw a simple <em>for </em>loop together and save a lot of time without having to write a script. I use loops at least weekly but I create or use scripts less often.</p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2010/09/bash-for-loops-plus-a-little-scripting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An Introduction to the Cingulum</title>
		<link>http://brainybehavior.com/neuroimaging/2010/09/an-introduction-to-the-cingulum/</link>
		<comments>http://brainybehavior.com/neuroimaging/2010/09/an-introduction-to-the-cingulum/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 03:38:15 +0000</pubDate>
		<dc:creator>Jared Tanner</dc:creator>
				<category><![CDATA[Fiber Tracking]]></category>
		<category><![CDATA[cingulum]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[fiber tracking]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://brainybehavior.com/neuroimaging/?p=126</guid>
		<description><![CDATA[I created this brief video of the cingulum. I am posting it here because it showcases some of the diffusion scan fiber tracking we do. The brain is that of a &#62;60 year old male who is part of our &#8230; <a href="http://brainybehavior.com/neuroimaging/2010/09/an-introduction-to-the-cingulum/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I created this brief video of the cingulum. I am posting it here because it showcases some of the diffusion scan fiber tracking we do. The brain is that of a &gt;60 year old male who is part of our study looking at patients with Parkinson&#8217;s disease. Visualizations were done with FreeSurfer and TrackVis.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="620" height="490" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/8TAmyOAkCz8?fs=1&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="620" height="490" src="http://www.youtube.com/v/8TAmyOAkCz8?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://brainybehavior.com/neuroimaging/2010/09/an-introduction-to-the-cingulum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

