OSCR

Neurocomputational mechanisms of reward-based online mood regulation in adolescents with bipolar disorder and major depressive disorder.

Code ↔ Paper

3 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 3 matches
  1. [1] § Materials and methods › fMRI data acquisition and preprocessing ↔ fMRI_Proc/03_funcpp02_23BPhappy.ipynb, lines 356–390 · score 0.86 · affine transform, dNwarpApply, align epi, motion corrected, AFNI, nonlinearly
  2. [2] § Materials and methods › fMRI general linear modeling ↔ fMRI_Proc/04_funcGLM1Loop_23BPhappy.ipynb, lines 12–64 · score 0.69 · dDeconvolve, parametrically modulated, GLM1, AFNI, regressors, GLMs
  3. [3] § Materials and methods › fMRI general linear modeling ↔ fMRI_Proc/04_funcGLM1_23BPhappy.ipynb, lines 35–54 · score 0.54 · dDeconvolve, AFNI, GLM1, regressors, GLMs

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Jupyter notebook · 537 lines · 23 KB · GPL-3.0 · 1 match

  1. # %% [markdown]
  2. # # 03_funcpp02
  3. # %% [markdown]
  4. # 功能像预处理的最核心部分。这一部分我们完成一下步骤
  5. # * Despike
  6. # * Slice-timing correction (时间层矫正)
  7. # * Distortion correction (图像畸变矫正)
  8. # * Motion correction (头动矫正)
  9. # * align anat 2 epi (结构像到功能像的配准)
  10. # * 把所有epi划到个体结构像空间
  11. # * 把所有epi的volume数据划到surface data
  12. # * 把所有epi的划到MNI标准空间
  13. # * Scale (标准化数据尺度,抓换成percent signal change)
  14. # %% [markdown]
  15. # ## Step 1. Despike
  16. # %%
  17. # ================================ despike =================================
  18. for run in runstr:
  19. ! 3dDespike -NEW -nomask -prefix pb01.{subj}.r{run}.despike pb00.{subj}.r{run}.tcat+orig
  20. ! rm pb00*
  21. # %% [markdown]
  22. # ## Step 2. Slice-timing correction
  23. # %%
  24. # ================================= tshift =================================
  25. for run in runstr:
  26. ! 3dTshift -tzero 0 -quintic -prefix pb02.{subj}.r{run}.tshift \
  27. -verbose -tpattern @{'../SliceTiming.txt'} pb01.{subj}.r{run}.despike+orig
  28. # 删掉上一步despike的data节省空间
  29. ! rm pb01*
  30. # %% [markdown]
  31. # ## Step 3. Distortion correction
  32. # %% [markdown]
  33. # 因为磁场不均匀的关系,图像会出现畸变。现在来做矫正。
  34. # %%
  35. # 首先找到
  36. for fwd,rev in zip(fwdfiles, revfiles):
  37. # create median datasets from forward and reverse time series
  38. ! 3dTstat -median -prefix rm.blip.med.fwd.r{fwd} pb02.{subj}.r{fwd}.tshift+orig
  39. ! 3dTstat -median -prefix rm.blip.med.rev.r{rev} pb02.{subj}.r{rev}.tshift+orig
  40. # automask the median datasets
  41. ! 3dAutomask -apply_prefix rm.blip.med.masked.fwd.r{fwd} rm.blip.med.fwd.r{fwd}+orig
  42. ! 3dAutomask -apply_prefix rm.blip.med.masked.rev.r{rev} rm.blip.med.rev.r{rev}+orig
  43. # compute the midpoint warp between the median datasets
  44. ! 3dQwarp -plusminus -pmNAMES Rev.r{rev} Fwd.r{fwd} \
  45. -pblur 0.05 0.05 -blur -1 -1 \
  46. -noweight -minpatch 9 \
  47. -noXdis -noZdis \
  48. -source rm.blip.med.masked.rev.r{rev}+orig \
  49. -base rm.blip.med.masked.fwd.r{fwd}+orig \
  50. -prefix blip_warp
  51. ! 3dNwarpApply -quintic -nwarp blip_warp_Fwd.r{fwd}_WARP+orig \
  52. -source rm.blip.med.masked.fwd.r{fwd}+orig \
  53. -prefix rm.blip.med.masked.fwd.post.r{fwd}
  54. ! 3dNwarpApply -quintic -nwarp blip_warp_Rev.r{rev}_WARP+orig \
  55. -source rm.blip.med.masked.rev.r{rev}+orig \
  56. -prefix rm.blip.med.masked.rev.post.r{rev}
  57. # 删掉多余文件
  58. ! rm blip_warp_Fwd.r{fwd}+orig* blip_warp_Rev.r{rev}+orig*
  59. # 修改个名字以便以后的操作
  60. ! 3dcopy blip_warp_Fwd.r{fwd}_WARP+orig blip_warp.r{fwd}_WARP+orig
  61. ! 3dcopy blip_warp_Rev.r{rev}_WARP+orig blip_warp.r{rev}_WARP+orig
  62. ! rm blip_warp_Fwd.r{fwd}+orig* blip_warp_Rev.r{rev}+orig* blip_warp_Fwd.r{fwd}_WARP+orig* blip_warp_Rev.r{rev}_WARP+orig*
  63. # for QC check,我们生成一个校正前和矫正后的平均EPI数据来作为distortion correction的效果证明
  64. ! 3dMean -prefix blip_pre_fwd.epi_mean.nii.gz rm.blip.med.masked.fwd.r*
  65. ! 3dMean -prefix blip_pre_rev.epi_mean.nii.gz rm.blip.med.masked.rev.r*
  66. ! 3dMean -prefix blip_post_fwd.epi_mean.nii.gz rm.blip.med.masked.fwd.post.r*
  67. ! 3dMean -prefix blip_post_rev.epi_mean.nii.gz rm.blip.med.masked.rev.post.r*
  68. # remove redundent file
  69. ! rm rm*
  70. # %% [markdown]
  71. # 这一步完成之后,可以手动打开
  72. # * blip_pre_fwd.epi_mean.nii.gz
  73. # * blip_pre_rev.epi_mean.nii.gz
  74. # * blip_post_fwd.epi_mean.nii.gz
  75. # * blip_post_rev.epi_mean.nii.gz
  76. #
  77. # 这四个文件也记录了对侧矫正的效果,只要有矫正效果,没有什么大问题即可。
  78. #
  79. # 然后把所有的run都做correction
  80. # %%
  81. for run in runstr:
  82. ! 3dNwarpApply -quintic -nwarp blip_warp.r{run}_WARP+orig \
  83. -source pb02.{subj}.r{run}.tshift+orig \
  84. -prefix pb03.{subj}.r{run}.blip
  85. # %% [markdown]
  86. # ## Step 4. Motion correction
  87. # %% [markdown]
  88. # 首先做motion correction。但是我们并不用其结果,主要是得到mc的线性转换矩阵
  89. # %%
  90. runstr.pop() #删去AP参照序列
  91. # ================================= volreg =================================
  92. base = 'vr_base_min_outlier+orig' #在前面生成
  93. # align each dset to base volume, then we separate whether we want to further align epi to anat
  94. for run in runstr:
  95. # register each volume to the base image
  96. ! 3dvolreg -verbose -zpad 1 -base {base} \
  97. -1Dfile dfile.r{run}.1D \
  98. -cubic \
  99. -1Dmatrix_save mat.r{run}.vr.aff12.1D \
  100. -prefix rm.epi.nomask.r{run} pb03.{subj}.r{run}.blip+orig
  101. # create an all-1 dataset to mask the extents of the warp
  102. ! 3dcalc -overwrite -a pb03.{subj}.r{run}.blip+orig -expr 1 -prefix rm.epi.all1
  103. # warp the all-1 dataset for extents masking
  104. ! 3dAllineate -base {base} \
  105. -input rm.epi.all1+orig \
  106. -1Dmatrix_apply mat.r{run}.vr.aff12.1D \
  107. -final NN -quiet \
  108. -prefix rm.epi.1.r{run}
  109. # make an extents intersection mask of this run across time domain
  110. # this makes a mask that all volumes in this run have valid numbers
  111. ! 3dTstat -min -prefix rm.epi.min.r{run} rm.epi.1.r{run}+orig
  112. # %% [markdown]
  113. # 计算更多的头动数值,以后可以用来GLM中的regressor
  114. # %%
  115. # 生成pb04.subj.r0*+volreg+orig
  116. # 生成epi_mean.nii.gz
  117. # motion打头的几个文件
  118. # 生成mc文件夹,里面放了矫正结果比较
  119. nRuns = nRuns-1
  120. # we take dmeaned motion (6), demean motion derivative (6) and their squares (12)
  121. # 合并 motion params
  122. ! cat dfile.r*.1D > dfile_rall.1D
  123. # 计算去均值的motion parameters (for use in regression)
  124. ! 1d_tool.py -infile dfile_rall.1D -set_nruns {nRuns} -demean -write motion_demean.1D
  125. # 计算一阶导数 (just to have)
  126. ! 1d_tool.py -infile dfile_rall.1D -set_nruns {nRuns} -derivative -demean -write motion_deriv.1D
  127. # calculate the square of demean and derivative of motion parameters (just to have)
  128. # for resting preproc, we usually have 24 motion regressor (6motion+6deriv+12 their square)
  129. np.savetxt('motion_demeansq.1D', np.loadtxt('motion_demean.1D')**2)
  130. np.savetxt('motion_derivsq.1D', np.loadtxt('motion_deriv.1D')**2)
  131. # create censor file motion_${subj}_censor.1D, for censoring motion
  132. ! 1d_tool.py -infile dfile_rall.1D -set_nruns {nRuns} \
  133. -show_censor_count -censor_prev_TR \
  134. -censor_motion {motion_censor} motion_{subj}
  135. # Estimate the motion parameter after motion correction, we can check the
  136. # effects of MC
  137. ! mkdir mc
  138. for run in runstr:
  139. ! 3dvolreg -verbose -zpad 1 -base {base} \
  140. -1Dfile dfile.r{run}_pos.1D \
  141. rm.epi.nomask.r{run}+orig
  142. ! rm volreg+orig*
  143. # make a single file of motion params
  144. ! cat dfile.r*_pos.1D > dfile_rall_pos.1D
  145. # make figure pre mc
  146. dfile_pre = np.loadtxt('dfile_rall.1D')
  147. plot(range(dfile_pre.shape[0]), dfile_pre[:,:3], color=['C0','C1','C2'], label=['roll(IS)','pitch(RL)','yaw(AP)'])
  148. plt.legend();plt.xlabel('time points');plt.ylabel('mm');
  149. plt.savefig('rots_pre.pdf');plt.close('all')
  150. plot(range(dfile_pre.shape[0]), dfile_pre[:,3:], color=['C3','C4','C5'], label=['dS','dL','dP'])
  151. plt.legend();plt.xlabel('time points (TR)');plt.ylabel('mm');
  152. plt.savefig('tran_pre.pdf');plt.close('all')
  153. # make figure pos mc
  154. dfile_pos = np.loadtxt('dfile_rall_pos.1D')
  155. plot(range(dfile_pos.shape[0]), dfile_pos[:,:3], color=['C0','C1','C2'], label=['roll(IS)','pitch(RL)','yaw(AP)'])
  156. plt.legend();plt.xlabel('time points');plt.ylabel('mm');
  157. plt.savefig('rots_pos.pdf');plt.close('all')
  158. plot(range(dfile_pos.shape[0]), dfile_pos[:,3:], color=['C3','C4','C5'], label=['dS','dL','dP'])
  159. plt.legend();plt.xlabel('time points (TR)');plt.ylabel('mm');
  160. plt.savefig('tran_pos.pdf');plt.close('all')
  161. # move file to directory
  162. ! mv rots*.pdf tran*.pdf dfile.r*_pos.1D dfile_r*_pos.1D mc/
  163. # note TRs that were not censored, note ktrs here is a str
  164. ktrs = unix_wrapper(f'1d_tool.py -infile motion_{subj}_censor.1D \
  165. -show_trs_uncensored encoded', wantreturn=True, verbose=0)
  166. # ----------------------------------------
  167. # create the extents mask: mask_epi_extents+orig and apply the task
  168. # (this is a mask of voxels that have valid data at every TR,
  169. # there might be some pixel out of extents during mc)
  170. ! 3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
  171. ! 3dcalc -a rm.epi.mean+orig -expr "step(a-0.999)" -prefix mask_epi_extents
  172. # and apply the extents mask to the EPI data
  173. # (delete any time series with missing data)
  174. for run in runstr:
  175. ! 3dcalc -a rm.epi.nomask.r{run}+orig -b mask_epi_extents+orig \
  176. -expr "a*b" -prefix pb04.{subj}.r{run}.volreg
  177. ! rm -f rm.* # rm.epi.nomask are big files, remove them
  178. ! rm -f {base}*
  179. # calculate a mean epi volume for next step anat epi registration
  180. ! 3dMean -prefix rm.epi_mean.nii.gz pb04.{subj}.r*.volreg+orig.HEAD
  181. ! 3dTstat -prefix epi_mean.nii.gz rm.epi_mean.nii.gz
  182. ! rm rm* mask_epi_extents+orig*
  183. # 删掉上一步distortion correction的数据,节省空间
  184. ! rm pb03*
  185. # %% [markdown]
  186. # ## Step 5. anat2epi
  187. # %% [markdown]
  188. # 这一步非常重要,是前面处理好的功能像和结构像进行配准,配准的结果一定要手动检查
  189. # %%
  190. # 首先把用来配准的epi像make a copy
  191. ! 3dcopy epi_mean.nii.gz epi_mean_tmp.nii.gz
  192. # 关键步骤。我们是把结构像配准到功能像,但是我们得到的转换矩阵是从相反的,功能像到结构像,这个矩阵可以后面用来转化epi数据
  193. #
  194. ! align_epi_anat.py -anat2epi -anat {t1.str} \
  195. -save_skullstrip -suffix _al_junk \
  196. -epi epi_mean_tmp.nii.gz -epi_base 0 \
  197. -epi_strip 3dAutomask \
  198. -volreg off -tshift off -giant_move
  199. # 生成nifti文件,方便我们在fsleyes上面查看配准效果
  200. ! 3dcopy {subj}_SurfVol_al_junk+orig {subj}_SurfVol_al_junk.nii.gz
  201. # %% [markdown]
  202. # 完成上面一步之后,要打开fsleyes仔细检查配准的结果,其中underlay选择CN003_SurfVol_al_junk+orig, overlay选择epi_mean_tmp+orig。然后检查两者是否一致。如果不匹配,则需要重新进行上面的过程,在开始之前,需要先删除上面产生的文件。可以做
  203. # ! rm {subj}_SurfVol_al* {subj}_SurfVol_ns*
  204. # 确认配准没有问题之后,进行下一步操作
  205. # %%
  206. # note that we align anat 2 epi, however, this xfm is from epi space to anat space
  207. # note that this xfm is compatible with LPS+ space, which is the default space in AFNI
  208. ! mv {t1.strnosuffix[:-5]}_al_junk_mat.aff12.1D mat.anat2epi.aff12.1D
  209. # create an skull-striped anat_final dataset, aligned with stats
  210. ! 3dcopy {t1.strnosuffix[:-5]}_ns+orig anat_final.{subj}.nii.gz
  211. ! rm {t1.strnosuffix[:-5]}_ns+orig*
  212. # rewrite the name of aligned anat
  213. ! 3dcopy {t1.strnosuffix[:-5]}_al_junk+orig anat2epi.{subj}.nii.gz
  214. ! rm {t1.strnosuffix[:-5]}_al_junk+orig*
  215. # Invert xfm
  216. ! cat_matvec -ONELINE mat.anat2epi.aff12.1D -I > mat.epi2anat.aff12.1D
  217. # warp the volreg base EPI dataset back to anat to make a final version
  218. ! 3dAllineate -base anat_final.{subj}.nii.gz \
  219. -input epi_mean.nii.gz \
  220. -1Dmatrix_apply mat.epi2anat.aff12.1D \
  221. -prefix epi2anat.{subj}.nii.gz
  222. # Record final registration costs
  223. ! 3dAllineate -base epi2anat.{subj}.nii.gz -allcostX -input anat_final.{subj}.nii.gz > out.allcostX.txt
  224. # Take the snapshots to show the quality of alignment
  225. ! @snapshot_volreg epi2anat.{subj}.nii.gz anat_final.{subj}.nii.gz
  226. ! @snapshot_volreg anat_final.{subj}.nii.gz epi2anat.{subj}.nii.gz
  227. ! @snapshot_volreg anat2epi.{subj}.nii.gz epi_mean.nii.gz
  228. ! @snapshot_volreg epi_mean.nii.gz anat2epi.{subj}.nii.gz
  229. # %% [markdown]
  230. # ## Step 6. epi to individual anat
  231. # %% [markdown]
  232. # 现在我们有了epi到anat的配准,然后我们就可以把所有的epi的文件划到t1的空间。注意,这一步并不是从motion correction之后的文件,也就是pb03.CN003.r0X.volreg+orig。我们要从早distrotion correction之前的文件,把从DC-MC-epi2anat这三个转换一次性的做完
  233. # %%
  234. resolution=2.4
  235. # ======== Transform epi to match anat, add by RZ ===============
  236. # In this step we need to concatenate Distortion(opt)+motion+affine transformations
  237. # align each dset to base volume, then we separate whether we want to further align epi to anat
  238. for run in runstr:
  239. # concatenate MC+aff transforms
  240. ! cat_matvec -ONELINE mat.anat2epi.aff12.1D -I mat.r{run}.vr.aff12.1D > mat.r{run}.warp.aff12.1D
  241. # we apply distortion correction + motion correction + anat2epi transformation
  242. cmd = f'3dNwarpApply -quintic -nwarp "mat.r{run}.warp.aff12.1D blip_warp.r{run}_WARP+orig" \
  243. -master {t1} -dxyz {resolution} \
  244. -source pb02.{subj}.r{run}.tshift+orig \
  245. -prefix rm.epi.nomask.r{run}'
  246. unix_wrapper(cmd)
  247. # create an all-1 dataset to mask the extents of the warp
  248. ! 3dcalc -overwrite -a pb02.{subj}.r{run}.tshift+orig -expr 1 -prefix rm.epi.all1
  249. # we apply distortion correction + motion correction + anat2epi transformation
  250. cmd = f'3dNwarpApply -quintic -nwarp "mat.r{run}.warp.aff12.1D blip_warp.r{run}_WARP+orig" \
  251. -master {t1} -dxyz {resolution} \
  252. -ainterp NN -quiet \
  253. -source rm.epi.all1+orig \
  254. -prefix rm.epi.1.r{run}'
  255. unix_wrapper(cmd)
  256. # make an extents intersection mask of this run across time domain
  257. # this makes a mask that all volumes in this run have valid numbers
  258. ! 3dTstat -min -prefix rm.epi.min.r{run} rm.epi.1.r{run}+orig
  259. # below file is big, should be removed
  260. ! rm rm.epi.1.r{run}+orig*
  261. # %% [markdown]
  262. # 做了变化之后,也要处理一下mask的问题
  263. # %%
  264. # ----------------------------------------
  265. # create the extents mask: mask_epi_extents+orig
  266. # (this is a mask of voxels that have valid data at every TR,
  267. # there might be some pixel out of extents during mc)
  268. ! 3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
  269. # and apply the extents mask to the EPI data
  270. ! 3dcalc -a rm.epi.mean+orig -expr "step(a-0.999)" -prefix mask_epi_extents
  271. # 去掉mask之外的voxel的数据
  272. for run in runstr:
  273. ! 3dcalc -a rm.epi.nomask.r{run}+orig -b mask_epi_extents+orig \
  274. -expr "a*b" -prefix pb05.{subj}.r{run}.al2anat
  275. # save to nifti format seems to reduce file size
  276. # rm.epi.nomask are big files, remove them
  277. ! rm rm.*
  278. # %% [markdown]
  279. # ## Step 7. epi volume 2 surface
  280. # %% [markdown]
  281. # 上一步我们已经把epi数据划到了和个体的结构像一个空间。很多时候我们需要做基于surface的数据分析。我们进一步把三维的epi数据插值划到surface上
  282. # %%
  283. surface_dir = FREESURFER_HOME+f'/subjects/{subj}/SUMA'
  284. # map volume data to the surface of each hemisphere
  285. for hemi in ['lh', 'rh']:
  286. for run in runstr:
  287. ! 3dVol2Surf -spec {surface_dir}/std.141.{subj}_{hemi}.spec \
  288. -sv {subj}_SurfVol+orig \
  289. -surf_A smoothwm \
  290. -surf_B pial \
  291. -f_index nodes \
  292. -f_steps 10 \
  293. -map_func ave \
  294. -oob_value 0 \
  295. -grid_parent pb05.{subj}.r{run}.al2anat+orig \
  296. -out_niml pb05.{subj}.{hemi}.r{run}.surf.niml.dset
  297. # %% [markdown]
  298. # ## Step 8. epi to MNI anat
  299. # %%
  300. # ======== Transform epi to match anat, add by RZ ===============
  301. # In this step we need to concatenate Distortion(opt)+motion+affine transformations
  302. # align each dset to base volume, then we separate whether we want to further align epi to anat
  303. for run in runstr:
  304. # we apply distortion correction + motion correction + anat2epi + nonlinear warp to MNI transformation
  305. # 注意我们这里是相反的顺序来concatenate的
  306. cmd = f'3dNwarpApply -quintic -nwarp "anatQQ.{subj}_WARP.nii anatQQ.{subj}.aff12.1D mat.r{run}.warp.aff12.1D blip_warp.r{run}_WARP+orig" \
  307. -master MNI152_2009_template_SSW.nii.gz \
  308. -dxyz {resolution} \
  309. -source pb02.{subj}.r{run}.tshift+orig \
  310. -prefix rm.epi.nomask.r{run}'
  311. unix_wrapper(cmd)
  312. # create an all-1 dataset to mask the extents of the warp
  313. ! 3dcalc -overwrite -a pb02.{subj}.r{run}.tshift+orig -expr 1 -prefix rm.epi.all1
  314. # we apply distortion correction + motion correction + anat2epi transformation
  315. cmd = f'3dNwarpApply -quintic -nwarp "anatQQ.{subj}_WARP.nii anatQQ.{subj}.aff12.1D mat.r{run}.warp.aff12.1D blip_warp.r{run}_WARP+orig" \
  316. -master MNI152_2009_template_SSW.nii.gz \
  317. -dxyz {resolution} \
  318. -source rm.epi.all1+orig \
  319. -ainterp NN -quiet \
  320. -prefix rm.epi.1.r{run}'
  321. unix_wrapper(cmd)
  322. # make an extents intersection mask of this run across time domain
  323. # this makes a mask that all volumes in this run have valid numbers
  324. ! 3dTstat -min -prefix rm.epi.min.r{run} rm.epi.1.r{run}+tlrc
  325. # below file is big, should be removed
  326. ! rm rm.epi.1.r{run}+tlrc*
  327. # %% [markdown]
  328. # 做了变化之后,也要处理一下mask的问题
  329. # %%
  330. # ----------------------------------------
  331. # create the extents mask: mask_epi_extents+orig
  332. # (this is a mask of voxels that have valid data at every TR,
  333. # there might be some pixel out of extents during mc)
  334. ! 3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
  335. # and apply the extents mask to the EPI data
  336. ! 3dcalc -a rm.epi.mean+tlrc -expr "step(a-0.999)" -prefix mask_epi_2mni_extents
  337. # 去掉mask之外的voxel的数据
  338. for run in runstr:
  339. ! 3dcalc -a rm.epi.nomask.r{run}+tlrc -b mask_epi_2mni_extents+tlrc \
  340. -expr "a*b" -prefix pb06.{subj}.r{run}.al2mni
  341. # save to nifti format seems to reduce file size
  342. # rm.epi.nomask are big files, remove them
  343. ! rm rm.*
  344. # %% [markdown]
  345. # ## Step 8.5 补充步骤,用于进行smooth操作
  346. # %%
  347. # 目的是对上一步step8所生成的pb06进行smooth 生成pb06s
  348. # 再对上上一步step7所生成的pb05***surf.niml文件进行smooth 生成pb05s*rh 和 pb05s*lh
  349. # 再对上上一步step7所生成的pb05.subj.r0*.al2anat+orig文件进行smooth 生成pb05s*.subj.r0*.blur+al2anat+orig
  350. for run in runstr:
  351. ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb06s.{subj}.r{run}.blur+al2mni+tlrc \
  352. pb06.{subj}.r{run}.al2mni+tlrc
  353. for run in runstr:
  354. ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb05s.{subj}.lh.r{run}.blur.surf.niml.dset \
  355. pb05.{subj}.lh.r{run}.surf.niml.dset
  356. for run in runstr:
  357. ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb05s.{subj}.rh.r{run}.blur.surf.niml.dset \
  358. pb05.{subj}.rh.r{run}.surf.niml.dset
  359. for run in runstr:
  360. ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb05s.{subj}.r{run}.blur+al2anat+orig \
  361. pb05.{subj}.r{run}.al2anat+orig
  362. # %% [markdown]
  363. # ## Step 9. 创造一个所有epi和mni模板共有的mask
  364. # %%
  365. # ====================== Mask =================================
  366. # Create 'full_mask' dataset (union mask)
  367. for run in runstr:
  368. ! 3dAutomask -prefix rm.mask_r{run}.nii.gz pb06.{subj}.r{run}.al2mni+tlrc
  369. # 创造一个所有功能像的run合起来的mask
  370. ! 3dmask_tool -inputs rm.mask_r*.nii.gz -union -prefix full_mask.{subj}.nii.gz
  371. ! rm rm.mask*
  372. # ---- create subject anatomy mask, mask_anat.$subj+orig ----
  373. # (resampled from aligned anat)
  374. # 把功能像resample到上面mask的分辨率
  375. ! 3dresample -master full_mask.{subj}.nii.gz -input \
  376. MNI152_2009_template_SSW.nii.gz'[0]' -prefix rm.resam.anat.nii.gz
  377. # convert to binary anat mask; fill gaps and holes
  378. ! 3dmask_tool -dilate_input 5 -5 -fill_holes -input rm.resam.anat.nii.gz \
  379. -prefix mask_anat.{subj}.nii.gz
  380. # 结合功能像和结构像的mask
  381. # compute tighter EPI mask by intersecting with anat mask
  382. ! 3dmask_tool -input full_mask.{subj}.nii.gz mask_anat.{subj}.nii.gz \
  383. -inter -prefix mask_epi_anat.{subj}.nii.gz
  384. # note Dice coefficient of masks, as well
  385. ! 3ddot -dodice full_mask.{subj}.nii.gz mask_anat.{subj}.nii.gz > out.mask_ae_dice.txt
  386. # 删掉多余文件
  387. ! rm rm*
  388. # %% [markdown]
  389. # ## Step 10. scale
  390. # %% [markdown]
  391. # 原始EPI图像的数据可能很大,从几百到4000不等。但是我们一般不考虑这个绝对强度,考虑的是信号增长的比例。所以把数据scale一下, 让所有的voxel的时间序列均值为100
  392. # %%
  393. # scale each voxel time series to have a mean of 100
  394. # (be sure no negatives creep in)
  395. # (subject to a range of [0,200])
  396. # scale volume data
  397. for run in runstr:
  398. ! 3dTstat -prefix rm.mean_r{run} pb06.{subj}.r{run}.al2mni+tlrc
  399. ! 3dcalc -a pb06.{subj}.r{run}.al2mni+tlrc -b rm.mean_r{run}+tlrc \
  400. -c mask_epi_2mni_extents+tlrc \
  401. -expr "c * min(200, a/b*100)*step(a)*step(b)" \
  402. -prefix pb07.{subj}.r{run}.scale
  403. # combine all datasets into one
  404. ! 3dTcat -prefix all_runs.{subj}.nii.gz pb07.{subj}.r*.scale+tlrc*
  405. # remove redundant file
  406. ! rm rm.mean*
  407. # 再scale surface data
  408. for hemi in ['lh', 'rh']:
  409. for run in runstr:
  410. ! 3dTstat -prefix rm.{hemi}.mean_r{run}.niml.dset \
  411. pb05.{subj}.{hemi}.r{run}.surf.niml.dset
  412. ! 3dcalc -a pb05.{subj}.{hemi}.r{run}.surf.niml.dset \
  413. -b rm.{hemi}.mean_r{run}.niml.dset \
  414. -expr 'min(200, a/b*100)*step(a)*step(b)' \
  415. -prefix pb07.{subj}.{hemi}.r{run}.scale.niml.dset
  416. # remove redundant file
  417. ! rm rm.*mean*
  418. # %%
  419. # 注意!!!这个cell的代码是对pb06s 以及pb05s 进行scale重置 也就是经过了smooth的数据
  420. # 生成pb07s*.scale
  421. # 这个文件被整合成all_runs_with_smooth
  422. # 生成pb07s*.scale.niml.dset
  423. # scale volume data
  424. for run in runstr:
  425. ! 3dTstat -prefix rm.mean_r{run} pb06s.{subj}.r{run}.blur+al2mni+tlrc
  426. ! 3dcalc -a pb06s.{subj}.r{run}.blur+al2mni+tlrc -b rm.mean_r{run}+tlrc \
  427. -c mask_epi_2mni_extents+tlrc \
  428. -expr "c * min(200, a/b*100)*step(a)*step(b)" \
  429. -prefix pb07s.{subj}.r{run}.scale
  430. # combine all datasets into one
  431. ! 3dTcat -prefix all_runs_with_smooth.{subj}.nii.gz pb07s.{subj}.r*.scale+tlrc*
  432. # remove redundant file
  433. ! rm rm.mean*
  434. # 再scale surface data
  435. for hemi in ['lh', 'rh']:
  436. for run in runstr:
  437. ! 3dTstat -prefix rm.{hemi}.mean_r{run}.niml.dset \
  438. pb05s.{subj}.{hemi}.r{run}.blur.surf.niml.dset
  439. ! 3dcalc -a pb05s.{subj}.{hemi}.r{run}.blur.surf.niml.dset \
  440. -b rm.{hemi}.mean_r{run}.niml.dset \
  441. -expr 'min(200, a/b*100)*step(a)*step(b)' \
  442. -prefix pb07s.{subj}.{hemi}.r{run}.scale.niml.dset
  443. # remove redundant file
  444. ! rm rm.*mean*
  445. # %% [markdown]
  446. # 到这一步,基本上最主要的预处理就完结了。下一步可以进一步针对surface数据跑GLM,因为afni的surface都是在freesurfer的模板上对其且标准化的,所以surface数据可以直接跑group analysis。也可以在已经划到MNI space上的volume数据跑GLM。以后在volume上跑GLM的结果可以直接用MNI152的T1像来可视化

