ICA Practical

Independent Component Analysis (ICA) is a tool that we can use to decompose FMRI data into spatially independent components, with each component represented by a spatial map and a time course.

We can use ICA at the single subject level to separate out true neuronal signal from noise, and use ICA at the group level to identify whole brain resting state networks (RSNs) that are common across the group.

Melodic is the tool in FSL that we use at both the subject and group level to decompose FMRI data into time-courses and spatial maps using ICA.

Contents:

Running single-subject ICA
Setting up and running ICA at the single-subject level.
Classifying and removing noise components from single-subject ICA
Manual and automated classification of ICs as signal or noise.
Registering cleaned single-subject data to the standard space
Aligning clean data to a common space ready for group level analysis

In the next sections, you will first see how to set up and run single-subject ICA, then use single-subject components to classify and remove noise, and use some scripting to register cleaned data to the standard space ready for group analysis. We will cover group ICA in the next practical.


Running single-subject ICA

Preparing for the single-subject ICA

Just like with task-fMRI, before you can run single-subject resting-state analysis you first need to prepare the necessary images:

Single-subject ICA via the MELODIC GUI

MELODIC has a simple GUI that has been structured to be similar to the FEAT GUI. The MELODIC GUI will allow you to apply the necessary pre-processing and ICA options.

G 1 input image - raw resting 4D fmri 6 melodic 1->6 2 alternative reference image - high contrast volume (if multi-band) 2->6 3 fieldmaps - mag_brain and fmap_rads (if using) 3->6 4 structural - brain extracted 4->6 5 standard - MNI brain 5->6 7 report.html 6->7 8 /filtered_func_data.ica 6->8 9 filtered_func_data.nii.gz 6->9 10 ... 6->10

Take a look at an example data directory:

cd ~/fsl_course_data/rest/ICA/single_subject/sub-control01

To set up the preprocessing and single-subject ICA, you would load in the following images (just as for task fMRI):

When would you use a high-contrast alternative reference image? What is the purpose of this image?

Can you identify the files listed above in the folder? Check your answer here

Open the Melodic GUI (Melodic_gui from MacOS) to see the similarity to the Feat GUI.

Click through the GUI and enter each of the images in the right place. Check with a tutor if you are not sure.

The recommended Pre-processing and Registration choices for single-subject resting-state analysis are largely the same as for task-fMRI, e.g. use MCFLIRT motion correction and FNIRT for non-linear registration(Note: You can find the additional information in B0_unwarping_info.txt. Leave other options as default). However, the following pre-processing choices should be considered when running single-subject ICA:

Running the ICA

To set the GUI to run a single-subject ICA, go to the Stats tab and select Single-session ICA from the dropdown list. You can also choose whether to Variance-normalise the timecourses or use Automatic dimensionaity estimation. Leave them both on as default.

What does "Variance-normalise the timecourses" do? Why should this be turned on as standard for single-subject ICA ? Answer

What does "Automatic dimensionality estimation" do? Why should this be turned on as standard for single-subject ICA? Answer

For single-subject ICA, the Post-stats tab can be left as default (Post-stats options do not affect the output of single-subject ICA, only the rendering of images in the report.html).

As the preprocessing and single-subject ICA would take too long to run in the practical today, just Save the settings in an .fsf file in the working directory. We have already run all the single-subject ICA on the data you will use for the rest of the practical.

Single-subject ICA via the FEAT GUI

You can also run the preprocessing and single-subject ICA via the Feat GUI by selecting Preprocessing from the top right drop-down list and selecting MELODIC ICA data exploration in the Pre-stats tab. This will run single-subject ICA with automatic dimensionality estimation.

Open the Feat GUI to work out how you would run the single-subject ICA. Ask a tutor if you are not sure.

Single-subject ICA via the command line

Unlike for other FSL tools, the melodic command line is NOT equivalent to the GUI.

The command line only performs ICA decomposition, while running MELODIC via the GUI will call different preprocessing steps and then use the melodic (command line) tool to perform ICA decomposition. Similarly, the FEAT GUI runs preprocessing and then can calls melodic command line to perform ICA decomposition.

Also, note that the MELODIC GUI only allows you to change the basic options for ICA decomposition. Get familiar with the options of the command line version to get full control over the ICA decomposition:

