引言
在之前處理任務(wù)態(tài)數(shù)據(jù)時(shí),使用了spm進(jìn)行操作,發(fā)現(xiàn)就算是使用了batch界面颅围,對于37名被試,也至少需要點(diǎn)擊不下成百上千次恨搓;而用batch導(dǎo)出的script批量化院促,也只能批量一個(gè)簡單的步驟。
做到一半忽然想起靜息態(tài)處理用到的DPABI斧抱,其實(shí)無論任務(wù)態(tài)還是靜息態(tài)兩者預(yù)處理部分都是類似的常拓,而DPABI就是為了批量處理被試而誕生的,所以還是再詳細(xì)敘述一下DPABI的預(yù)處理流程辉浦。而后再用其批量處理過后的結(jié)果使用spm進(jìn)行任務(wù)態(tài)模型的設(shè)計(jì)與個(gè)體分析弄抬。
此次采用的是之前spm中采用的任務(wù)態(tài)FMRI數(shù)據(jù)。
一宪郊、 DPABI處理順序
完整順序
預(yù)處理常用順序
二掂恕、DPABI批處理詳細(xì)步驟
整理一下目前批量處理的四種做法
1.最原始的spmBatch單個(gè)被試,一個(gè)一個(gè)點(diǎn)擊操作弛槐,費(fèi)時(shí)費(fèi)力懊亡,但重在精準(zhǔn)。
2.spmBatch導(dǎo)出script后替換被試名稱乎串,整理成被試個(gè)數(shù)量的job文件店枣,再在.m文件中復(fù)制粘貼被試個(gè)數(shù)量的執(zhí)行步驟。比第一種方法稍微減輕些工作量,但總體依舊繁瑣鸯两。
3.在第二種方法的基礎(chǔ)上坏瞄,直接修改code的循環(huán)。但是需要有一定的code基礎(chǔ)甩卓,有一定難度鸠匀,但是掌握后,便可自己維護(hù)與修改code逾柿。
4.使用DPABi進(jìn)行預(yù)處理缀棍,只需整理文件數(shù)據(jù)結(jié)構(gòu),簡單省時(shí)机错,但是容易報(bào)錯(cuò)爬范,而且其中的步驟并非完全和spm相同,所以跑出來的結(jié)果可能不同弱匪,此處有待考證青瀑。
1.數(shù)據(jù)準(zhǔn)備
如圖3,4,這是到手的數(shù)據(jù)萧诫,已經(jīng)被初步整理成了.nii格式斥难。
但是DPABI需要特殊的文件結(jié)構(gòu),所以仍需進(jìn)一步整理帘饶,這里展示使用的R語言code和最終的整理效果哑诊。
#R語言批量準(zhǔn)備DPABI處理前文件結(jié)構(gòu)
#共37個(gè)被試,需準(zhǔn)備RW及刻、SD與T1三個(gè)大文件夾镀裤,并分裝37個(gè)被試相應(yīng)的文件。
#創(chuàng)建37個(gè)子文件夾
setwd("D:/desk/speed/data_1/task_spm/RW")
sapply(paste0("sub_10",1:9), dir.create)
sapply(paste0("sub_1",10:37), dir.create)
setwd("D:/desk/speed/data_1/task_spm/SD")
sapply(paste0("sub_20",1:9), dir.create)
sapply(paste0("sub_2",10:37), dir.create)
setwd("D:/desk/speed/data_1/task_spm/T1/RW")
sapply(paste0("sub_10",1:9), dir.create)
sapply(paste0("sub_1",10:37), dir.create)
setwd("D:/desk/speed/data_1/task_spm/T1/SD")
sapply(paste0("sub_20",1:9), dir.create)
sapply(paste0("sub_2",10:37), dir.create)
#移動(dòng)文件
#結(jié)構(gòu)像
##RW文件夾
for (i in 1:9) {file.copy(
paste("D:/desk/speed/data_1/T1/RW/sub_10",as.character(i),"/10",as.character(i),"_t1.nii",sep = ""),
paste("D:/desk/speed/data_1/task_spm/T1/RW/sub_10",as.character(i),"/10",as.character(i),"_t1.nii",sep = ""))
}
for (i in 10:37) {file.copy(
paste("D:/desk/speed/data_1/T1/RW/sub_1",as.character(i),"/1",as.character(i),"_t1.nii",sep = ""),
paste("D:/desk/speed/data_1/task_spm/T1/RW/sub_1",as.character(i),"/1",as.character(i),"_t1.nii",sep = ""))
}
##SD文件夾
for (i in 1:9) {file.copy( paste("D:/desk/speed/data_1/T1/SD/sub_20",as.character(i),"/20",as.character(i),"_t1.nii",sep = ""),
paste("D:/desk/speed/data_1/task_spm/T1/SD/sub_20",as.character(i),"/20",as.character(i),"_t1.nii",sep = ""))
}
for (i in 10:37) {file.copy(paste("D:/desk/speed/data_1/T1/SD/sub_2",as.character(i),"/2",as.character(i),"_t1.nii",sep = ""),paste("D:/desk/speed/data_1/task_spm/T1/SD/sub_2",as.character(i),"/2",as.character(i),"_t1.nii",sep = ""))
}
#功能像文件移動(dòng)
##RW
for (i in 1:9) {file.copy(
paste("D:/desk/speed/data_0/RW/10",as.character(i),"_speed.nii",sep = ""),paste("D:/desk/speed/data_1/task_spm/RW/sub_10",as.character(i),"/10",as.character(i),"_speed.nii",sep = ""))
}
for (i in 10:37) {file.copy(
paste("D:/desk/speed/data_0/RW/1",as.character(i),"_speed.nii",sep = ""),paste("D:/desk/speed/data_1/task_spm/RW/sub_1",as.character(i),"/1",as.character(i),"_speed.nii",sep = ""))
}
##SD
for (i in 1:9) {file.copy(
paste("D:/desk/speed/data_0/SD/20",as.character(i),"_speed.nii",sep = ""),paste("D:/desk/speed/data_1/task_spm/SD/sub_20",as.character(i),"/20",as.character(i),"_speed.nii",sep = ""))
}
for (i in 10:37) {file.copy(
paste("D:/desk/speed/data_0/SD/2",as.character(i),"_speed.nii",sep = ""),paste("D:/desk/speed/data_1/task_spm/SD/sub_2",as.character(i),"/2",as.character(i),"_speed.nii",sep = ""))
}
2.去除前三個(gè)TP
1)運(yùn)行界面設(shè)置
然后主要結(jié)果是一個(gè)tsv文件缴饭,此處可以看到TP等每個(gè)被試的基礎(chǔ)信息暑劝。
2)檢查發(fā)現(xiàn)共有220個(gè)TP,此時(shí)去除前3個(gè)颗搂。
再空跑一次后担猛,發(fā)現(xiàn)TP已變成217。
3.預(yù)處理參數(shù)設(shè)置
1)了解DPABI中縮寫
2)分別設(shè)置R(頭動(dòng)校準(zhǔn))峭火,配準(zhǔn)毁习,W(標(biāo)準(zhǔn)化)智嚷,S(平滑)卖丸,automask(后續(xù)便于統(tǒng)計(jì)分析,非必選)(block設(shè)計(jì)不進(jìn)行時(shí)間校準(zhǔn)盏道,而標(biāo)準(zhǔn)化方法這里我們盡量選擇和spm一致的方法稍浆,new segment這里我沒跑通,最終選擇的還是old segment。)
4.結(jié)果文件結(jié)構(gòu)
三衅枫、SPM模型設(shè)計(jì)與個(gè)體分析
由于DPABI最終處理結(jié)果是4D文件嫁艇,而SPM處理仍需要3d文件,所以還是需要將4d轉(zhuǎn)化為3d弦撩。
由于此處模型設(shè)計(jì)是spm特有的操作步咪,所以仍需一個(gè)一個(gè)單獨(dú)操作。
不過設(shè)置以下4個(gè)步驟的batch后益楼,每個(gè)被試只需要修改“4Dto3D的輸入文件”猾漫,“4Dto3D的輸出文件目錄”,“model設(shè)計(jì)的輸出目錄”以及“model設(shè)計(jì)中的頭動(dòng)文件”這四個(gè)地方就可以了感凤。
1.4Dto3D
2.fMRI model specification
回歸選取的頭動(dòng)參數(shù)需要選中每個(gè)被試前面處理生成的rp.txt文件悯周。
這里按照實(shí)驗(yàn)設(shè)計(jì)speed onsets寫為:0:62:372;baseline寫為:32:62:404
3.Model estimation
4.設(shè)置Contrast(后續(xù)統(tǒng)計(jì)分析使用)(1 -1 0 0 0 0 0 0)
5結(jié)果展示(更改con文件命名為與被試同陪竿,便于后續(xù)統(tǒng)計(jì)分析)
這里再介紹一種方法禽翼,也就是以上說明的第三種批量處理方法對第三步:“SPM模型設(shè)計(jì)與個(gè)體分析”進(jìn)行code批量化
1.首先設(shè)計(jì)一個(gè)batch,如上族跛,然后導(dǎo)出script闰挡。
2.對script進(jìn)行matlab的批處理修改,如下:
修改主要包含兩部分:
1.對spm的環(huán)境進(jìn)行設(shè)置:
(1)將batch中的matlabbatch全部替換成jobs
(2)加入spm_get_defaults和spm_jobman('initcfg')
(3)循環(huán)內(nèi)部結(jié)尾加入spm_jobman('run',jobs);clear jobs
2.添加循環(huán):針對自己的文件結(jié)構(gòu)添加循環(huán)
這些code的修改參考了賈曉燕的文章((11條消息) SPM批處理數(shù)據(jù)_賈曉燕的博客-CSDN博客_spm 批處理)
%-----------------------------------------------------------------------
% 時(shí)間:20220913
%程序員:wishing
%目的:批量處理DPABI預(yù)處理后的任務(wù)態(tài)數(shù)據(jù)礁哄,包含4D轉(zhuǎn)3D解总、model 設(shè)計(jì)、model評估與contrast設(shè)計(jì)四個(gè)步驟姐仅。
%-----------------------------------------------------------------------
clear,clc;
spm_get_defaults
spm_jobman('initcfg');
for i = 1:2
filename_in = char(append('D:\desk\speed\data_1\Dp_spm\RW\FunImgRWS\sub_10',string(i),'\swr10',string(i),'_speed.nii,1'));
filename_out = char(append('D:\desk\speed\data_1\Dp_spm\RW\FunImgRWS\sub_10',string(i)));
filename_re = char(append('D:\desk\speed\data_1\Dp_spm\RW\RealignParameter\sub_10',string(i),'\rp_10',string(i),'_speed.txt'));
jobs{1}.spm.util.split.vol = {filename_in};
jobs{1}.spm.util.split.outdir = {filename_out};
jobs{2}.spm.stats.fmri_spec.dir = {filename_out};
jobs{2}.spm.stats.fmri_spec.timing.units = 'secs';
jobs{2}.spm.stats.fmri_spec.timing.RT = 2;
jobs{2}.spm.stats.fmri_spec.timing.fmri_t = 35;
jobs{2}.spm.stats.fmri_spec.timing.fmri_t0 = 18;
jobs{2}.spm.stats.fmri_spec.sess.scans(1) = cfg_dep('4D to 3D File Conversion: Series of 3D Volumes', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','splitfiles'));
jobs{2}.spm.stats.fmri_spec.sess.cond(1).name = 'speed';
jobs{2}.spm.stats.fmri_spec.sess.cond(1).onset = [0
62
124
186
248
310
372];
jobs{2}.spm.stats.fmri_spec.sess.cond(1).duration = 32;
jobs{2}.spm.stats.fmri_spec.sess.cond(1).tmod = 0;
jobs{2}.spm.stats.fmri_spec.sess.cond(1).pmod = struct('name', {}, 'param', {}, 'poly', {});
jobs{2}.spm.stats.fmri_spec.sess.cond(1).orth = 1;
jobs{2}.spm.stats.fmri_spec.sess.cond(2).name = 'baseline';
jobs{2}.spm.stats.fmri_spec.sess.cond(2).onset = [32
94
156
218
280
342
404];
jobs{2}.spm.stats.fmri_spec.sess.cond(2).duration = 30;
jobs{2}.spm.stats.fmri_spec.sess.cond(2).tmod = 0;
jobs{2}.spm.stats.fmri_spec.sess.cond(2).pmod = struct('name', {}, 'param', {}, 'poly', {});
jobs{2}.spm.stats.fmri_spec.sess.cond(2).orth = 1;
jobs{2}.spm.stats.fmri_spec.sess.multi = {''};
jobs{2}.spm.stats.fmri_spec.sess.regress = struct('name', {}, 'val', {});
jobs{2}.spm.stats.fmri_spec.sess.multi_reg = {filename_re};
jobs{2}.spm.stats.fmri_spec.sess.hpf = 128;
jobs{2}.spm.stats.fmri_spec.fact = struct('name', {}, 'levels', {});
jobs{2}.spm.stats.fmri_spec.bases.hrf.derivs = [0 0];
jobs{2}.spm.stats.fmri_spec.volt = 1;
jobs{2}.spm.stats.fmri_spec.global = 'None';
jobs{2}.spm.stats.fmri_spec.mthresh = 0.8;
jobs{2}.spm.stats.fmri_spec.mask = {''};
jobs{2}.spm.stats.fmri_spec.cvi = 'AR(1)';
jobs{3}.spm.stats.fmri_est.spmmat(1) = cfg_dep('fMRI model specification: SPM.mat File', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
jobs{3}.spm.stats.fmri_est.write_residuals = 0;
jobs{3}.spm.stats.fmri_est.method.Classical = 1;
jobs{4}.spm.stats.con.spmmat(1) = cfg_dep('Model estimation: SPM.mat File', substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
jobs{4}.spm.stats.con.consess{1}.tcon.name = 's-b';
jobs{4}.spm.stats.con.consess{1}.tcon.weights = [1 -1 0 0 0 0 0 0];
jobs{4}.spm.stats.con.consess{1}.tcon.sessrep = 'none';
jobs{4}.spm.stats.con.delete = 0;
spm_jobman('run',jobs);
clear jobs
end
四花枫、DPABI群體統(tǒng)計(jì)分析
群體分析這里使用SPM也可以,不過由于之前用DPABI更加順手掏膏,所以最后還是用DPBAI進(jìn)行劳翰,二者本質(zhì)相同,核心都是spm中的code馒疹。
1.單樣本t檢驗(yàn)
1)準(zhǔn)備文件結(jié)構(gòu)
#R語言
#單樣本檢驗(yàn)DAPBI文件結(jié)構(gòu)
#RW
for (i in 1:9) {file.copy(
paste("D:/desk/speed/data_1/Dp_spm/RW/FunImgARWS/sub_10",as.character(i),"/con_0001.nii",sep = ""),
paste("D:/desk/speed/data_1/Dp_spm/group/one_ttest/RW_con/con_",as.character(i),".nii",sep = ""))
}
for (i in 10:37) {file.copy(
paste("D:/desk/speed/data_1/Dp_spm/RW/FunImgARWS/sub_1",as.character(i),"/con_0001.nii",sep = ""),
paste("D:/desk/speed/data_1/Dp_spm/group/one_ttest/RW_con/con_",as.character(i),".nii",sep = ""))
}
2)文件結(jié)構(gòu)展示
3)DPABI單樣本t檢驗(yàn)
這里根據(jù)行為學(xué)指標(biāo)與頭動(dòng)指標(biāo)排除被試(1,5,8,9,10,14,23,32,33)
4)view結(jié)果并報(bào)告佳簸。