03_funcpp02_23BPhappy.ipynb at commit d84fb3d, under GPL-3.0 · at the source

Overview

Authors: Yu-Feng Xia1, Yingyan Zhong2, Zi-Jian Cheng1, Enzhao Cong2,3, Yifeng Xu2, Ru-Yuan Zhang4,5,6
  1. Brain Health Institute, National Center for Mental Disorders, Shanghai Mental Health Center, Shanghai Jiao Tong University School of Medicine and School of Psychology, 1954 Huashan Road, Xuhui District, Shanghai 200030, China
  2. Shanghai Mental Health Center, Shanghai Jiao Tong University School of Medicine, 600 Wanping South Road, Shanghai 200030, China
  3. Shanghai Tenth People’s Hospital, School of Medicine, Tongji University, 301 Middle Yanchang Road, Jing’an District, Shanghai 200030, China
  4. School of Psychological and Cognitive Sciences and Beijing Key Laboratory of Behavior and Mental Health, Peking University, 5 Yiheyuan Road, Haidian Distrct, Beijing 100871, China
  5. IDG/McGovern Institute for Brain Research, Peking University, 5 Yiheyuan Road, Haidian Distrct, Beijing 100871, China
  6. Key Laboratory of Machine Perception (Ministry of Education), Peking University, 5 Yiheyuan Road, Haidian Distrct, Beijing 100871, China