melodic --help
What would be the input file (-i) of the melodic command line, assuming we have already run the basic preprocessing steps?

Can you think of an example where you would run melodic through the command line instead of the GUI?

Output of MELODIC single-subject ICA

We have run single-subject ICA via the FEAT GUI for you on a set of 12 subjects, including six patients with a tumour (~/fsl_course_data/rest/ICA/sub-0???) and six healthy controls (~/fsl_course_data/rest/ICA/sub-control0???). We are grateful to Natalie Voets for providing the datasets.

Change directory to look at the content of one of these subjects' /*.feat directory.

Many of the output images will be familiar from task-fMRI analysis, e.g. example_func.nii.gz, filtered_func_data.nii.gz and report.html.

Can you remember what the example_func.nii.gz and filtered_func_data.nii.gz images are? Check your answers with your neighbour.

Please note: These single-subject data have already been 'cleaned' (explained in the next section). The *_clean.nii.gz and labels.txt files are NOT automatically generated in the single-subject ICA.

Due to the fact that melodic has to make an initial guess about ICA decomposition, running melodic twice on the same data with the same settings can lead to small differences in the number and order of the estimated components.

The output from single-subjet ICA is the filtered_func_data.ica directory, which contains all output related to running MELODIC. Go into the filtered_func_data.ica directory and look at the contents.

The key output in this directory is the melodic_IC.nii.gz, which is a 4D image where each volume is a component generated in the single-subject ICA.

How many components this subject's data has been decomposed into? Use the fslinfo command to do this and then check by viewing the html report (firefox filtered_func_data.ica/report/00index.html)

Classifying and removing noise components from single-subject ICA

The primary purpose of running single-subject ICA is to clean the single-subject data, by identifying and removing components relating to artefacts (e.g. motion, physiological noise). Among the filtered_func_data.ica/melodic_IC.nii.gz components we want to identify those relating to noise and remove them from the pre-processed 4D resting fMRI data (filtered_func_data.nii.gz) to produce a 'clean' version of the preprocesed data (filtered_func_data_clean.nii.gz). This process can be done manually or using an automated method. In this section you will learn how to do it in both ways.

Manual IC classification

In this part of the practical you are going to label ICA components as either signal or noise.

To do this you need to look carefully at three pieces of information for each component: 1) the spatial map, 2) the time course, and 3) the power spectrum of the time course. Take a look at the example spatial maps, time courses and power spectra for 'good' (signal) and 'bad' (noise) shown in the Figure below (the spatial maps shown are all noise components).

Figure 1 Figure 2
Discuss with your neighbour what you are looking for in each of the following sources of information to determine whether an ICA component is of neuronal origin?
  • The spatial map
  • The time course
  • The power spectrum

To get an understanding of the influence of data quality and quantity on the performance of ICA, you are going to take a look at two examples - one using multi-band data, one using non-multiband EPI data. We will use FSLeyes in Melodic mode to simultaneously show the spatial map, time course and power spectrum for each component.

cd  ~/fsl_course_data/rest/ICA/IC_classification

Manual labelling of multi-band fMRI

In the first example, we have provided the components from a single-subject ICA run via the FEAT GUI on a 15-minute run of multiband data. No smoothing was applied during preprocessing.

First, load the Rest_MB6.feat/design.fsf in the FEAT GUI to see how the single-subject preprocessing and ICA was run for this subject.

Close the FEAT GUI and open the single-subject ICA output in FSLeyes:

fsleyes --scene melodic -ad Rest_MB6.feat/filtered_func_data.ica &
Before loading in the labels.txt file, make sure melodic_IC is selected in the overlay list.

Click on the Load labels button in the label panel on the right of the FSLeyes window, and select the labels.txt file from the Rest_MB6.feat directory. You will be shown a message saying the label file does not refer to the melodic directory, which is because we renamed it - click on Apply the labels to the current overlay. You will now see labels for all the components except for ten which are labeled as Unknown (in yellow).

Please have a look at the 10 Unknown components and label each one as either Unclassified noise or as Signal (note that FSLeyes allows you to include more informative labels if you wish). Once you have classified all of the components, please save your results by overwriting the labels.txt file and close FSLeyes.

Manual labelling of EPI fMRI

