Enigma - Structural image processing protocol (结构图像处理协议协议)

ENIGMA TOOLBOX


ENIGMA工具箱提供了一个平台,协调ENIGMA Working Groups内部和之间的分析方法,从而实现了跨多种疾病的meta-和mega-分析病例对照比较,并且提供皮质和皮质下数据投影到surface的可视化展示。

使用ENIGMA工具箱之前,我们需要把数据根据ENIGMA图像处理协议处理成ENIGMA工具箱能够使用的数据格式。

 

Structural image processing protocol (结构图像处理协议协议)

一、先用Freesurfer处理数据:recon-all

例如:recon-all -all -i 101309_3T_T1w_MPR1.nii -s 101309_3T_T1w_MPR1

我分别处理了7个对象(脑残示范)

批量处理流程(其实您可以从这里开始, Linux系统)

1. Preparations

创建一个文件夹命名为 “enigma”,包含两个文件夹“input” and “output”,以及“figures”:

mkdir <path>/enigma
mkdir <path>/enigma/input enigma/output
mkdir <path>/enigma/figures/

input文件夹中存放所有对象的nii.gz格式的扫描数据,每个文件命名为“subj[number].nii.gz” (e.g. subj01.nii.gz, subj02.nii.gz, subj03.nii.gz).

注:如果同时含有1.5T和3T扫描,需要分开存放,也就是需要有这些文件夹:

enigma/15T/input and enigma/3T/input 

enigma/15T/output and enigma/3T/output

(以下步骤为仅含有一种类型文件的操作说明)

It is recommended to use the c-shell or enhanced c-shell for FreeSurfer, you can do this by simply typing:

csh 或者 tcsh

You can set this shell permanently as your default:

chsh -s /bin/csh 或者 chsh -s /bin/tcsh

2.Setup FreeSurfer

FreeSurfer官方教程:https://surfer.nmr.mgh.harvard.edu/fswiki/QuickInstall

  1. The variable FREESURFER_HOME is set (so your computer knows where FreeSurfer is installed):

         setenv FREESURFER_HOME <freesurfer_installation_directory>/freesurfer

    2. The FreeSurfer set up script must be sourced (so FreeSurfer knows the location of everything it needs):

         source $FREESURFER_HOME/SetUpFreeSurfer.csh

    3. FreeSurfer has been pointed to a directory of subjects to work on:

        setenv SUBJECTS_DIR <path>/enigma/input

例如:

export FREESURFER_HOME=/Applications/freesurfer
source $FREESURFER_HOME/SetUpFreeSurfer.sh
export TUTORIAL_DATA=/Applications/freesurfer/tutorial_data
export SUBJECTS_DIR=$TUTORIAL_DATA/buckner_data/tutorial_subjs
cd $SUBJECTS_DIR

3. Run preprocessing pipeline

1. 批量处理input-folder中的文件,为所有对象运行“recon–all”。在input-folder中创建一个text文件,例如:nano List_subjects.txt。即包含全部对象的一个列表。

subj01

subj02

subj03

2. 创建一个循环处理多个数据的脚本,例如:nano loop_recon-all。

#!/bin/bash

exec <List_subjects.txt

while read x; do

recon-all –i $x.nii.gz –s $x –all

mv $x/ <path>/enigma/output

done

使上面创建的脚本可运行,并运行这个脚本文件:

chmod u+x loop_recon_all

./loop_recon_all

结果:

每个对象命名的文件夹,每个文件夹中出现10?8 new folders (such as ‘mri’, ‘stats’, ‘surf’ etc).

//  以上,Freesurfer处理部分完成✅

4. Extract subcortical volumes

提取皮质下体积,需要运行下面的命令:

cd <path>/enigma/output

bash

echo "SubjID,LLatVent,RLatVent,Lthal,Rthal,Lcaud,Rcaud,Lput,Rput,Lpal,Rpal,Lhippo,Rhippo,Lamyg,Ramyg,Laccumb,Raccumb,ICV" > LandRvolumes.csv

for subj_id in `ls -d subj*`; do

printf "%s,"  "${subj_id}" >> LandRvolumes.csv

for x in Left-Lateral-Ventricle Right-Lateral-Ventricle Left-Thalamus-Proper Right-Thalamus-Proper Left-Caudate Right-Caudate Left-Putamen Right-Putamen Left-Pallidum Right-Pallidum Left-Hippocampus Right-Hippocampus Left-Amygdala Right-Amygdala Left-Accumbens-area Right-Accumbens-area; do

printf "%g," `grep  ${x} ${subj_id}/stats/aseg.stats | awk '{print $4}'` >> LandRvolumes.csv

