Semi-autoMatic Artifact Removal Tool (SMART)

SMART was developed during my dissertation work at the University of Texas at Austin. The idea was to preprocess electroencephalogram (EEG) data that was collected while participants meditated with their eyes closed. EEG is infamous for getting easily corrupted by muscular and other artifactual sources of noise. Thus, we used a two step process of pre-processing EEG data. First, we used second-order blind source separation to find sources that were uncorrelated in time (hence second-order). Second, we developed a novel semi-automatic web-based tool (or SMART) to identify non-neural sources of artifact (e.g., muscular artifact, ocular artifact, and  interference by power lines).

The identification of artifacts was done in SMART by using three key pieces of information – topological, temporal (mainly auto-correlation function), and spectral structure of each component. Based on simple rules, first SMART identified sources as different kinds of artifacts. Followed by generating a web-based tool, so that the researcher can quickly and efficiently go over all the components and their corresponding properties to judge whether SMART correctly classified the source under consideration as noise or not. If not, then the researcher can override source’s classification by clicking a radio button. The screenshot below better portrays the point.

The source code is provided here. For more information on the SMART tool, please see the following references. Also, if you use this tool in your research, please cite these as well.

  1. Saggar M, et al. (2012) Intensive training induces longitudinal changes in meditation state-related EEG oscillatory activity.   Front. Hum. Neurosci. 6:256. doi: 10.3389/fnhum.2012.00256
  2. Saggar, M. (2011) Computational analysis of meditation. Retrieved from University of Texas Digital Repository: Electronic Theses and Dissertations, (Austin, TX), Pages: 24-44.

NOTE: SMART for other imaging modalities (fMRI and fNIRS) is under testing and will be released very soon.

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

Renaming multiple files in Unix (or Mac)

Say you have all your files named ABC_something_numbered.nii.gz and you want to rename all these files as ABC_somethingelse_numbered.nii.gz. Here is how you can achieve that in a single command

for f in ABC_*; do mv “$f” “${f/something/somethingelse}”;done

Note: if you have the rename package installed, you can use that instead.

Hope that helps!

Posted in Uncategorized | Tagged , , | Leave a comment

Using Parallel Computation Toolbox from Matlab

If you have the Parallel Computation Toolbox (PCT) from Matlab, you can use its power and ease of use to run neuroimaging analysis in parallel. Read more here and here for more information on this toolbox. The trick is to use multiple CPU cores on your machine for running analysis in parallel. For example, when I am running some analysis on every participant, I can use PCT to launch the analysis on 6-8 participants in parallel, which cuts down the run time to about 5 times or so.

To use this toolbox, first open the matlab pool as follows

matlabpool open  % to use all the available CPU cores OR

matlabpool open 2 % to open just two of them

Then just  change the for loop (e.g., over each participant) to

parfor p = 1:1:npart

% calculation here

end

And closing the pool in the end,

matlabpool close;

 

Hope that helps!

Posted in matlab, unix | Tagged , , | Leave a comment

Cool Python tutorials by Google

Check out  Google’s Python Classes – very easy and neat way of learning Python for all kinds of beginners (especially Neuroimagers – since Python is the future :D ). These classes were taught by Nick Parlante  – Many thanks to Nick :)

I have embedded the videos below (from YouTube) for ease and here is the link to the exercises (as referred in the tutorials)

Tut 1 – Introduction, strings

Tut 2 – Lists and sorting

Tut 3 – Dicts and files

Tut 4 – Regular expressions

Tut 5 – Utilities

Tut 6 – Utilities urllib

Tut 7 – Conclusions

Posted in unix | Tagged , , | 1 Comment

Running FSL commands from Matlab

Yes, you can run FSL from Matlab. Here is how – two step process for me (but it could be more efficient, if need be):

(a) First, launch Matlab (assuming on a Mac) from a terminal that is already setup for FSL (see here for more info)

/Applications/<matlab_folder>/bin/matlab &

(b) Second, at the beginning of your Matlab script, add the following lines of code. This way Matlab knows where does FSL exist,

    % set FSL environment
setenv(‘FSLDIR’,'/usr/local/fsl’);  % this to tell where FSL folder is
setenv(‘FSLOUTPUTTYPE’, ‘NIFTI_GZ’); % this to tell what the output type would be

That’s it and you can launch any FSL command as follows,

cmd = ‘/usr/local/fsl/bin/feat design.fsf’;
system(cmd);

Hope that helps!

Posted in fmri, fsl, matlab | 1 Comment

Brain extraction using FSL (BET)

In order to register functional MRI data on to the high-resolution structural image, one first needs to extract the brain out of the structural image (aka skull stripping). I usually use BET tool (provided by FSL) for the same. However, it sometime takes forever to adjust parameters (f and g) to get the best results out. Especially, in cases where the lower half of structural image is noisy. To solve the problem and save time, I have found that pre-masking the structural images to standard space brain usually helps. So run this command before running your regular bet command will help,

standard_space_roi <input> <output> -b

Then run the BET command (usually with very liberal f-values) works beautifully, e.g.,

bet <input> <output> -f 0.15

Hope that helps!

Posted in fmri, fsl | Leave a comment

Running fslview in Ubuntu 11.10 using Chroot

Follow the amazingly helpful and life-saver set of steps listed here: Chroot workaround for fslview

Kudos to the author!

 

 

Posted in fmri, fsl, unix | Leave a comment

Simple perl command for replacing text inside files

For one file
perl -p -i -e "s/<orig>/<new>/g" <filename.txt>
Or multiple files
perl -p -i -e "s/<orig>/<new>/g" *.<filetype>

							
Posted in fmri, unix | 1 Comment

A cool way to display FSL results

If your fMRI results (using FSL) are in MNI space, you can use the following Freesurfer command to get beautiful figures for presenting your results.

For right hemisphere:

tksurfer fsaverage rh inflated -overlay <thresh_zstat_imagename>

For left hemisphere:

tksurfer fsaverage lh inflated -overlay <thresh_zstat_imagename>

Results:

Note:

This is an approximation and only for display purposes, but it works (without registration) since the fsaverage brain is in MNI space as well.

Posted in fmri | 3 Comments