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.
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.
Just like with task-fMRI, before you can run single-subject resting-state analysis you first need to prepare the necessary images:
BET
) to use for registrationBET
)fsl_prepare_fieldmaps
).
See the Registration Practical for further details.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.
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):
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:
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.
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.
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.
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
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
.
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.
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.
fslinfo
command to do this and then check by viewing the html report (firefox filtered_func_data.ica/report/00index.html
)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.
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).
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
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 &
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.
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.
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.
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.
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?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
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.
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
has already been run on the Rest_EPI.ica data using the following command:
fix Rest_EPI.ica training.RData 30 -m
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
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
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.
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.
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.
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:
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
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
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.
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.