Journal: Psychoradiology, volume 6, article kkag015
Dates: received 23 November 2025; accepted 6 April 2026; published online 10 April 2026
Type: Research article · Language: English
License: CC BY-NC
Identifiers: DOI 10.1093/psyrad/kkag015 · PMID 42078071 · PMCID PMC13133896 · OpenAlex W4408886061
Open access: diamond, a free copy (OpenAlex)
Status: code verified
Categories: fMRI (modality), human (organism), depression (population), bipolar (population)
Methods: Statistics, Connectivity, fMRI & imaging
Keywords: bipolar disorder, major depressive disorder, decision-making, functional magnetic resonance imaging, reward prediction error
Journal subjects: Naturalistic Neuroimaging: A New Perspective on Psychiatric Disorders
Topic: Bipolar Disorder and Treatment (Psychiatry and Mental health, Medicine), according to OpenAlex
Citations: not cited yet (Europe PMC); 88 references in the paper

Abstract

Background: The overlapping symptoms between bipolar disorder (BD) and major depressive disorder (MDD) pose a challenge in diagnosis and treatment. A prevailing hypothesis suggests that mood dysregulation may be linked to impairments in the reward system, but the neurocomputational differences between BD and MDD remain elusive. This study investigates whether atypical reward processing affects subjective mood in adolescents with BD and MDD. Our research aims to elucidate the behavioral and neural differences between the two groups, facilitating more accurate and timely diagnosis and intervention.

