Session 10 - fMRI NiLearn Flashcards
What command do you use to clone the relevant git repository for the fMRI analysis?
!git clone -b s7_fmri –single-branch https://vcs.ynic.york.ac.uk/cn/pin-material.git
What command do you use to install Nilearn, a required module for fMRI analysis in Colab?
!pip install nilearn
How do you change the directory to ‘s7_fmri’ in a Python script?
import os
os.chdir(‘/content/pin-material/s7_fmri’)
We have now seen the main methods for loading and saving MRI and fMRI data in Python and we have performed a simple frequency domain analysis.
We needed … to do this
We just needed the nibabel nib.load() function to get data into numpy.
What type of file is “filtered_func_data_MNI3mm.nii.gz” typically used for in fMRI analysis?
It is typically used as the preprocessed functional MRI (fMRI) data, often after spatial normalization to a standard brain template (MNI3mm).
Command that sees ‘filtered_func_data_MNI3MM.nii.gz
We are going to move onto how to do some analysis of fMRI data in a more modern way using a module called
nilearn
nilearn comes from a same family of neuroimaging software as nibabel and implemenets
a whole bunch of fMRI analysis tools from simple to complex.
Nilearn works with other modules and uses
a cool statistics and machine learning package called Scikit-Learn (sklearn: SKL) to do all sorts of fancy 21st-centure machine learning things.
Nilearn contains routines for performing
he standard univariate analyses that we show you at YNiC
What module is used for fMRI analysis in a modern manner, integrating with Scikit-Learn?
Nilearn
Describe the experimental design used in the example provided in notes for applying nilearn, including the duration, TR, trial types, and characteristics of each trial type - (4)
The experiment lasted 320s with a TR of 2.0s, resulting in 160 volumes of data.
It involved two trial types, Hand movement, and Visual flickering grating, running simultaneously.
The Hand movement condition comprised 16s of finger movement followed by 16s of rest, starting at 6s into the experiment.
The Visual flickering grating appeared on the screen at 0s, stayed on for 10s, off for 10s, and then repeated.
Summary of experiment used for nilearn - hand movement and visual grating
To summarise, our experiment involved the following timeline, shown for the first minute of the experiment. + in the table below means that the given stimulus is ‘on’.
The hardest part of any fMRI analysis is telling the analysis software
what event happened, when it happened and how long they lasted
Often, the hardest part of any fMRI analysis is telling the analysis software what event happened and when. And how long they lasted.
It’s easy to get this wrong - as…
for example, by forgetting to take into account offsets in the fMRI start times, mistaking the length of the TRs or using the wrong stimulus files
If you are ever sitting in front of a ‘failed’ fMRI analysis, first check your
event files!
What format does Nilearn require for describing stimuli, and what are the necessary components? - (3)
Nilearn requires stimuli to be described in a ‘TAB separated file’ (TSV) format.
The necessary components include the onset time of the events (in seconds), the type of event (trial_type), and the duration of each event.
Wants these values in columns
What would our TSV file look like for our hand movement and visual grating experiment?
TSVs are just like CSVs except the columns are
separated by tabs (\t).
We can read TSV file into
a Pandas dataframe and pass it directly to the fMRI analysis code.
First step in producing TSV file for an experiment of hand duration and vision duration is that - (3)
We will use pandas to generate a nice structure to hold the information (a table with the names, onsets and durations)
Pandas can then write that table directly to disk.
. We will also define the hand and vision stimulus durations as variables at the start - Then, if we need to change them for some reason (perhaps to analyze another dataset) we only have to change those lines.
Second time in constructing TSV , after constructing duration, is the
constructing variables containing a list of onset times
Second step of TSV
Constructing onset times for hand movement which said Constructing onset times for hand movement which said where the condition starts at 6 seconds into the experiment and alternates every 32 seconds. Each cycle consists of 16 seconds of activity followed by 16 seconds of rest. :
hand_duration = 16s
explaining this code - (2)
The ‘range()’ function is used to generate a list of onset times, starting at 6 and ending before 320 (the duration of the experiment), with a step size of ‘hand_duration * 2’.
Since ‘hand_duration’ is 16 seconds, ‘hand_duration * 2’ equals 32 seconds, ensuring the desired alternating pattern of 16s on and 16s off.
What would be output?
Second step of TSV
Constructing onset times for visual grating - which
starting at 0s and alternating every 20s (10s on, 10s off)
explain this code - (2)
vision_onsets = list(range(0, 320, vision_duration*2))
vision_duration = 10s
The ‘range()’ function is used to generate a list of onset times, starting at 0 and ending before 320 (the duration of the experiment), with a step size of ‘vision_duration * 2’.
Since ‘vision_duration’ is 10 seconds, ‘vision_duration * 2’ equals 20 seconds, ensuring the desired alternating pattern of 10s on and 10s off.
What would be output of this code?
After constructing onset and duration variables for hand movement and visual we need to make
two Pandas dataframes - One is for the hand movements, the other is for the vision things.
ithin each data frame we keep the same ‘duration’.
Third step producing pandas dataframe
Explain the creation of the dataframe for the Hand Movement condition - (2)
We create a dataframe using Pandas from dictionary type key (value-pairs), where each row represents a trial of the Hand Movement condition.
The dataframe consists of three columns: ‘trial_type’, indicating the type of trial (hand_movement); ‘onset’, containing the onset times calculated previously; and ‘duration’, representing the duration of each hand movement trial (calculated hand_onset and hand_duration previously)