Neurocomputational mechanisms of reward-based online mood regulation in adolescents with bipolar disorder and major depressive disorder.
The 3 matches
- [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] § 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] § 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
- # %% [markdown]
- # # 03_funcpp02
- # %% [markdown]
- # 功能像预处理的最核心部分。这一部分我们完成一下步骤
- # * Despike
- # * Slice-timing correction (时间层矫正)
- # * Distortion correction (图像畸变矫正)
- # * Motion correction (头动矫正)
- # * align anat 2 epi (结构像到功能像的配准)
- # * 把所有epi划到个体结构像空间
- # * 把所有epi的volume数据划到surface data
- # * 把所有epi的划到MNI标准空间
- # * Scale (标准化数据尺度,抓换成percent signal change)
- # %% [markdown]
- # ## Step 1. Despike
- # %%
- # ================================ despike =================================
- for run in runstr:
- ! 3dDespike -NEW -nomask -prefix pb01.{subj}.r{run}.despike pb00.{subj}.r{run}.tcat+orig
- ! rm pb00*
- # %% [markdown]
- # ## Step 2. Slice-timing correction
- # %%
- # ================================= tshift =================================
- for run in runstr:
- ! 3dTshift -tzero 0 -quintic -prefix pb02.{subj}.r{run}.tshift \
- -verbose -tpattern @{'../SliceTiming.txt'} pb01.{subj}.r{run}.despike+orig
- # 删掉上一步despike的data节省空间
- ! rm pb01*
- # %% [markdown]
- # ## Step 3. Distortion correction
- # %% [markdown]
- # 因为磁场不均匀的关系,图像会出现畸变。现在来做矫正。
- # %%
- # 首先找到
- for fwd,rev in zip(fwdfiles, revfiles):
- # create median datasets from forward and reverse time series
- ! 3dTstat -median -prefix rm.blip.med.fwd.r{fwd} pb02.{subj}.r{fwd}.tshift+orig
- ! 3dTstat -median -prefix rm.blip.med.rev.r{rev} pb02.{subj}.r{rev}.tshift+orig
- # automask the median datasets
- ! 3dAutomask -apply_prefix rm.blip.med.masked.fwd.r{fwd} rm.blip.med.fwd.r{fwd}+orig
- ! 3dAutomask -apply_prefix rm.blip.med.masked.rev.r{rev} rm.blip.med.rev.r{rev}+orig
- # compute the midpoint warp between the median datasets
- ! 3dQwarp -plusminus -pmNAMES Rev.r{rev} Fwd.r{fwd} \
- -pblur 0.05 0.05 -blur -1 -1 \
- -noweight -minpatch 9 \
- -noXdis -noZdis \
- -source rm.blip.med.masked.rev.r{rev}+orig \
- -base rm.blip.med.masked.fwd.r{fwd}+orig \
- -prefix blip_warp
- ! 3dNwarpApply -quintic -nwarp blip_warp_Fwd.r{fwd}_WARP+orig \
- -source rm.blip.med.masked.fwd.r{fwd}+orig \
- -prefix rm.blip.med.masked.fwd.post.r{fwd}
- ! 3dNwarpApply -quintic -nwarp blip_warp_Rev.r{rev}_WARP+orig \
- -source rm.blip.med.masked.rev.r{rev}+orig \
- -prefix rm.blip.med.masked.rev.post.r{rev}
- # 删掉多余文件
- ! rm blip_warp_Fwd.r{fwd}+orig* blip_warp_Rev.r{rev}+orig*
- # 修改个名字以便以后的操作
- ! 3dcopy blip_warp_Fwd.r{fwd}_WARP+orig blip_warp.r{fwd}_WARP+orig
- ! 3dcopy blip_warp_Rev.r{rev}_WARP+orig blip_warp.r{rev}_WARP+orig
- ! 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*
- # for QC check,我们生成一个校正前和矫正后的平均EPI数据来作为distortion correction的效果证明
- ! 3dMean -prefix blip_pre_fwd.epi_mean.nii.gz rm.blip.med.masked.fwd.r*
- ! 3dMean -prefix blip_pre_rev.epi_mean.nii.gz rm.blip.med.masked.rev.r*
- ! 3dMean -prefix blip_post_fwd.epi_mean.nii.gz rm.blip.med.masked.fwd.post.r*
- ! 3dMean -prefix blip_post_rev.epi_mean.nii.gz rm.blip.med.masked.rev.post.r*
- # remove redundent file
- ! rm rm*
- # %% [markdown]
- # 这一步完成之后,可以手动打开
- # * blip_pre_fwd.epi_mean.nii.gz
- # * blip_pre_rev.epi_mean.nii.gz
- # * blip_post_fwd.epi_mean.nii.gz
- # * blip_post_rev.epi_mean.nii.gz
- #
- # 这四个文件也记录了对侧矫正的效果,只要有矫正效果,没有什么大问题即可。
- #
- # 然后把所有的run都做correction
- # %%
- for run in runstr:
- ! 3dNwarpApply -quintic -nwarp blip_warp.r{run}_WARP+orig \
- -source pb02.{subj}.r{run}.tshift+orig \
- -prefix pb03.{subj}.r{run}.blip
- # %% [markdown]
- # ## Step 4. Motion correction
- # %% [markdown]
- # 首先做motion correction。但是我们并不用其结果,主要是得到mc的线性转换矩阵
- # %%
- runstr.pop() #删去AP参照序列
- # ================================= volreg =================================
- base = 'vr_base_min_outlier+orig' #在前面生成
- # align each dset to base volume, then we separate whether we want to further align epi to anat
- for run in runstr:
- # register each volume to the base image
- ! 3dvolreg -verbose -zpad 1 -base {base} \
- -1Dfile dfile.r{run}.1D \
- -cubic \
- -1Dmatrix_save mat.r{run}.vr.aff12.1D \
- -prefix rm.epi.nomask.r{run} pb03.{subj}.r{run}.blip+orig
- # create an all-1 dataset to mask the extents of the warp
- ! 3dcalc -overwrite -a pb03.{subj}.r{run}.blip+orig -expr 1 -prefix rm.epi.all1
- # warp the all-1 dataset for extents masking
- ! 3dAllineate -base {base} \
- -input rm.epi.all1+orig \
- -1Dmatrix_apply mat.r{run}.vr.aff12.1D \
- -final NN -quiet \
- -prefix rm.epi.1.r{run}
- # make an extents intersection mask of this run across time domain
- # this makes a mask that all volumes in this run have valid numbers
- ! 3dTstat -min -prefix rm.epi.min.r{run} rm.epi.1.r{run}+orig
- # %% [markdown]
- # 计算更多的头动数值,以后可以用来GLM中的regressor
- # %%
- # 生成pb04.subj.r0*+volreg+orig
- # 生成epi_mean.nii.gz
- # motion打头的几个文件
- # 生成mc文件夹,里面放了矫正结果比较
- nRuns = nRuns-1
- # we take dmeaned motion (6), demean motion derivative (6) and their squares (12)
- # 合并 motion params
- ! cat dfile.r*.1D > dfile_rall.1D
- # 计算去均值的motion parameters (for use in regression)
- ! 1d_tool.py -infile dfile_rall.1D -set_nruns {nRuns} -demean -write motion_demean.1D
- # 计算一阶导数 (just to have)
- ! 1d_tool.py -infile dfile_rall.1D -set_nruns {nRuns} -derivative -demean -write motion_deriv.1D
- # calculate the square of demean and derivative of motion parameters (just to have)
- # for resting preproc, we usually have 24 motion regressor (6motion+6deriv+12 their square)
- np.savetxt('motion_demeansq.1D', np.loadtxt('motion_demean.1D')**2)
- np.savetxt('motion_derivsq.1D', np.loadtxt('motion_deriv.1D')**2)
- # create censor file motion_${subj}_censor.1D, for censoring motion
- ! 1d_tool.py -infile dfile_rall.1D -set_nruns {nRuns} \
- -show_censor_count -censor_prev_TR \
- -censor_motion {motion_censor} motion_{subj}
- # Estimate the motion parameter after motion correction, we can check the
- # effects of MC
- ! mkdir mc
- for run in runstr:
- ! 3dvolreg -verbose -zpad 1 -base {base} \
- -1Dfile dfile.r{run}_pos.1D \
- rm.epi.nomask.r{run}+orig
- ! rm volreg+orig*
- # make a single file of motion params
- ! cat dfile.r*_pos.1D > dfile_rall_pos.1D
- # make figure pre mc
- dfile_pre = np.loadtxt('dfile_rall.1D')
- plot(range(dfile_pre.shape[0]), dfile_pre[:,:3], color=['C0','C1','C2'], label=['roll(IS)','pitch(RL)','yaw(AP)'])
- plt.legend();plt.xlabel('time points');plt.ylabel('mm');
- plt.savefig('rots_pre.pdf');plt.close('all')
- plot(range(dfile_pre.shape[0]), dfile_pre[:,3:], color=['C3','C4','C5'], label=['dS','dL','dP'])
- plt.legend();plt.xlabel('time points (TR)');plt.ylabel('mm');
- plt.savefig('tran_pre.pdf');plt.close('all')
- # make figure pos mc
- dfile_pos = np.loadtxt('dfile_rall_pos.1D')
- plot(range(dfile_pos.shape[0]), dfile_pos[:,:3], color=['C0','C1','C2'], label=['roll(IS)','pitch(RL)','yaw(AP)'])
- plt.legend();plt.xlabel('time points');plt.ylabel('mm');
- plt.savefig('rots_pos.pdf');plt.close('all')
- plot(range(dfile_pos.shape[0]), dfile_pos[:,3:], color=['C3','C4','C5'], label=['dS','dL','dP'])
- plt.legend();plt.xlabel('time points (TR)');plt.ylabel('mm');
- plt.savefig('tran_pos.pdf');plt.close('all')
- # move file to directory
- ! mv rots*.pdf tran*.pdf dfile.r*_pos.1D dfile_r*_pos.1D mc/
- # note TRs that were not censored, note ktrs here is a str
- ktrs = unix_wrapper(f'1d_tool.py -infile motion_{subj}_censor.1D \
- -show_trs_uncensored encoded', wantreturn=True, verbose=0)
- # ----------------------------------------
- # create the extents mask: mask_epi_extents+orig and apply the task
- # (this is a mask of voxels that have valid data at every TR,
- # there might be some pixel out of extents during mc)
- ! 3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
- ! 3dcalc -a rm.epi.mean+orig -expr "step(a-0.999)" -prefix mask_epi_extents
- # and apply the extents mask to the EPI data
- # (delete any time series with missing data)
- for run in runstr:
- ! 3dcalc -a rm.epi.nomask.r{run}+orig -b mask_epi_extents+orig \
- -expr "a*b" -prefix pb04.{subj}.r{run}.volreg
- ! rm -f rm.* # rm.epi.nomask are big files, remove them
- ! rm -f {base}*
- # calculate a mean epi volume for next step anat epi registration
- ! 3dMean -prefix rm.epi_mean.nii.gz pb04.{subj}.r*.volreg+orig.HEAD
- ! 3dTstat -prefix epi_mean.nii.gz rm.epi_mean.nii.gz
- ! rm rm* mask_epi_extents+orig*
- # 删掉上一步distortion correction的数据,节省空间
- ! rm pb03*
- # %% [markdown]
- # ## Step 5. anat2epi
- # %% [markdown]
- # 这一步非常重要,是前面处理好的功能像和结构像进行配准,配准的结果一定要手动检查
- # %%
- # 首先把用来配准的epi像make a copy
- ! 3dcopy epi_mean.nii.gz epi_mean_tmp.nii.gz
- # 关键步骤。我们是把结构像配准到功能像,但是我们得到的转换矩阵是从相反的,功能像到结构像,这个矩阵可以后面用来转化epi数据
- #
- ! align_epi_anat.py -anat2epi -anat {t1.str} \
- -save_skullstrip -suffix _al_junk \
- -epi epi_mean_tmp.nii.gz -epi_base 0 \
- -epi_strip 3dAutomask \
- -volreg off -tshift off -giant_move
- # 生成nifti文件,方便我们在fsleyes上面查看配准效果
- ! 3dcopy {subj}_SurfVol_al_junk+orig {subj}_SurfVol_al_junk.nii.gz
- # %% [markdown]
- # 完成上面一步之后,要打开fsleyes仔细检查配准的结果,其中underlay选择CN003_SurfVol_al_junk+orig, overlay选择epi_mean_tmp+orig。然后检查两者是否一致。如果不匹配,则需要重新进行上面的过程,在开始之前,需要先删除上面产生的文件。可以做
- # ! rm {subj}_SurfVol_al* {subj}_SurfVol_ns*
- # 确认配准没有问题之后,进行下一步操作
- # %%
- # note that we align anat 2 epi, however, this xfm is from epi space to anat space
- # note that this xfm is compatible with LPS+ space, which is the default space in AFNI
- ! mv {t1.strnosuffix[:-5]}_al_junk_mat.aff12.1D mat.anat2epi.aff12.1D
- # create an skull-striped anat_final dataset, aligned with stats
- ! 3dcopy {t1.strnosuffix[:-5]}_ns+orig anat_final.{subj}.nii.gz
- ! rm {t1.strnosuffix[:-5]}_ns+orig*
- # rewrite the name of aligned anat
- ! 3dcopy {t1.strnosuffix[:-5]}_al_junk+orig anat2epi.{subj}.nii.gz
- ! rm {t1.strnosuffix[:-5]}_al_junk+orig*
- # Invert xfm
- ! cat_matvec -ONELINE mat.anat2epi.aff12.1D -I > mat.epi2anat.aff12.1D
- # warp the volreg base EPI dataset back to anat to make a final version
- ! 3dAllineate -base anat_final.{subj}.nii.gz \
- -input epi_mean.nii.gz \
- -1Dmatrix_apply mat.epi2anat.aff12.1D \
- -prefix epi2anat.{subj}.nii.gz
- # Record final registration costs
- ! 3dAllineate -base epi2anat.{subj}.nii.gz -allcostX -input anat_final.{subj}.nii.gz > out.allcostX.txt
- # Take the snapshots to show the quality of alignment
- ! @snapshot_volreg epi2anat.{subj}.nii.gz anat_final.{subj}.nii.gz
- ! @snapshot_volreg anat_final.{subj}.nii.gz epi2anat.{subj}.nii.gz
- ! @snapshot_volreg anat2epi.{subj}.nii.gz epi_mean.nii.gz
- ! @snapshot_volreg epi_mean.nii.gz anat2epi.{subj}.nii.gz
- # %% [markdown]
- # ## Step 6. epi to individual anat
- # %% [markdown]
- # 现在我们有了epi到anat的配准,然后我们就可以把所有的epi的文件划到t1的空间。注意,这一步并不是从motion correction之后的文件,也就是pb03.CN003.r0X.volreg+orig。我们要从早distrotion correction之前的文件,把从DC-MC-epi2anat这三个转换一次性的做完
- # %%
- resolution=2.4
- # ======== Transform epi to match anat, add by RZ ===============
- # In this step we need to concatenate Distortion(opt)+motion+affine transformations
- # align each dset to base volume, then we separate whether we want to further align epi to anat
- for run in runstr:
- # concatenate MC+aff transforms
- ! cat_matvec -ONELINE mat.anat2epi.aff12.1D -I mat.r{run}.vr.aff12.1D > mat.r{run}.warp.aff12.1D
- # we apply distortion correction + motion correction + anat2epi transformation
- cmd = f'3dNwarpApply -quintic -nwarp "mat.r{run}.warp.aff12.1D blip_warp.r{run}_WARP+orig" \
- -master {t1} -dxyz {resolution} \
- -source pb02.{subj}.r{run}.tshift+orig \
- -prefix rm.epi.nomask.r{run}'
- unix_wrapper(cmd)
- # create an all-1 dataset to mask the extents of the warp
- ! 3dcalc -overwrite -a pb02.{subj}.r{run}.tshift+orig -expr 1 -prefix rm.epi.all1
- # we apply distortion correction + motion correction + anat2epi transformation
- cmd = f'3dNwarpApply -quintic -nwarp "mat.r{run}.warp.aff12.1D blip_warp.r{run}_WARP+orig" \
- -master {t1} -dxyz {resolution} \
- -ainterp NN -quiet \
- -source rm.epi.all1+orig \
- -prefix rm.epi.1.r{run}'
- unix_wrapper(cmd)
- # make an extents intersection mask of this run across time domain
- # this makes a mask that all volumes in this run have valid numbers
- ! 3dTstat -min -prefix rm.epi.min.r{run} rm.epi.1.r{run}+orig
- # below file is big, should be removed
- ! rm rm.epi.1.r{run}+orig*
- # %% [markdown]
- # 做了变化之后,也要处理一下mask的问题
- # %%
- # ----------------------------------------
- # create the extents mask: mask_epi_extents+orig
- # (this is a mask of voxels that have valid data at every TR,
- # there might be some pixel out of extents during mc)
- ! 3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
- # and apply the extents mask to the EPI data
- ! 3dcalc -a rm.epi.mean+orig -expr "step(a-0.999)" -prefix mask_epi_extents
- # 去掉mask之外的voxel的数据
- for run in runstr:
- ! 3dcalc -a rm.epi.nomask.r{run}+orig -b mask_epi_extents+orig \
- -expr "a*b" -prefix pb05.{subj}.r{run}.al2anat
- # save to nifti format seems to reduce file size
- # rm.epi.nomask are big files, remove them
- ! rm rm.*
- # %% [markdown]
- # ## Step 7. epi volume 2 surface
- # %% [markdown]
- # 上一步我们已经把epi数据划到了和个体的结构像一个空间。很多时候我们需要做基于surface的数据分析。我们进一步把三维的epi数据插值划到surface上
- # %%
- surface_dir = FREESURFER_HOME+f'/subjects/{subj}/SUMA'
- # map volume data to the surface of each hemisphere
- for hemi in ['lh', 'rh']:
- for run in runstr:
- ! 3dVol2Surf -spec {surface_dir}/std.141.{subj}_{hemi}.spec \
- -sv {subj}_SurfVol+orig \
- -surf_A smoothwm \
- -surf_B pial \
- -f_index nodes \
- -f_steps 10 \
- -map_func ave \
- -oob_value 0 \
- -grid_parent pb05.{subj}.r{run}.al2anat+orig \
- -out_niml pb05.{subj}.{hemi}.r{run}.surf.niml.dset
- # %% [markdown]
- # ## Step 8. epi to MNI anat
- # %%
- # ======== Transform epi to match anat, add by RZ ===============
- # In this step we need to concatenate Distortion(opt)+motion+affine transformations
- # align each dset to base volume, then we separate whether we want to further align epi to anat
- for run in runstr:
- # we apply distortion correction + motion correction + anat2epi + nonlinear warp to MNI transformation
- # 注意我们这里是相反的顺序来concatenate的
- 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" \
- -master MNI152_2009_template_SSW.nii.gz \
- -dxyz {resolution} \
- -source pb02.{subj}.r{run}.tshift+orig \
- -prefix rm.epi.nomask.r{run}'
- unix_wrapper(cmd)
- # create an all-1 dataset to mask the extents of the warp
- ! 3dcalc -overwrite -a pb02.{subj}.r{run}.tshift+orig -expr 1 -prefix rm.epi.all1
- # we apply distortion correction + motion correction + anat2epi transformation
- 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" \
- -master MNI152_2009_template_SSW.nii.gz \
- -dxyz {resolution} \
- -source rm.epi.all1+orig \
- -ainterp NN -quiet \
- -prefix rm.epi.1.r{run}'
- unix_wrapper(cmd)
- # make an extents intersection mask of this run across time domain
- # this makes a mask that all volumes in this run have valid numbers
- ! 3dTstat -min -prefix rm.epi.min.r{run} rm.epi.1.r{run}+tlrc
- # below file is big, should be removed
- ! rm rm.epi.1.r{run}+tlrc*
- # %% [markdown]
- # 做了变化之后,也要处理一下mask的问题
- # %%
- # ----------------------------------------
- # create the extents mask: mask_epi_extents+orig
- # (this is a mask of voxels that have valid data at every TR,
- # there might be some pixel out of extents during mc)
- ! 3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
- # and apply the extents mask to the EPI data
- ! 3dcalc -a rm.epi.mean+tlrc -expr "step(a-0.999)" -prefix mask_epi_2mni_extents
- # 去掉mask之外的voxel的数据
- for run in runstr:
- ! 3dcalc -a rm.epi.nomask.r{run}+tlrc -b mask_epi_2mni_extents+tlrc \
- -expr "a*b" -prefix pb06.{subj}.r{run}.al2mni
- # save to nifti format seems to reduce file size
- # rm.epi.nomask are big files, remove them
- ! rm rm.*
- # %% [markdown]
- # ## Step 8.5 补充步骤,用于进行smooth操作
- # %%
- # 目的是对上一步step8所生成的pb06进行smooth 生成pb06s
- # 再对上上一步step7所生成的pb05***surf.niml文件进行smooth 生成pb05s*rh 和 pb05s*lh
- # 再对上上一步step7所生成的pb05.subj.r0*.al2anat+orig文件进行smooth 生成pb05s*.subj.r0*.blur+al2anat+orig
- for run in runstr:
- ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb06s.{subj}.r{run}.blur+al2mni+tlrc \
- pb06.{subj}.r{run}.al2mni+tlrc
- for run in runstr:
- ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb05s.{subj}.lh.r{run}.blur.surf.niml.dset \
- pb05.{subj}.lh.r{run}.surf.niml.dset
- for run in runstr:
- ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb05s.{subj}.rh.r{run}.blur.surf.niml.dset \
- pb05.{subj}.rh.r{run}.surf.niml.dset
- for run in runstr:
- ! 3dmerge -1blur_fwhm 4.0 -doall -prefix pb05s.{subj}.r{run}.blur+al2anat+orig \
- pb05.{subj}.r{run}.al2anat+orig
- # %% [markdown]
- # ## Step 9. 创造一个所有epi和mni模板共有的mask
- # %%
- # ====================== Mask =================================
- # Create 'full_mask' dataset (union mask)
- for run in runstr:
- ! 3dAutomask -prefix rm.mask_r{run}.nii.gz pb06.{subj}.r{run}.al2mni+tlrc
- # 创造一个所有功能像的run合起来的mask
- ! 3dmask_tool -inputs rm.mask_r*.nii.gz -union -prefix full_mask.{subj}.nii.gz
- ! rm rm.mask*
- # ---- create subject anatomy mask, mask_anat.$subj+orig ----
- # (resampled from aligned anat)
- # 把功能像resample到上面mask的分辨率
- ! 3dresample -master full_mask.{subj}.nii.gz -input \
- MNI152_2009_template_SSW.nii.gz'[0]' -prefix rm.resam.anat.nii.gz
- # convert to binary anat mask; fill gaps and holes
- ! 3dmask_tool -dilate_input 5 -5 -fill_holes -input rm.resam.anat.nii.gz \
- -prefix mask_anat.{subj}.nii.gz
- # 结合功能像和结构像的mask
- # compute tighter EPI mask by intersecting with anat mask
- ! 3dmask_tool -input full_mask.{subj}.nii.gz mask_anat.{subj}.nii.gz \
- -inter -prefix mask_epi_anat.{subj}.nii.gz
- # note Dice coefficient of masks, as well
- ! 3ddot -dodice full_mask.{subj}.nii.gz mask_anat.{subj}.nii.gz > out.mask_ae_dice.txt
- # 删掉多余文件
- ! rm rm*
- # %% [markdown]
- # ## Step 10. scale
- # %% [markdown]
- # 原始EPI图像的数据可能很大,从几百到4000不等。但是我们一般不考虑这个绝对强度,考虑的是信号增长的比例。所以把数据scale一下, 让所有的voxel的时间序列均值为100
- # %%
- # scale each voxel time series to have a mean of 100
- # (be sure no negatives creep in)
- # (subject to a range of [0,200])
- # scale volume data
- for run in runstr:
- ! 3dTstat -prefix rm.mean_r{run} pb06.{subj}.r{run}.al2mni+tlrc
- ! 3dcalc -a pb06.{subj}.r{run}.al2mni+tlrc -b rm.mean_r{run}+tlrc \
- -c mask_epi_2mni_extents+tlrc \
- -expr "c * min(200, a/b*100)*step(a)*step(b)" \
- -prefix pb07.{subj}.r{run}.scale
- # combine all datasets into one
- ! 3dTcat -prefix all_runs.{subj}.nii.gz pb07.{subj}.r*.scale+tlrc*
- # remove redundant file
- ! rm rm.mean*
- # 再scale surface data
- for hemi in ['lh', 'rh']:
- for run in runstr:
- ! 3dTstat -prefix rm.{hemi}.mean_r{run}.niml.dset \
- pb05.{subj}.{hemi}.r{run}.surf.niml.dset
- ! 3dcalc -a pb05.{subj}.{hemi}.r{run}.surf.niml.dset \
- -b rm.{hemi}.mean_r{run}.niml.dset \
- -expr 'min(200, a/b*100)*step(a)*step(b)' \
- -prefix pb07.{subj}.{hemi}.r{run}.scale.niml.dset
- # remove redundant file
- ! rm rm.*mean*
- # %%
- # 注意!!!这个cell的代码是对pb06s 以及pb05s 进行scale重置 也就是经过了smooth的数据
- # 生成pb07s*.scale
- # 这个文件被整合成all_runs_with_smooth
- # 生成pb07s*.scale.niml.dset
- # scale volume data
- for run in runstr:
- ! 3dTstat -prefix rm.mean_r{run} pb06s.{subj}.r{run}.blur+al2mni+tlrc
- ! 3dcalc -a pb06s.{subj}.r{run}.blur+al2mni+tlrc -b rm.mean_r{run}+tlrc \
- -c mask_epi_2mni_extents+tlrc \
- -expr "c * min(200, a/b*100)*step(a)*step(b)" \
- -prefix pb07s.{subj}.r{run}.scale
- # combine all datasets into one
- ! 3dTcat -prefix all_runs_with_smooth.{subj}.nii.gz pb07s.{subj}.r*.scale+tlrc*
- # remove redundant file
- ! rm rm.mean*
- # 再scale surface data
- for hemi in ['lh', 'rh']:
- for run in runstr:
- ! 3dTstat -prefix rm.{hemi}.mean_r{run}.niml.dset \
- pb05s.{subj}.{hemi}.r{run}.blur.surf.niml.dset
- ! 3dcalc -a pb05s.{subj}.{hemi}.r{run}.blur.surf.niml.dset \
- -b rm.{hemi}.mean_r{run}.niml.dset \
- -expr 'min(200, a/b*100)*step(a)*step(b)' \
- -prefix pb07s.{subj}.{hemi}.r{run}.scale.niml.dset
- # remove redundant file
- ! rm rm.*mean*
- # %% [markdown]
- # 到这一步,基本上最主要的预处理就完结了。下一步可以进一步针对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
- 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
- Shanghai Mental Health Center, Shanghai Jiao Tong University School of Medicine, 600 Wanping South Road, Shanghai 200030, China
- Shanghai Tenth People’s Hospital, School of Medicine, Tongji University, 301 Middle Yanchang Road, Jing’an District, Shanghai 200030, China
- 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
- IDG/McGovern Institute for Brain Research, Peking University, 5 Yiheyuan Road, Haidian Distrct, Beijing 100871, China
- Key Laboratory of Machine Perception (Ministry of Education), Peking University, 5 Yiheyuan Road, Haidian Distrct, Beijing 100871, China
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
d84fb3d15c2f5b52575d6eb4d0cbd23a69188870, 20 May 2025Availability: 1 check, the latest on 29 September 2026: the link answers
- 29 September 2026: the link answers
66 files
- Exp/
4player/ , MATLAB, 18 linesgene_gif_array.m - Exp/
materials/ , MATLAB, 24 linesGetRectFrame.m - Exp/
materials/ , MATLAB, 23 linesGetRectFrame2.m - Exp/
materials/ , MATLAB, 95 linesShuffle.m - Exp/
materials/ , MATLAB, 9 linescheckend.m - Exp/
materials/ , MATLAB, 6 linesdraw_text_dot.m - Exp/
materials/ , MATLAB, 9 linesdrawcenteredtext.m - Exp/
materials/ , MATLAB, 10 linesdrawcenteredtext_dot.m - Exp/
materials/ , MATLAB, 9 linesdrawfix.m - Exp/
materials/ , MATLAB, 17 linesget_ITI_list.m - Exp/
materials/ , MATLAB, 39 linesget_frame_info.m - Exp/
materials/ , MATLAB, 33 linesget_trial_list.m - Exp/
materials/ , MATLAB, 43 linesget_trial_list_for_risky _decision.m - Exp/
materials/ , MATLAB, 37 linesinit_screen.m - Exp/
practice_risky_decision. , MATLAB, 382 linesm - Exp/
pre_post_test.m , MATLAB, 157 lines - Exp/
resting.m , MATLAB, 69 lines - Exp/
sub_info.m , MATLAB, 49 lines - Exp/
task1_risky_decision.m , MATLAB, 422 lines - Exp/
task2_step1_demo_in.m , MATLAB, 212 lines - Exp/
task2_step2_in.m , MATLAB, 305 lines - Exp/
task2_step3_out.m , MATLAB, 306 lines - Modelfit/
Model_Comparison/ , MATLAB, 177 linesModel_Comparision.m - Modelfit/
Model_Comparison/ , MATLAB, 48 linesrecord_model1/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 31 linesrecord_model1/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 105 linesrecord_model1/ fit_risky_decision_nonli n.m - Modelfit/
Model_Comparison/ , MATLAB, 67 linesrecord_model10/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 24 linesrecord_model10/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 105 linesrecord_model10/ fit_risky_decision_model 11.m - Modelfit/
Model_Comparison/ , MATLAB, 42 linesrecord_model2/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 24 linesrecord_model2/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 102 linesrecord_model2/ fit_risky_decision_model 2.m - Modelfit/
Model_Comparison/ , MATLAB, 48 linesrecord_model3/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 32 linesrecord_model3/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 105 linesrecord_model3/ fit_risky_decision_model 3.m - Modelfit/
Model_Comparison/ , MATLAB, 49 linesrecord_model4/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 32 linesrecord_model4/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 107 linesrecord_model4/ fit_risky_decision_model 4.m - Modelfit/
Model_Comparison/ , MATLAB, 47 linesrecord_model5/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 31 linesrecord_model5/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 105 linesrecord_model5/ fit_risky_decision_model 5.m - Modelfit/
Model_Comparison/ , MATLAB, 49 linesrecord_model6/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 31 linesrecord_model6/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 105 linesrecord_model6/ fit_risky_decision_model 6.m - Modelfit/
Model_Comparison/ , MATLAB, 55 linesrecord_model7/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 31 linesrecord_model7/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 106 linesrecord_model7/ fit_risky_decision_model 8.m - Modelfit/
Model_Comparison/ , MATLAB, 55 linesrecord_model8/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 31 linesrecord_model8/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 110 linesrecord_model8/ fit_risky_decision_model 9.m - Modelfit/
Model_Comparison/ , MATLAB, 66 linesrecord_model9/ fit_happiness.m - Modelfit/
Model_Comparison/ , MATLAB, 24 linesrecord_model9/ fit_plot.m - Modelfit/
Model_Comparison/ , MATLAB, 56 linesrecord_model9/ untilitycurve.m - fMRI_Proc/
01_organizedata_23BPhapp , Jupyter, 87 linesy.ipynb - fMRI_Proc/
02_anatprep_23BPhappy.ip , Jupyter, 145 linesynb - fMRI_Proc/
03_funcpp01_23BPhappy.ip , Jupyter, 175 linesynb - fMRI_Proc/
03_funcpp02_23BPhappy.ip , Jupyter, 537 lines, 1 matchynb - fMRI_Proc/
03_funcpp03_23BPhappy.ip , Jupyter, 85 linesynb - fMRI_Proc/
04_funcGLM1Loop_23BPhapp , Jupyter, 112 lines, 1 matchy.ipynb - fMRI_Proc/
04_funcGLM1_23BPhappy.ip , Jupyter, 64 lines, 1 matchynb - fMRI_Proc/
05_funcGLM2_23BPhappy.ip , Jupyter, 163 linesynb - fMRI_Proc/
06_funcPPI_23BPhappy.ipy , Jupyter, 54 linesnb - fMRI_Proc/
07_funcROI_23BPhappy.ipy , Jupyter, 108 linesnb - fMRI_Proc/
movematfiles.ipynb , Jupyter, 73 lines - fMRI_Proc/
remake_mask.ipynb , Jupyter, 34 lines - LICENSE, License, 674 lines
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://
BibTeX
@article{xia2026neurocom
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/
url = {https://
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/
VL - 6
SP - kkag015
SN - 2634-4416
PB - Oxford University Press
DO - 10.1093/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1093/
"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":
"volume": "6",
"page": "kkag015",
"DOI": "10.1093/
"PMID": "42078071",
"PMCID": "PMC13133896",
"ISSN": "2634-4416",
"publisher": "Oxford University Press",
"URL": "https://
"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 communicationsIn 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: NatureIn 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 mappingIn 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 biologyIn 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 dataIn 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 communicationsIn 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: NeuronIn 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 : CBIn 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.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 65 scripts, and 3 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:206898a05aad96ae…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
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.