Methods: Forty-five adolescents (aged ≤ 19 years) diagnosed with BD-II in depressed mood states (N = 25) or MDD (N = 20) completed a risky gambling task while their brain responses were recorded using functional magnetic resonance imaging (fMRI). Several computational models were constructed to uncover the associations between various reward components (e.g. reward prediction errors, RPE) and trial-wise fluctuations in subjective mood during the task.

Results: Adolescents with BD exhibited a lower best choice rate and a higher uncertain choice rate compared to those with MDD. Computational modeling and mediation analysis suggested a tripartite mediating relationship between RPE-mood association, decision rationality, and symptom severity. Using fMRI, we observed significant RPE-related activation in the ventral striatum, which showed a slight positive correlation with the RPE-mood association. We also noted subtle differences in several brain regions (i.e. medial orbitofrontal cortex) between the BD and MDD groups. These differences were further associated with manic symptoms.

Conclusion: Decision rationality mediated the association between RPE-mood association and symptom severity. Relative to adolescents with MDD, those with BD showed decreased decision rationality, along with modest but distinct reward-related neural patterns on fMRI. These findings highlight the crucial role of reward processing in mood regulation and provide preliminary neurocomputational evidence that may inform future diagnostic biomarker development.

Reproduced under the paper's license (CC BY-NC), from the paper cited above.