done

printf "%g" `cat ${subj_id}/stats/aseg.stats | grep IntraCranialVol | awk -F, '{print $4}'` >> LandRvolumes.csv

echo "" >> LandRvolumes.csv

done

完成后,得到一个文件“LandRvolumes.csv”:

用Excel打开应该长成这个样子:

用记事本打开应该长成这个样子:

5. Generate histogram plots

1. 安装R(http://cran.r-project.org/)

2. 下载脚本:http://enigma.ini.usc.edu/wp-content/uploads/scripts/ENIGMA_plots.R

3. 复制步骤4中得到的LandRvolumes.csv到figures文件夹中:

cp <path>/enigma/output/LandRvolumes.csv <path>/enigma/figures/

Make sure that the columns are in the same order as in the file above. Also, note that the “x” is the marker that should be used to mark files as poorly segmented or excluded (see step 9). Also, you need to make sure that there are no missing values in the file. In the LandRvolumes.csv file missing values will appear as two commas in a row “,,”. Missing values are probably easier to see in a spreadsheet program like Microsoft Excel, there it will just be a blank cell. You need to put an “x” value for any missing value so that it will be excluded from the analysis.

4.  把ENIGMA_plots.R放入figures文件夹中:

mv <path>/downloads/enigma_plots.R <path>/enigma/figures/

进入figures文件夹中,并执行ENIGMA_plots.R脚本:

cd <path>/enigma/figures

R --no-save --slave < ENIGMA_plots.R

结果得到一个文件SummaryStats.txt和一系列PNG直方图:

SummaryStats.txt文件用Excel和记事本打开应该分别长成这个样子:

  

PNG直方图大概这个样子:

6. Perform outlier detection

注:后面的步骤都是为了检测前面生成的数据是否有误(是否有异常值)

1. 基于SummaryStats.txt文件,执行一个半自动化的脚本mkIQIrange.sh,脚本内容如下:

This is done by defining the Interquartile Interval (IQI), defined as Quartile 1 (Q1) – 1.5 times the Interquartile Range (IQR) to Quartile 3 (Q3) + 1.5 times the IQR.

#!/bin/bash

echo "Region,MNminus1.5IQI,MNplus1.5IQI" > IQI_range.csv

sed '1d' SummaryStats.txt | grep -v "Assym" | grep -v "Avg_"  | awk ' { print $1","$4-2.698*$5","$4+2.698*$5 } ' >> IQI_range.csv

N_regions=`more LandRvolumes.csv | head -n 1 | awk -F "," ' { print NF } '`

for (( c=2; c<=$N_regions; c++))

do roi=`more LandRvolumes.csv | head -n 1 | awk -F "," ' { print $'$c' } '`

IQI_low=`more IQI_range.csv | grep $roi | awk -F "," ' { print $2 }'`

IQI_high=`more IQI_range.csv | grep $roi | awk -F "," ' { print $3 }'`

IQI_low_int=`printf "%10.0f\n" $IQI_low`

IQI_high_int=`printf "%10.0f\n" $IQI_high`

echo "Looking for subjects with "$roi" volumes outside of "$IQI_low":"$IQI_high

cnt=1

for textline in `sed '1d' LandRvolumes.csv | awk -F "," ' { print $'$c' } '`

do cnt=`echo $cnt+1 | bc `

textline_int=`printf "%10.0f\n" $textline`

if [ $textline_int -gt $IQI_high_int ];

then sid=`more LandRvolumes.csv | head -n $cnt | tail -n 1 | awk -F "," ' { print $1 } '`

echo $sid" has a "$roi" of "$textline", this volume is high"

fi

if [ $textline_int -lt $IQI_low_int ];

then sid=`more LandRvolumes.csv | head -n $cnt | tail -n 1 | awk -F "," ' { print $1 } '`

echo $sid" has a "$roi" of "$textline", this volume is low"

fi

done

done

执行脚本mkIQIrange.sh,来可视化对象,这个步骤需要安装FSLview。

#!/bin/bash

./mkIQIrange.sh > jnk.txt

 

more jnk.txt | grep "has" |  awk -F/ ' { print $NF } ' | awk ' { print $1 } '| sort | uniq > jnk2.txt

more jnk2.txt | wc -l

hd=`pwd`

 

for img in `more jnk2.txt`

do echo $img

cd <home directory>/enigma/output/$img/mri/

mri_convert --out_orientation RAS --in_type mgz --out_type nii T1.mgz T1.nii ;

mri_convert --out_orientation RAS --in_type mgz --out_type nii aseg.mgz aseg.nii ;

more $hd/jnk.txt | grep $img

fslview T1.nii aseg.nii -t 0.2 -l "MGH-Subcortical";

rm *.nii

done

FSLView will open automatically to visualize the subjects that were identified as outliers, so that you can verify that the structure is delineated properly.

Note: If a subject is identified as an outlier, but after inspection you decide the subject is properly segmented, you should NOT exclude its structures from your LandRvolumes.csv (see step 9).

 

// 到此为止,您可以移步到ENIGMA TOOLBOX:https://enigma-toolbox.readthedocs.io/en/latest/#

 

7. Create PNGs for the quality check

下载ENIGMA Matlab scripts并解压缩:(http://enigma.ini.usc.edu/wp-content/uploads/CORTEX/QC_ENIGMA_Cortex.zip)

下载脚本‘func_make_subcorticalFS_ENIGMA_QC.m’:( http://enigma.ini.usc.edu/wp-content/uploads/scripts/func_make_subcorticalFS_ENIGMA_QC.m )

下载脚本‘make_subcortical_ENIGMA_QC_webpage.sh’ :( http://enigma.ini.usc.edu/wp-content/uploads/scripts/make_subcortical_ENIGMA_QC_webpage.sh 

move them to the same folder containing all other matlab scripts.

Start Matlab:

<path_to_matlab>/matlab

Add the ENIGMA_QC folder containing all of the required scripts to Matlab’s path: File -> Set Path -> Add Folder -> {OK} -> {Save} -> {Close}

When you work in Matlab without a GUI, you can instead type:

addpath <path>/enigma/QC_ENIGMA

In the Matlab console window, change directories to the folder with all of your FreeSurfer subject folders.

cd <path>/enigma/output/

Make a directory to store all of the QC output.

mkdir <path>/enigma/output/QC/

In the Matlab command window we can do:

QC_output_directory=’<path>/enigma/output/QC/';

FS_directory='<path>/enigma/output/';

a=dir(char(strcat(FS_directory,'/subj*')));%Choose this so that it selects only %your subject folders that contain FS output

for x = 1:size(a,1)

    [c,b,d]=fileparts(a(x,1).name); %b becomes the subject_name

try

func_make_subcorticalFS_ENIGMA_QC(QC_output_directory, b, [FS_directory,'/', b, '/mri/orig.mgz'], [FS_directory,'/',b, '/mri/aparc+aseg.mgz']);

end

display(['Done with subject: ', b,': ',num2str(x-2), ' of ', num2str(size(a,1)-2)]);

end

The func_make_subcorticalFS_ENIGMA_QC-script should take approximately 7 seconds/subject and will output a series of *.png image files separated by individual subject folders.

NB: if you run into problems with this Matlab loop try removing the last “/” in the QC_output_directory variable. So, QC_output_directory='<home-directory>/enigma/output/QC/'; would become QC_output_directory='<path>/enigma/output/QC’; 

8. Perform quality check on the webpage

To create a webpage for easy viewing of the QC output you just generated in Matlab, go to the directory where you stored the script make_subcortical_ENIGMA_QC_webpage.sh and make sure it is executable:

chmod 777 make_subcortical_ENIGMA_QC_webpage.sh

Now to run the script, just give the script the full path to the directory where you stored the Matlab QC output files:

./make_subcortical_ENIGMA_QC_webpage.sh <path>/enigma/output/QC/

NB: If you have trouble running this script, it’s possible that you need to fix the line endings in the script before running. You can do this by running this command:

sed -i -e 's/\r$//' make_subcortical_ENIGMA_QC_webpage.sh

The script will create multiple webpages (e.g. ‘ENIGMA_Amyg_volume_QC.html’, ENIGMA_Subcortical_QC.html’) in the same folder as your QC output. To open one of these webpages in a browser of your choice in a Linux environment. For example:

firefox <path>/enigma/output/QC/ENIGMA_Subcortical_QC.html

If you want to check the segmentation on another computer, you can just copy over the whole QC-folder to your computer and open the webpage from there.

9. Exclude poor segmentations

Based on the histogram plots, outlier detection and the quality check on the webpage, you may have identified some poor segmentations. You can try to re-run “recon-all” on the subjects showing poor segmentations and go through step 4 to 6 again.

If this does not help, then you have to exclude these volumes from LandRvolumes.csv by marking them with an “x” and re-run the ENIGMA_plots.R on your updated LandRvolumes.csv (see step 5). Send us the new histograms and SummaryStats.txt once you are finished.

 

// The End.

 

Enigma - Structural image processing protocol (结构图像处理协议协议)下载地址:

http://enigma.ini.usc.edu/   (Enigma官方首页)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值