しばらく前に、Ubuntu 18.04用にHCP Pipelineの環境を設定する方法を記載しましたが、いくつかアップデートもあるので、Ubuntu 22.04用以降でも設定できるようにします。
*2023/10/08追記: Neurodebianの設定についてうまく動かないミスがありましたので修正しました。神谷先生、ご指摘ありがとうございました。
*2024/03/29追記: Ubuntu 22.04でFreeSurferのスクリプトがダウンロードできない不具合を解消しました。金子先生、ご指摘ありがとうございました。
*2025/12/25追記: Ubuntu 20.04 はサポートが終了したので、タイトルから Ubuntu 20.04 は取り除きました。また、現在は FIX は pyFIXを使うようになったので、FIX関連は取り除きました。上敷領先生、ご指摘ありがとうございました。
主要な解析ソフトのインストール
以下のソフトウェアをインストールする必要があります。
– HCP pipelines
– Workbench
– FreeSurfer https://surfer.nmr.mgh.harvard.edu/fswiki
– FSL https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
– MSM (HCP用)バイナリファイル
– Gradunwarp (Optional)
以下、各ソフトのインストールについて解説します。この通りにしていけば、設定できます。
HCP Pipeline (2025年12月時点では 5.0.0)
- Human connectome projectにおけるMRI解析処理で使用されているスクリプト集です。HCP Pipelineの公式サイトには、~/projects の下に置くことを前提に書いてあります。今後のアップデートを考えると、若干ディスク容量を浪費しますが、git clone したものを、コピーするのが結果的には楽かなと思いました。また、Exampleにあるスクリプトは、~/projects/Pipelines なので、~/git の下にクローンを起き、そしてそれを、~/projects の下に Pipelines という名前でコピーします。
mkdir ~/git ~/projects cd ~/git git clone https://github.com/Washington-University/HCPpipelines.git cp -r HCPpipelines ~/projects/Pipelines
- HCP Pipeline のバージョンは、HCPpipelinesディレクトリの直下にある sho_version でわかります。
cd ~/projects/Pipelines ./show_version
私の環境では以下のようになりました。
DIRECTORY: /home/ユーザー名/projects/Pipelines
PRODUCT: HCP Pipeline Scripts
VERSION: Post-v5.0.0-819fc700
COMMIT: 819fc700bd71f5f3e13769646186dfcbb5330f84
MODIFIED: no
Connectome Workbench
- HCPの基幹となるソフトウェアです。Ubuntu用にNeurodebianが準備しているのでそれを使うのがとても便利です。(Lin4Neuroにはセットアップ済みです)
-
まだNeurodebianの設定をしていない場合、以下でセットアップします。
cat << EOS > neurodebian.sources.list deb [arch=amd64 signed-by=/usr/share/keyrings/neurodebian.gpg] http://neuroimaging.sakura.ne.jp/neurodebian data main contrib non-free deb [arch=amd64 signed-by=/usr/share/keyrings/neurodebian.gpg] http://neuroimaging.sakura.ne.jp/neurodebian $(lsb_release -cs) main contrib non-free EOS sudo mv neurodebian.sources.list /etc/apt/sources.list.d/ wget -O- http://neuro.debian.net/_static/neuro.debian.net.asc |\ sudo gpg --dearmor --yes --output /usr/share/keyrings/neurodebian.gpg sudo apt update
- Neurodebianの設定が終わっている場合は、以下でConnectome workbenchをインストールします。
sudo apt install connectome-workbench
FreeSurfer 6.0.1
- FreeSurferのインストールに特化したスクリプトを私が準備してあるので、それを走らせるのが簡単です。
- 以下のリンクから、ライセンスを入手し、license.txt を ~/Downloads に保存します。
https://surfer.nmr.mgh.harvard.edu/registration.html - その後、以下で必要なパッケージとFreeSurferのインストールとセッティングが行われます。
- FreeSurferは8.xがリリースされていますが、2025年12月時点でも、HCP pipeline 5.0.0 の prerequisites として、依然としてFreeSurfer 6.xを使用することが勧められています。(ソース: Release of HCP Pipeline 5.0.0)
- もし、VirtualBox内のubuntuに対して設定するのならば、VirtualBoxにあわせた修正をしますかという質問にYesと答えてください。recon-allがVirtualBoxの共有フォルダでは動かない問題を解決してあります。
- スクリプトが走り終わった後、新たにターミナルを起動することで、FreeSurferは使用可能になります。
cd ~/Downloads wget https://gitlab.com/kytk/lin4neuro-jammy/-/raw/main/installer-scripts/freesurfer6.0.1_installer.sh bash freesurfer6.0.1_installer.sh
FSL
- fslinstaller.py を入手することで、あとはほぼ自動でインストールおよび設定が完了します。
- 初回は、以下のリンクからregistrationを行います。(fslinstaller.pyは、下に示す方法で入手できます)
https://fsl.fmrib.ox.ac.uk/fsldownloads_registration
cd ~/Downloads curl -O https://fsl.fmrib.ox.ac.uk/fsldownloads/fslinstaller.py python3 fslinstaller.py
- インストール完了後、ログアウトし、再度ログインします。
MSM (Multimodal Surface Matching)
- FreeSurfer等のCortical Surface registration を補助するツールです。
- Fuctional MRIやDiffusionなどの解析結果をSurfaceにMappingする際に個人の脳溝・脳回特徴をより反映させてくれる為、疾患解析等での精度があがるようです。
- FSLに搭載されているものをより新しいものに置き換えます。
cd $HOME/Downloads wget https://github.com/ecr05/MSM_HOCR/releases/download/v3.0FSL/msm_ubuntu_v3 sudo cp msm_ubuntu_v3 /usr/local/fsl/bin cd /usr/local/fsl/bin sudo mv msm msm.orig sudo mv msm_ubuntu_v3 msm sudo chmod 755 msm
Matlab runtime R2022b (Matlabを持っていない場合)
- HCP Pipelines 5.0.0 のリリースノートにMatlabのコンパイルを すべて R2022bに統一したと書いてあります。
- こちらも私がスクリプトを準備してありますので以下で入手して実行します。
cd ~/Downloads wget https://gitlab.com/kytk/lin4neuro-jammy/-/raw/main/installer-scripts/mcr_R2022b_installer.sh bash mcr_R2022b_installer.sh
- この結果、/usr/local/MATLAB/MCR/R2022b に MCRがインストールされます。そして、これを使用する場合には、変数を以下のように設定します。
export MATLAB_COMPILER_RUNTIME=/usr/local/MATLAB/MCR/R2022b
Gradunwarp (optional)
- 装置による歪み補正を行うpython scriptです。
- Siemens()とGE()しか対応していない+撮像PCの中にあるcoeff.gradファイルを取得する必要があるため、対応不可ならインストールしなくともOKです。
cd ~/git git clone https://github.com/Washington-University/gradunwarp.git cd gradunwarp <h1>pip を利用してGradunwapに必要なpython packagesをインストール</h1> pip3 install numpy scipy pydicom nose sphinx nibabel python3 setup.py install --prefix=~/.local/bin
以上です。
いつも大変お世話になっております。
最近、新しいPC(Ubuntu 22.04)を購入してHCP pipelineの環境構築を行っているのですが、こちらのFIXのURL(wget http://www.fmrib.ox.ac.uk/~steve/ftp/fix.tar.gz)は現在、なくなっているようです。gitlab(https://git.fmrib.ox.ac.uk/fsl/fix.git)などからcloneするのがいいのでしょうか?調べてみたところ現在Python版 FIX(pyfix)が開発されているようなのですが、こちらを使用する場合はFSLをインストールしていれば、上記のFIXの設定は不要でしょうか?MATLAB/R版FIXとの違いなどはありますでしょうか?
お忙しいところ恐縮なのですがお時間ある時にでもご教授頂けますと幸いです。
広島大学 上敷領
上敷領先生
FIXは FSLの6.0.6から pyFIXとしてリリースされていて、HCP Pipeline 5.0.0 からはそれで使われていますね。
これまでのFIXとpyFIXの違いは、以下に記載されています。
https://git.fmrib.ox.ac.uk/fsl/pyfix
コマンドは同じになります。最新のFSLを入れて、 fix とだけタイプすると、以下のヘルプが出ます。
FIX (FMRIB's ICA-based Xnoiseifier) [version 0.9.0] Simple usage, assuming training data already exists: fix <mel.ica> <training.pyfix_model> <thresh> [fix -a options] Extract features, classify and run cleanup - equivalent to: fix -f <mel.ica> ; fix -c <mel.ica> <train>.pyfix_model <thresh> ; fix -a <mel.ica>/fix4melview_<train>_<thresh>.txt [-a options] For the [fix -a options], see "fix -a" usage below. The first argument should be a FEAT/MELODIC output directory that includes a filtered_func_data.ica melodic output. Example: fix study1/subject1.ica HCP_noHP.pyfix_model 20 -m -h 200 Example: fix subject2.feat Standard_noHP.pyfix_model 20 -m (ICA must have been turned on in FEAT pre-stats) Usage for each stage separately, including creation of training data: fix -f <mel.ica> Feature extraction (for later training and/or classifying). fix -t <training-output-basename> [-l] [-u] <mel1.ica> <mel2.ica> ... Train classifier (Training output basename followed by list of Melodic directories). Every Melodic directory must contain hand_labels_noise.txt listing the artefact components, e.g.: [1, 4, 99, ... 140]. -l : optional LOO accuracy testing. -u : optional hyperparameter optimisation using Optuna (if installed). fix -c <mel.ica> <training.pyfix_model> <thresh> Classify ICA components. fix -C <training.pyfix_model> <mel1.ica> <mel2.ica> ... Classify components for all listed Melodic directories over a range of thresholds and produce LOO-style accuracy testing using existing hand classifictions. Every Melodic directory must contain hand_labels_noise.txt listing the artefact components, e.g.: [1, 4, 99, ... 140]. fix -a <labels.txt> [<mel.ica>] [-m] [-h <highpass>] [-A] Apply cleanup, using artefacts listed in the .txt file, to the data inside the enclosing Feat/Melodic directory. If <mel.ica> is not provided, it is assumed that <labels.txt> is contained within <mel.ica>. -m optionally also cleanup motion confounds, with highpass filtering of motion confounds controlled by -h -h Highpass filtering of motion confounds and CIfTI time series data. - if -h is omitted, fix will use the highpass cutoff in a design.fsf file, ifpresent. - if -h is omitted, and no design.fsf is present, no filtering of the motion confounds or CIfTI data will take place. - If -h -1, no highpass filtering will be performed. - -h 0 apply linear detrending only. - -h <highpass> with a positive <highpass> value, apply highpass with <highpass> being full-width (2*sigma) in seconds. -A apply aggressive (full variance) cleanup, instead of the default less- aggressive (unique variance) cleanup. The following built-in models can be used for classification: - HCP25_hp2000 - HCP7T_hp2000 - HCP_Style_Single_Multirun_Dedrift - NHP_HCP_Macaque - NHP_HCP_MacaqueCyno - Standard - UKBiobank - WhII_MB6 - WhII_Standard後日、この記事も編集します。ご質問ありがとうございました。
ありがとうございます!教えて頂き大変助かりました! 上敷領
ありがとうございます。今、記事を修正しました。