Repository

Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.

GITSyfX/CCNN-23BPhappy

License: GPL-3.0
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Commit: d84fb3d15c2f5b52575d6eb4d0cbd23a69188870, 20 May 2025
Languages: MATLAB (53), Jupyter (12)
Size: 120 files, 65 scripts
Software Heritage: not archived
Found in: the text, “Computational modeling of mood regulation”
Holds: license file, 12 notebooks
Not found: README, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Statistics and Machine Learning Toolbox (24 files), Psychtoolbox (14 files), AFNI (10 files), Optimization Toolbox (9 files), Parallel Computing Toolbox (9 files), FSL (2 files), SciPy (2 files), FreeSurfer (1 file), Matplotlib (1 file), NumPy (1 file), pandas (1 file), SPM (1 file)
Availability: 1 check, the latest on 29 September 2026: the link answers
  • 29 September 2026: the link answers
66 files

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 65 scripts, each with its path and the digest of its content;
  • 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 29 September 2026: the first record

Recorded: type, language, journal, volume, pages, dates, 6 authors, 5 keywords, 2 funders, 84 references.

Cite

This paper

Xia, Y.-F., Zhong, Y., Cheng, Z.-J., Cong, E., Xu, Y., & Zhang, R.-Y. (2026). Neurocomputational mechanisms of reward-based online mood regulation in adolescents with bipolar disorder and major depressive disorder. Psychoradiology, 6, kkag015. https://doi.org/10.1093/psyrad/kkag015

