3 Data management
In neuroimaging
General
State in 2022
Image credit: (Juavinett 2022)
BIDS
1. Psychopy
BIDS plugin for PsychoPy
Should be installed and enabled to save events (conditions and button presses) in a comprehensive and standardized manner.
This will also make our data analysis easier
Installation
Open psychopy and press “Get more” on the right side. Alternatively you can open “plugin/pachages manager” via “Tools” menue. Psychopy-plugin should be listed among the available plugins.
On the university computers, bids plugin is available through software center.
Experiment adjustment1
Thanks to
Lukas currently took over the BIDS plugin development.
Properties
- Experiment name will correspond to the task-[taskname] properety in the bids dataset. It is therefore useful to have a short name without capital letters. This did not work on my mac, but maybe this is an OS issue?
- Participant: switched from random code generator to 001. Since we keep the naming consistent with the MRI dataset, and have multiple runs, it is not useful to generate a new code on every run repetition
- Session: changed from 001 to 1. This is just our naming convention. Nobody has hundreds of sessions, so we do not expect a number with more than two digits.
Renaming?
File
Project folder
For the task label to work properly in the BIDS plugin, I also tried renaming the experiment file and the folder, but this did not help. Gambling is still spelled out with a capital “G” no mater what I do. Let’s stay tuned for the psychopy-bids updates.
Research question
What information do we actually need for analysis?
We should keep the research question in mind.
H1 is formulated as a one-way ANOVA with three pairwise post-hoc tests
H2 is formulated as 2x2 two-way ANOVA (at least we will simplify it to that)
Unique conditions
small win
small loss
large win
large loss
pass
trials.xlsx
For every trial, we should be able to identify whether it is win, loss or pass.
For every win or loss trial, we need to know if it is a win/loss with high stakes or with low stakes.
Note: right now we are not taking the win probability into account, but we know that it is always low for large stakes, and large for low stakes, so it is redundant.
Side note:
Ideal paradigm
Each trial type appears the same number of times
Carryover counterbalancing - each condition is equally likely to be preceded by each other condition (Brooks 2012)
Events of interest in a trial
gamble_trial or gamble_outcome?
Do we need key presses?
Adding bids events
Scanner trigger
I am not sure if it is needed after all, but I added a bids component to a routine that waits 10 seconds after the scanner trigger and logged its onset.
Linking to a routine # 1
In the BIDS Event Type field you can choose between TaskEvent and BehEvent. For now the difference does not matter much, let’s choose task event.
Linking to a routine #2
Right now time 0 in our experiment is the start of the welcome screen. We want time 0 to be the scanner trigger. Will take care of it later.
Adding bids events of interest
New variable outcome_trial
We need one variable to take 3 possible outcomes: win, loss or pass. Therefore, I adjusted the code, adding a variable “outcome_trial” for this purpose.
points_text
We are creating a bids event and linking it to points_text within the trial (because this routine appears on every loop interation).
Time stamp
Time 0 - scanning onset
Now we want to adjust the onset time to the scanner trigger arrival. This is done by ticking “Manually set values” and putting the difference between the onset of the current routine and the start of the blank period.
It would have been better and more accurate to subtract the actually key press time, but I ran out of time.
Other events
Here I added two other bids events that may or may not be useful, just in case: Trial onset and key press, including reaction times.
BIDS export
It is important to add the bidsExport routine at the end of the experiment.
- For fMRI, the data type should be “func”
- Choose. your favourite license
- Tick the box “Add Run Nubmers” - this should attach run numbers to the file names in bids format for every new run. I did not get it to work properly on mac (it was always run 1, overwriting the previous file). But supposedly it works on windows and linux.
Complete BIDS dataset
Example
This is how a complete dataset for fmri analysis should look like. You should have functional _bold.nii.gz files and _events.tsv files in one func/ folder.
2. DICOM to BIDS
Neurodesk
MRI data formats
DICOM - medical image format
- .dcm .ima or nothing at all
NIFTI - neuroimaging format we work with
- .nii or .nii.gz
bidscoin
Shell commands
#!/bin/bash
# you can copypaste the following commands into the terminal window that is opened by BIDSCOINER
# define directories
sourceFolder=/home/jovyan/completion2/dcm
sortedFolder=/home/jovyan/completion2/dcm_sorted
# check the output of the source folder
ls -l $sourceFolder
# make the target directory with subdirectories
mkdir -p $sortedFolder
# change to the script folder
cd /home/jovyan/dicomsort/
# run the script
./DICOMsort.sh $sourceFolder $sortedFolder
# check the output of the target folder
ls -l $sortedFolder
# run bidsmapper
bidsmapper $sortedFolder /home/jovyan/completion2/bids
# note: in the intendedFor of the fieldmap, add func/sub-001_ses-1_xxx_bold.*
# once you are happy with the mapping, run bidscoiner
bidscoiner $sortedFolder /home/jovyan/completion2/bids
bismapper
Currently, to discover the data we need to delete the content of the “subprefix” field and then save the bids map in the default location. After this, run the same bidsmapper command again.
Subject and session
Now the bidsmapper discovered everything, but the files are not named correctly.
Edit subject and session first.
Now we need to rename the files by clicking “Edit” next to every file.
Editing file names: anatomical
anatmprage -> mprage in the “acq” filed
Editing file names: functional
Edit the task name and acq field
Do this for every functional file
In the intendedFor of the fieldmap, add “func/sub-999_ses-1_task-completion_acq–noise_bold.*” with a wildcard. This will select all respective functional runs
Once you are happy, run bidscoiner to do the actual conversion
View files
MRICron
Now you can view the nifti files with any suitable software
3. Quality assurance
MRIQC
MRIQC (Esteban et al. 2017)is a tool used for quality assurance of bids-valid datasets. It is a bids app, meaning that it works on bids-conform data.
Running MRIQC
Should take around 10 minutes
Command line
# define relevant paths
bids_folder=/home/jovyan/gambling/bids/
mriqc_folder=/home/jovyan/gambling/bids/derivatives/mriqc/
# create mriqc directory
mkdir -p $mriqc_folder
# run mriqc
mriqc $bids_folder $mriqc_folder participant --participant-label 001
Output
You will see that there are html outputs for anatomical and functional scans. They can be viewed in a browser, without actually loading the images.
Anatomical
Noise
Actual image
This is useful to quickly identify problems with the data. A rating widget is also available, which is useful for large datasets.
Functional
For functional data, in addition to spatial noise (middle) and average image over time (right), there is a section showing temporal noise over time. Note how the values are highest in the eyes (due to eye movements) and in the center of the brain, due to blood pulsation.
Carpet plots for functional data
Carpet plot shows signal fluctuations over time (x-axis) for each voxel (y-axis). Note how there are some patterns initially and at the end. There should be no clear pattern during the experiment, this speaks for good signal quality.
References
valid for PsychoPy v2024.2.4↩︎