In the second example, we have provided the components from a single-subject ICA run via the MELODIC GUI on an older EPI dataset that has fewer timepoints and bigger voxel size. Some smoothing has been performed during preprocessing of this dataset.

First, load the Rest_EPI.feat/design.fsf in the MELODIC GUI to see how the single-subject preprocessing and ICA was run for this subject.

You can label components in any way you wish, and you can even assign more than one label to a component. But in the end, any component which does not have a label of Signal or Unknown will be treated as a noise component, and will be regressed from the data set in the following step, using fsl_regfilt.

Close the MELODIC GUI and open the single-subject ICA output in FSLeyes:

fsleyes --scene melodic -ad Rest_EPI.ica/filtered_func_data.ica &

Load the labels.txt file (inside Rest_EPI.ica) in the same manner as before, and classify the 10 Unknown components. Again, save the results by overwriting labels.txt and close FSLeyes.

Removal of noise components with fsl_regfilt

You will now manually "clean up" the EPI data example by removing the components that you classified as noise from your data. This is done using fsl_regfilt, which will regress the time courses of the noise components from the data.

G 1 fsl_regfilt 5 output filename (-o Rest_EPI.ica/filtered_func_data_clean.nii.gz) 1->5 2 input image (-i Rest_EPI.ica/filtered_func_data.nii.gz) 2->1 3 ICA timeseries (-d Rest_EPI.ica/filtered_func_data.ica/melodic_mix) 3->1 4 list of noise component numbers (-f 1,2,3 ...) 4->1

The help information from fsl_regfilt explains what the command does: "Data de-noising by regressing out part of a design matrix using simple OLS regression on 4D images". In our case, what does the design matrix contain?
Incorrect! Remember that this is resting state data, so there are no task regressors!
Correct! The timeseries from the components that are labelled as noise will be regressed out of the dataset.
Incorrect! This is a single-subject ICA analysis, so there are no subject labels at this point.

To manually remove the noise components from the Rest_EPI.ica data, first we need to get a list of IDs of the noise components:

tail -1 Rest_EPI.ica/labels.txt
What did this UNIX command do?

Now we can pass this list of numbers to fsl_regfilt (important: in the command below, replace 1,2,3 with the output of the above command, making sure to remove the square brackets from the terminal output and include the quotes '' in the command):

fsl_regfilt -i Rest_EPI.ica/filtered_func_data.nii.gz \
            -d Rest_EPI.ica/filtered_func_data.ica/melodic_mix \
            -o Rest_EPI.ica/filtered_func_data_clean.nii.gz \
            -f "1,2,3"

Make sure you understand what each of the command's flags do. If not sure, check the help and/or ask a tutor.

The cleaned and pre-processed data is located at Rest_EPI.ica/filtered_func_data_clean.nii.gz. If you open this file in FSLeyes, you may note that, visually, the data looks very similar to the original preprocessed data (Rest_EPI.ica/filtered_func_data.nii.gz). But you might see some subtle differences in the time courses for some voxels.



Automatic IC classification and noise removal

To avoid manual labelling of all the components for every single subject, tools have been developed to try automatically identify components that represent structured noise in fMRI data. We will take a look at two of these tools:

Now you are going to compare your own classification of signal and noise components for the EPI data to classifications done by FIX and by AROMA.

FIX classified components

FIX has already been run on the Rest_EPI.ica data using the following command:

fix Rest_EPI.ica training.RData 30 -m
In the FIX command-line call, the number 30 is a threshold between 0 and 100 - a lower value will result in more conservative clean-up (i.e. less chance of good components being removed), whereas a higher value will result in more aggressive clean up. The -m option tells FIX to regress motion parameters from the data, in addition to regressing noise components.

A key output of FIX is a .txt file that lists the classification of each component, and provides a comma separated list of noise ICs at the bottom. The name of the txt file is formatted as: fix4melview_‹training data›_thr‹threshold›.txt

Use the tail command to get a list of the components that were classified as noise by FIX, and compare them against your own results (what you passed to fsl_regfilt, above).

Click here to check the command to list the FIX-classified noise components.

AROMA classified components

AROMA has also already been run on the Rest_EPI.ica data using the following command:

python2.7 ICA_AROMA.py \
-in filtered_func_data.nii.gz \
-out AROMA \
-mc mc/prefiltered_func_data_mcf.par \
-affmat reg/example_func2highres.mat \
-warp reg/highres2standard_warp.nii.gz \
-md filtered_func_data.ica
If the single-subject ICA directory is not specified (with the -md or -meldir flag), AROMA will run ICA decomposition as well. See user guide for details.

The output of AROMA is in a directory /AROMA, and the identified noise components are listed in a text file classified_motion_ICs.txt

Use the cat command to get a list of the components that were classified as noise by AROMA, and compare them against your own results (what you passed to fsl_regfilt).

Click here to check the command to list the AROMA-classified noise components.

For the ten components that you classified (which were numbers 1, 13, 14, 24, 29, 33, 36, 37, 39 and 42) do your labels, the FIX and AROMA labels agree? Remember that the lists from FIX and AROMA contain all the components that were definitely labeled as noise. This means that the rest of the components were either labeled as Signal or as Unknown.

Note that FIX and AROMA also automatically regress out the noise components and produce the 4D cleaned data as part of the output (see the relative user guides for details), therefore there is no need to apply fsl_regfilt separately.


Registering cleaned single-subject data to the standard space

If you run group ICA via the MELODIC GUI, the GUI can apply the transformations/warps to align the single subject data to the standard space. HOWEVER, if you have applied cleaning at the single subject level (which is recommended!), you currently cannot use the MELODIC GUI to run the group ICA, because the GUI would use the un-cleaned images. Instead, as you will see in the next practical, you need to run the group ICA from the melodic command line on data already registered in standard space.

The clean preprocessed 4D resting state data produced by the steps above (filtered_func_data_clean.nii.gz) is still in the native subject space. In fact, the MELODIC/FEAT Registration settings at the single-subject level only generate the transformations/warps necessary to align the functional data to the standard space without applying them. Therefore, before moving on to the group analysis (next practical), the cleaned single-subject data needs to be aligned to the standard space by applying the transformations/warps.

Let's go back to our tumour patients (sub-0*) and controls (sub-control0*) inside ~/fsl_course_data/rest/ICA/ and align the filtered_func_data_clean.nii.gz to the standard space, using the applywarp command:

G 1 applywarp 5 output filename (-o filtered_func_data_clean_standard) 1->5 2 input image (-i filtered_fund_data_clean.nii.gz) 2->1 3 reference image (-r reg/standard.nii.gz) 3->1 4 transformation matix (--premat=reg/example_func2highres.mat) 4->1 6 FNIRT warp image (-w reg/highres2standard_warp.nii.gz) 6->1

Type applywarp to see the usage and work out how to run the registration of the cleaned data to standard space for subject sub-control01 using the transformations/warps generated when running the single-subject MELODIC. Check your answer here

Scripting

To save us manually registering each of our tumour patients and controls, we can run the following simple script from ~/fsl_course_data/rest/ICA/ to process all subjects simultaneously.

#!/bin/sh
for j in `ls -d */*_resting.feat` ; do
    applywarp -r ${j}/reg/standard.nii.gz \
              -i ${j}/filtered_func_data_clean.nii.gz \
              -o ${j}/filtered_func_data_clean_standard.nii.gz \
              --premat=${j}/reg/example_func2highres.mat \
	      -w ${j}/reg/highres2standard_warp.nii.gz
done
ls -1 */*_resting.feat/filtered_func_data_clean_standard.nii.gz >> inputlist_new.txt
Describe what each stage of this script is doing. What does the 'for j in...' section do? What does the -1 flag (that's the number one, not the letter 'l') to the ls command mean? More generally, what can you do to figure out what a given command, or a parameter to a command, is used for? Ask a tutor if anything is unclear.

The output of this script will be a standard space clean preprocessed 4D resting image for each subject (filtered_func_data_clean_standard.nii.gz) as well as a txt file (inputlist_new.txt), which contains a list of the filepaths to the filtered_func_data_clean_standard.nii.gz for each subject. This list is necessary for running the group ICA and the dual regression, which will be covered in the next practical.

This script makes some critical assumptions about how you have processed the fMRI data for each of your subjects. What are those assumptions?

The registration script above is also saved in the ~/fsl_course_data/rest/ICA/optional_script.sh directory. You can run it by typing (don't do this now, it takes around 20 mins to run):

sh ./optional_script.sh


The End.