一、fmriprep介紹
fMRIPrep is a BIDS App that employs a standardized pre-processing pipeline on BIDS-compliant fMRI data. This pipeline utilizes the leading tools from different fMRI software packages (AFNI, FSL, ANTs, Freesurfer, nipype) to perform specific steps during the pre-processing. Rather than being limited to an individual package, fMRIPrep will leverage the best software tool for each pre-processing step, such as ANTs for normalization, FreeSurfer for surface reconstruction, and so on. In addition, users can easily access the workflows to determine how their data is pre-processed, thus providing better transparency and reproducibility.
對應缺點:
Limitations and reasons not to use fMRIPrep:
1.Very narrow FoV images oftentimes do not contain enough information for standard image registration methods to work correctly. Also, problems may arise when extracting the brain from these data. fMRIPrep supports pre-aligned BOLD series, and accepting pre-computed derivatives such as brain masks is a target of future effort.
2.fMRIPrep may also underperform for particular populations (e.g., infants) and non-human brains, although appropriate templates can be provided to overcome the issue.
3.The “EPInorm” approach is currently not supported, although we plan to implement this feature (see #620).
4.If you really want unlimited flexibility (which is obviously a double-edged sword).
5.If you want students to suffer through implementing each step for didactic purposes, or to learn shell-scripting or Python along the way.
6.If you are trying to reproduce some in-house lab pipeline.
(摘自fmriprep官網描述)
二、環境要求
1.電腦版本是win10專業版,教育版之類也可以,家庭版不可以!(docker要求)
2.conda + python3.8(個人感覺3以上就可以吧)
三、docker安裝和配置fmriprep
1.docker安裝
參考鏈接:
b站詳細fmriprep_tutorial,強烈推薦,本文大多參考該視頻
菜鳥教程安裝
另一個安裝博客
注意1:剛安裝好記得更新Linux內核(WSL2),按提示就行;安裝完成要設定環境變數
一方面安裝成功會看到對應電腦對應任務欄或者右下角隱藏欄也會出現小海豚,安裝不成功就是紅色小海豚,也可以命令列進行安裝成功測驗:
docker run --rm hello-world
注意2:docker記憶體有限制,若有必要記得更改默認位置,參考鏈接:
docker記憶體配置
小插曲:由于我的電腦比較low,我在設定記憶體出現了報錯記憶體不夠,重新打開docker再減小記憶體就可以,盡量分配的越多越好,
Q:docker默認安裝在c盤,這個有辦法改嗎?這個更改配置貌似就是把image之類的轉移到了其他地方,有知道的可以給俺說一下,阿里嘎多!
2.配置fmriprep
命令列輸入:
docker pull nipreps/fmriprep
該命令自動拉取最新的fmriprep,請注意更新版本,
3.fmriprep呼叫
呼叫方式:
1)直接在docker運行,需要輸入多余的引數(不推薦)
2)下載腳本(注意保證你能使用pip)并添加到環境變數方便以后直接使用fmriprep-docker呼叫,命令列輸入:
pip install --user --upgrade fmriprep-docker
命令列輸入以下代碼測驗:
fmriprep-docker
四、準備BIDS資料集
1.BIDS介紹
BIDS全稱是Brain Imaging Data Structure,它是一種統一的腦影像資料存盤規范,利于資料共享;目前有許多優秀的神經影像app支持bids格式,稱之為BIDS-app,fmriprep就是一種,
知乎介紹
一個BIDS資料集格式的example

其他參考資料:
對應官網鏈接
github參考
BIDS Validator,可檢驗格式的合理性
2.創建資料集
創建BIDS格式的資料集一共需要5步:
1)DICOM files to NIfTI
使用dcn2niix來做(win務必建議如下命令):
dcm2niix conda install -c conda-forge dcm2niix
小碎念:這步我搞了好久,卡了半天,明明安裝成功,但是在后續操作我一直報如下錯誤,然后我試著已經添加環境變數依舊報錯,后嘗試在powershell中運行.\dcm2niix等各種方法依舊不行,然后我將dcm2niix.exe安裝到我自己的Anaconda\Scripts就可以了,不知道為什么;后續詢問b站up說可以試著嘗試使用下面這個命令:

pip install dcm2niix
然后安裝:
pip install dcm2bids --user
然后手動修改bug
先找到自己的dcm2bids的安裝路徑,上面這個命令就可以直接看到了,如果沒有就再輸入一遍,修改如圖的utils.py檔案,在第二幅圖的位置加上/,原來的是沒有/的:


2)存盤檔案
結構:被試-Session-模態-檔案,參考:
dcm2bids的主頁
(1)創建一個新檔案夾
(2)三個主要命令:
dcm2bids_helper -d
dcm2bids_scaffold -o
dcm2bids -d <原始的DICOM檔案夾路徑> -p 01 -c D:\demo\BIDS_config.json -o <指定輸出路徑> --forceDcm2niix
說明:
“-d”, “–dicom_dir”:原始DICOM檔案路徑
“-s”, “–session”
“-c”, “–config”:需要自己撰寫的組態檔(重要,后面單獨再說)
“-o”, “–output_dir”:指定輸出路徑
–forceDcm2niix 強制后綴
(3)命令說明
dcm2bids_helper -d:獲得一個幫助檔案,通過該檔案才能知道如何去撰寫config檔案
dcm2bids_helper -d <原始DICOM資料路徑>
運行成功后會顯示幫助檔案路徑;


我們主要通過json檔案撰寫config檔案;通過原始的dicom資料中包含的鍵值對篩選出我們想要的dicom資料并將這些資料轉化成DIffTI格式,并且正確的重命名到bisd格式下,

更多撰寫config資料參考:
bids官網
Andy’s Brain Book
dcm2bids_scaffold -o:創建一個bids的目錄結構(這些檔案必須正常存在才能運行fmriprep),如下圖,后續需要根據自己的資料集進行修改檔案內容:
dcm2bids_scaffold -o <指定路徑>

檔案夾含義及修改參考官方鏈接:
檔案解釋和內容修改
第三條dcm2bids命令運行效果:

3)添加描述檔案
其余檔案的描述
4)手動添加必要東西
如下圖所示:
(1)sourcedata是用來放原始的dicom資料的;
(2)code用來放一些自己撰寫的批處理檔案等;
(3)sub-01是dcm2bids生成的bids格式被試;
(4)derivatives用來存放最后運行fmriprep預處理的生成檔案;
(5)其他描述檔案參考3)
參考知乎:
補充

5)檢驗合理性
BIDS Validator
五、預處理
有兩種方式:一種是在docker里面運行,不過相對繁瑣,不推薦;我們介紹利用fmriprep-docker進行處理,
其中需要用到freesurfer的證書:
證書獲取
人機驗證不能顯示的解決辦法


報錯參考
總結
剛開始學,自己基礎也不好,而且不fan qiang找到的資料太少了,花了好幾天時間才搞好,特此記錄以防后續需要,也是自己的第一篇博客,如果對大家有幫助就更好啦!特別感謝寶藏up主biubiuqu,大家可以看他的視頻,本文章好多借鑒本視頻,后續希望自己可以繼續堅持!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/400404.html
標籤:其他
