owned this note
owned this note
Published
Linked with GitHub
# MRI Analysis in Python
This is a collaborative scratchpad to shares resources related to the analysis and pre-processing of fMRI data. This notepad will be updated during the duration of the course!
## Neuroimaging Forum
[Neurostars](https://neurostars.org) is a community forum for asking questions specific to neuroimaging. You can use this as a resource if you have specific questions you'd like to ask the community about
## Workshop Resources
[**ATTENDENCE TEST**](https://support.scinet.utoronto.ca/education/mods/_standard/tests/test_intro.php?tid=200)
- [Setup Guide](https://docs.google.com/document/d/1KaKtm17ABOBce0vLBaIlwSsb4PPbdDJsueh1Cf67TpI/edit?usp=sharing)
- [Slides](https://docs.google.com/presentation/d/10y_padozF4URvHDzjwFFqhDFBmCLumz2Gfe_3K59Reg/edit?usp=sharing)
- [fMRIPrep Slides](https://oesteban.github.io/ohbm19/#1)
- [Git Repo](https://github.com/carpentries-incubator/SDC-BIDS-fMRI)
## Preprocessing Resources
These are all BIDS-compatible pipelines! Meaning that once your dataset is in BIDS format you can run these on your dataset quite easily!
- [fMRIPrep - pipeline for pre-processing fMRI data](https://fmriprep.org/en/stable/)
- [MRIQC - for basic quality assessment of BIDS dataset](https://mriqc.readthedocs.io/en/latest/)
- [Ciftify - for surface based analysis of fMRI data on any dataset](https://edickie.github.io/ciftify/#/)
- [HCPPipelines - for Human Connectome Project surface-based preprocessing](https://github.com/BIDS-Apps/HCPPipelines)
- Note that HCPPipelines is meant for HCP-like acquisitions, *it is not compatible with every dataset*! Use **Ciftify** for everything else!
## Analysis Resources
### General
- [Handbook of fMRI Analysis](http://www.leixulab.net/paper/2011HandbookfMRI.pdf)
- You can learn about some of the theory behind fMRI data analysis as told by some experts in the field
- [Mumford Brain Stats](https://www.youtube.com/c/mumfordbrainstats/videos)
- A series of Youtube tutorials on fMRI analysis. Many of the videos use FSL or SPM rather than Python but the concepts are still relevant.
- [Nilearn Tutorials](https://nilearn.github.io/auto_examples/index.html)
- You can find similar materials to what the course covers over here as well as more advanced material such as Machine Learning methods on neuroimaging data
- [MVPA Meanderings](http://mvpa.blogspot.com/)
- Excellent series of blog posts on various topics in fMRI neuroimaging analysis
- [Connectome Workbench (Advanced)](https://www.humanconnectome.org/software/connectome-workbench)
- This tool provides utilities for surface-based analysis of fMRI data. Surface-based analysis has many benefits over the traditional volumetric form of fMRI analysis see [this paper by fellow co-instructor, Erin Dickie](https://pubmed.ncbi.nlm.nih.gov/31091476/) which discusses this topic
- Note: you will need to project your fMRI data to the surface for this tool. This can be achieved using **Ciftify** or **HCPpipelines** which are linked above in this doc.
### Confound Regression
Choosing which confound regressors to use in your analysis is tricky and there's a lot of discussion in the community about the trade-offs made by each motion estimator. Below are a few papers to help guide your decision-making process for choosing confund regressors:
- [Benchmarking of participant-level confound regression strategies for the control of motion artifact in studies of functional connectivity](https://www.sciencedirect.com/science/article/pii/S1053811917302288)
- [Recent progress and outstanding issues in motion correction in resting state fMRI](https://pubmed.ncbi.nlm.nih.gov/25462692/)
## Assignment
TBD
## Q&A
During the duration of the course you may have questions that pop up after each session. If you post them here, we'll try to cover them at the beginning of each session!
***
**Q**
For the last part of the Day 1 exercise (getting the native functional data), is using layout.get(..., space='T1w') okay? The solution still uses a for loop so just wanted to double check.
**A**
Great observation! Yes you can just use space="T1w", it'll work because unlike the anatomical data, where native T1w data doesn't use "space-T1w" in the file name, the functional data *does* have "space-T1w" in its file name - therefore it can be correctly parsed by pyBIDS!
***
**Q**
Well, might as well ask here: What's a good resource to be in touch with the neuroimaging community? For example Hadley Wickham's book, Oxford Handbook for Medical Statistics, Rbloggers and STDHA websites are good places for R and Stats. What are the equivalents in neuroimaging?
**A**
The neuroimaging equivalent would be Neurostars. You can find it linked under the "Neuroimaging Forum" heading. Also, if you are using software packages hosted on GitHub, asking questions using GitHub issues is also a good place. Lastly, there's a neuroimaging Slack-like platform with different channels to ask questions on specific topics: https://mattermost.brainhack.org
***
**Q**
I am going through the execise from 02-exploring_fmriprep. Any time that I enter layout.get command it get NameError: name 'layout' is not defined. This is for the first two exercises. When doing the third exercise I have a NameError: name 'func_data' is not defined. What am I missing? I entered the following commands:
1.
func_data = layout.get( datatype='func', suffix='preproc', space='T1w')
2. mni_func_data = layout.get(datatype-'func', suffix='preproc', space='MNI152NLin2009cAsym')
mni_func_data
3.native_func_data = [b for b in func_data if b not in mni_func_data]
native_func_data
Thank You, I just re-ran the code before, and it all worked.
**A**
Did you re-run the code that comes before the exercise section? Anytime you close a notebook all the variables that you generated get lost, you need to re-run the cells from the beginning to re-initialize the variables again.
***
**Q**
In 04-integration_functional_data_solutions, right after command:
func_mni_img.shape
it suggests that we try
func.slicer[x,y,z] vs/or func.slicer[x,y,z,t]
But, I get the error:
NameError: name 'func' is not defined
Thank You
**A**
Those are just meant to be illustrative examples of how functional data has 4 indices vs. just 3.
The variable "func" is never defined in any of the cells which is why you're getting that error.
It works now, thank you.
***
**Q**
In 06_data-cleaning-with-nilearn, the sectionon Applying confound regression, Method 1
When I run:
clean_img = img.clean_img(func_img,confounds=confounds_matrix,detrend=True,standardize=True,
low_pass=low_pass,high_pass=high_pass,t_r=t_r, mask_img=mask_file)
I get a ValueError, i'm guessing it has to do with "t_r=t_r, mask_img=mask_file)", and again
ValueError: "Mask shape: (65, 77, 49) is different from img shape:(65, 77, 5)"
More errors show up on next line when using plot.plot..... I'm guessing it could be with the shape/size not matching.
**A**
I tried running through the solutions notebook and can't reproduce your error. Maybe you mis-specified dropping TRs? i.e:
`func_img = raw_func_img.slicer[:,:,:5,:]?
`
I can't think of other reasons why the shape of the functional image would have "5" in it's third dimension.
***
**Q**
Just to make sure, for submitting the assignment, may we upload the Jupyter notebook into the Assignment Dropbox section on our Scinet account?
**A**
Yes you can download the notebook as a PDF then upload that as the file!
***
**Q**
Hi, somewhat off topic of the assignment, but I'm interested in running fmriprep on a large sample and was wondering if you could link any code to run it in parallel on SciNet? I have already created the singularity image and bids converted my files. Thanks!
**A**
Here's an example from Erin:
https://github.com/edickie/bids-on-scinet/blob/master/examples/sbatch_fmriprep1.1.2_anat_p08.sh
We may have more examples, stay posted...!
***
For anyone having issues with getting files for notebook 4 copy and paste this block below:
```
fmriprep_dir = '../data/ds000030/derivatives/fmriprep/'
layout=BIDSLayout(fmriprep_dir, validate=False)
T1w_files = layout.get(subject='10788', datatype='anat', suffix='preproc', space='MNI152NLin2009cAsym',return_type='file')
brainmask_files = layout.get(subject='10788', datatype='anat', suffix='brainmask', space='MNI152NLin2009cAsym',return_type='file')
func_files = layout.get(subject='10788', datatype='func', suffix='preproc', space='MNI152NLin2009cAsym',return_type='file')
func_mask_files = layout.get(subject='10788', datatype='func', suffix='brainmask', space='MNI152NLin2009cAsym',return_type='file')
```
***