Goal:Effectively implement fMRI batch first-level analysis for the Despicable Me data for the subset of participants assigned to you. “Effectively” means quality checking intermediate steps.
Instructions: There are 100 participant folders in the data/RBC/HBN_BIDS/folder. Several are assigned to you in this csv file 3first-level_analysis/homework/first-level_analysis/subject_assignment.csv
Deliverables: This document edited to include
Commented code describing each step.
Visualizations and commentary, as requested specifically, below.
All the output from your preprocessing steps included in the participant’s folder on the Box drive.
Hint: This file is located at 3first-level_analysis/homework/first-level_analysis/first-level_analysis.qmd
Code
sites =read.csv('/Users/vandeks/Library/CloudStorage/Box-Box/SMN/3first-level_analysis/homework/first-level_analysis/subject_assignment.csv')# all my subjectIDssimonsSubjects = sites[which(sites$student=='Simon'),'subject']# sites for all my participantssimonsSites = sites[which(sites$student=='Simon'),'site']write.table(simonsSubjects, file ='simonsSubjects.txt', row.names=FALSE, col.names=FALSE, quote=FALSE)
Batch brain extraction (20 pts)
After our last class, we found that fsl_anat worked most consistently for preprocessing the structural image. Run bias correction and brain extraction on your full subset of images to get the output you need as input for FEAT. You can work in a group or as a class to write a batch script, or you can share code to do this.
Code
# runs anatomical preprocessingfor i in$(cat simonsSubjects.txt);doanat=$(ls /Users/vandeks/Library/CloudStorage/Box-Box/SMN/data/RBC/HBN_BIDS/${i}/*/anat/*T1w.nii.gz);echo"Processing subject $i";;fsl_anat-i$anat--clobber;done
Write a loop in R in this document to create a visualization of one or a couple slices for each participant to quality check the brain extraction and add it to this document to be submitted as an html. Hint: There are some participants missing anatomical images – if that’s the case, you have to make sure to skip the person who is missing a structural (T1) image.
Code
# nifti imagesfor i in$(cat simonsSubjects.txt);dols /Users/vandeks/Library/CloudStorage/Box-Box/SMN/data/RBC/HBN_BIDS/${i}/*/func/*task-movieDM_bold.nii.gz;done
Start the FSL GUI from the command line by typing fsl and then open the FEAT fMRI Analysis (you can also do this directly typing Feat_gui at the command line). Open the .fsf file you produced from your last homework and set it up to perform the statistical analysis for the Despicable Me data. All the prior settings you used before loaded in. List all the 4D Nifti images for your subjects here. Also list all the brain-extracted structural images, here.
Hint: On my laptop, when I change the tab in the FEAT GUI, all the buttons disappear; if you adjust the window size, they reappear.
Do these things:
Set the temporal filtering high-pass filtering to 130 seconds.
Delete 6 initial volumes.
Set the spatial smoothing FWHM to 5mm.
Make sure you have the right slice timing file. This should be the same for all participants you are analyzing. It’s different by site.
Use linear registration from the T1 (structural) image to the MNI template. Uncheck the nonlinear registration box.
Select all 4D Nifti images for the subset of participants you are analyzing. You created this list above.
Leave output directory blank.
Select all brain-extracted structural images for the subset of participants you are analyzing. Hint: They have to be in the same order as the 4D fMRI images. You created this list above. Make sure they are in the exact same order as the
Include the standard motion covariates.
Use the event files I showed in class – they delete six volumes. Include the temporal derivative and apply temporal filtering to the event file. Use the double gamma HRF.
Include a screenshot of your design in here, in your html submission.
Run the analysis. Hint: You might want to run it for one person and check the output. Then run it for everyone in your subset and run it overnight.
Deliverables (10 pts)
Registration QA
Write a loop or lapply command to print all the functional-to-standard registration images (“Registration of example_func to standard”) into this document. Include the subject ID in the output so you can identify who they belong to. Hint: They are stored in the participants .feat folder output in the mc folder and you can print from loops using results='asis' and cat to print the markdown syntax you need.
Create a list of participants whose registration is bad that we might exclude from analysis and output their subject IDs in this file.
Motion QA
Write a loop or lapply command to print all the motion plots (“MCFLIRT estimated mean displacement (mm)”) into this document. Include the subject ID in the output so you can identify who they belong to. Hint: They are stored in the participants .feat folder output in the mc folder and you can print from loops using results-'asis' and cat to print the markdown syntax you need.
Create a list of participants whose mean relative displacement is larger than 0.5mm. We will exclude those participants from the analyses.