BibTeX

@article{xia2026neurocomputational,
author = {Xia, Yu-Feng and Zhong, Yingyan and Cheng, Zi-Jian and Cong, Enzhao and Xu, Yifeng and Zhang, Ru-Yuan},
title = {{Neurocomputational mechanisms of reward-based online mood regulation in adolescents with bipolar disorder and major depressive disorder}},
journal = {Psychoradiology},
year = {2026},
month = apr,
volume = {6},
pages = {kkag015},
publisher = {Oxford University Press},
issn = {2634-4416},
doi = {10.1093/psyrad/kkag015},
url = {https://doi.org/10.1093/psyrad/kkag015},
pmid = {42078071},
pmcid = {PMC13133896}
}

RIS

TY - JOUR
AU - Xia, Yu-Feng
AU - Zhong, Yingyan
AU - Cheng, Zi-Jian
AU - Cong, Enzhao
AU - Xu, Yifeng
AU - Zhang, Ru-Yuan
TI - Neurocomputational mechanisms of reward-based online mood regulation in adolescents with bipolar disorder and major depressive disorder
T2 - Psychoradiology
J2 - Psychoradiology
PY - 2026
DA - 2026/04/10
VL - 6
SP - kkag015
SN - 2634-4416
PB - Oxford University Press
DO - 10.1093/psyrad/kkag015
UR - https://doi.org/10.1093/psyrad/kkag015
LA - en
ER -

CSL-JSON

{
"id": "10.1093/psyrad/kkag015",
"type": "article-journal",
"title": "Neurocomputational mechanisms of reward-based online mood regulation in adolescents with bipolar disorder and major depressive disorder",
"container-title": "Psychoradiology",
"author": [
{
"family": "Xia",
"given": "Yu-Feng"
},
{
"family": "Zhong",
"given": "Yingyan"
},
{
"family": "Cheng",
"given": "Zi-Jian"
},
{
"family": "Cong",
"given": "Enzhao"
},
{
"family": "Xu",
"given": "Yifeng"
},
{
"family": "Zhang",
"given": "Ru-Yuan"
}
],
"container-title-short": "Psychoradiology",
"volume": "6",
"page": "kkag015",
"DOI": "10.1093/psyrad/kkag015",
"PMID": "42078071",
"PMCID": "PMC13133896",
"ISSN": "2634-4416",
"publisher": "Oxford University Press",
"URL": "https://doi.org/10.1093/psyrad/kkag015",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
10
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-71151-2 [code]
Common and distinct neural correlates of social interaction processing and theory of mind in narratives.
Journal: Nature communications
In common: Psychtoolbox, AFNI, Optimization Toolbox, 9 other tools
[2] doi:10.2147/opth.s590186 [code]
Differential Effects of Balanced and Imbalanced Binocular Stimulation on Visual Cortex Responses in Amblyopic Children.
Journal: Clinical ophthalmology (Auckland, N.Z.)
In common: Psychtoolbox, AFNI, Parallel Computing Toolbox, 7 other tools, fMRI, 1 reference
[3] doi:10.1038/s41586-026-10631-3 [code]
A prognostic human brain network for diffuse midline glioma.
Journal: Nature
In common: Psychtoolbox, Optimization Toolbox, Parallel Computing Toolbox, 8 other tools
[4] doi:10.1002/hbm.70577 [code]
Disgust Propensity, Not Disgust Sensitivity, Shapes the Reactivity of a Subjective Disgust Circuit in Humans.
Journal: Human brain mapping
In common: AFNI, Optimization Toolbox, Parallel Computing Toolbox, 7 other tools, fMRI
[5] doi:10.1038/s42003-026-10276-y [code]
The cellular correlates and adolescent reorganisation of cortical myelination networks in the common marmoset.
Journal: Communications biology
In common: AFNI, Optimization Toolbox, Parallel Computing Toolbox, 7 other tools, 1 reference
[6] doi:10.1162/imag.a.1262 [code]
Frame-wise multi-echo distortion correction for superior functional MRI.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Optimization Toolbox, Parallel Computing Toolbox, FreeSurfer, 7 other tools, fMRI, 1 reference
[7] doi:10.1038/s41597-026-07676-4 [code]
A neuroimaging dataset combining movie-watching, eye-tracking, sensorimotor mapping, and cognitive tasks.
Journal: Scientific data
In common: AFNI, Parallel Computing Toolbox, FreeSurfer, 7 other tools, 1 reference
[8] doi:10.1038/s41467-026-74565-0 [code]
The functional neurobiology of dispositions towards negative emotions.
Journal: Nature communications
In common: AFNI, Optimization Toolbox, Parallel Computing Toolbox, 7 other tools
[9] doi:10.1016/j.neuron.2026.04.011 [code]
Precision fMRI reveals densely interdigitated network patches with conserved motifs in the lateral prefrontal cortex.
Journal: Neuron
In common: AFNI, Parallel Computing Toolbox, FreeSurfer, 6 other tools, fMRI, 1 reference
[10] doi:10.1016/j.cub.2026.05.068 [code]
An abstract relational map emerges in the human medial prefrontal cortex with consolidation.
Journal: Current biology : CB
In common: AFNI, Optimization Toolbox, FreeSurfer, 7 other tools, fMRI

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.