<jupyter_start><jupyter_text>Getting ABIDE and running recon-all<jupyter_code>abide_amazon_addy = 'https://s3.amazonaws.com/fcp-indi/data/Projects/ABIDE_Initiative/Outputs/freesurfer/5.1'

subid = 'NYU_0050954'
abide_freesurfer = os.path.join(src_data_dir, 'abide', 'freesurfer')

fs_subdir = os.path.join(abide_freesurfer, subid)
if not os.path.exists(fs_subdir):    
    run(['mkdir', '-p', fs_subdir])

for subdir in ['mri', 'surf','label','scripts']:
    localdir = os.path.join(fs_subdir, subdir)
    if not os.path.exists(localdir):
        run(['mkdir', '-p', localdir])
    
for filename in ['T1.mgz', 'aparc+aseg.mgz', 'aparc.a2009s+aseg.mgz', 'wmparc.mgz', 'brain.finalsurfs.mgz']:
    download_file(os.path.join(abide_amazon_addy, subid, 'mri', filename.replace('+','%20')),
                               os.path.join(fs_subdir, 'mri', filename))

for surface in ['pial', 'white', 'sphere.reg', 'sphere', 'curv', 'sulc', 'thickness']:
    for hemi in ['lh', 'rh']:
        download_file(os.path.join(abide_amazon_addy, subid, 'surf', '{}.{}'.format(hemi,surface)),
                      os.path.join(fs_subdir, 'surf', '{}.{}'.format(hemi,surface)))

for labelname in ['aparc', 'aparc.a2009s', 'BA']:
    for hemi in ['lh', 'rh']:
        download_file(os.path.join(abide_amazon_addy, subid, 'label', '{}.{}.annot'.format(hemi,labelname)),
                      os.path.join(fs_subdir, 'label', '{}.{}.annot'.format(hemi,labelname))) 

for script in ['recon-all.done', 'build-stamp.txt']:
    download_file(os.path.join(abide_amazon_addy, subid, 'scripts', script), 
                  os.path.join(fs_subdir, 'scripts', script))
run(['ciftify_recon_all', '--hcp-data-dir', hcp_data_dir,
        '--fs-subjects-dir', abide_freesurfer, 
        'NYU_0050954'])

run(['cifti_vis_recon_all', 'snaps', '--hcp-data-dir',hcp_data_dir, 'NYU_0050954'])
run(['cifti_vis_recon_all', 'index', '--hcp-data-dir', hcp_data_dir])<jupyter_output><empty_output><jupyter_text>Download ABIDE PCP data for ciftify_vol_result tests<jupyter_code>def download_vmhc(subid):
    amazon_addy = 'https://s3.amazonaws.com/fcp-indi/data/Projects/ABIDE_Initiative/Outputs/cpac/filt_global/vmhc/{}_vmhc.nii.gz'.format(subid)
    sub_vmhc = os.path.join(src_vmhc, '{}_vmhc.nii.gz'.format(subid))
    download_file(amazon_addy, sub_vmhc)        

src_vmhc = os.path.join(src_data_dir, 'abide', 'vmhc')    
if not os.path.exists(src_vmhc): 
    run(['mkdir', src_vmhc])

subjects=['NYU_0050954','NYU_0050955']
for subid in subjects:
    download_vmhc(subid)
subject = 'NYU_0050954'
run(['cifti_vis_map', 'nifti-snaps',
        '--hcp-data-dir', hcp_data_dir,
        '--qcdir', os.path.join(hcp_data_dir, 'abide_vmhc_vis'),
        '--resample-nifti', '--colour-palette', 'fidl', 
        os.path.join(src_vmhc, '{}_vmhc.nii.gz'.format(subject)), subject, '{}_vmhc'.format(subject)])
subject = 'NYU_0050954'
run(['cifti_vis_map', 'nifti-snaps',
        '--hcp-data-dir', hcp_data_dir,
        '--qcdir', os.path.join(hcp_data_dir, 'abide_vmhc_vis'),
        '--resample-nifti',  
        os.path.join(src_vmhc, '{}_vmhc.nii.gz'.format(subject)), subject, '{}_vmhc_dcol'.format(subject)])
subject = 'NYU_0050954'
run(['cifti_vis_map', 'nifti-snaps', 
        '--qcdir', os.path.join(hcp_data_dir, 'abide_vmhc_vis'),
        '--resample-nifti', '--colour-palette', 'fidl', 
        os.path.join(src_vmhc, '{}_vmhc.nii.gz'.format(subject)), 'HCP_S1200_GroupAvg', '{}_vmhc'.format(subject)])
subject = 'NYU_0050955'
run(['cifti_vis_map', 'nifti-snaps',
        '--qcdir', os.path.join(hcp_data_dir, 'abide_vmhc_vis'),
        '--resample-nifti',
        os.path.join(src_vmhc, '{}_vmhc.nii.gz'.format(subject)), 'HCP_S1200_GroupAvg', '{}_vmhc'.format(subject)])
run(['cifti_vis_map', 'index',
        '--hcp-data-dir', '/tmp',
        '--qcdir', os.path.join(hcp_data_dir, 'abide_vmhc_vis')])<jupyter_output><empty_output><jupyter_text>Testing ciftify_vol_result with HCP data..if data in src<jupyter_code>HCP_subid = '100307'
HCP_src_dir = os.path.join(src_data_dir, 'HCP') 
label_vol = os.path.join(HCP_src_dir, HCP_subid, 'MNINonLinear', 'aparc+aseg.nii.gz')
scalar_vol = os.path.join(HCP_src_dir, HCP_subid, 'MNINonLinear', 'T2w_restore.nii.gz')

run_HCP_tests = True if os.path.exists(HCP_src_dir) else False

if run_HCP_tests:
    HCP_out_dir = os.path.join(new_outputs, 'HCP')
    run(['mkdir', '-p', HCP_out_dir])
    run(['ciftify_vol_result', '--debug','--HCP-Pipelines', '--resample-nifti',
         '--hcp-data-dir', HCP_src_dir,
        '--integer-labels', HCP_subid, label_vol, 
         os.path.join(HCP_out_dir, '{}.aparc+aseg.32k_fs_LR.dscalar.nii'.format(HCP_subid))])
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--HCP-MSMAll','--resample-nifti',
         '--hcp-data-dir', HCP_src_dir,
        '--integer-labels', HCP_subid, label_vol, 
         os.path.join(HCP_out_dir, '{}.aparc+aseg_MSMAll.32k_fs_LR.dscalar.nii'.format(HCP_subid))])
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--resample-nifti',
         '--hcp-data-dir', HCP_src_dir, HCP_subid, 
         os.path.join(HCP_src_dir, HCP_subid, 'MNINonLinear', 'T2w_restore.nii.gz'),
         os.path.join(HCP_out_dir, '{}.T2w_restore.32k_fs_LR.dscalar.nii'.format(HCP_subid))])
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--HCP-MSMAll',
         '--hcp-data-dir', HCP_src_dir, HCP_subid, 
         os.path.join(HCP_src_dir, HCP_subid, 'MNINonLinear', 'T2w_restore.2.nii.gz'),
         os.path.join(HCP_out_dir, '{}.T2w_restore_MSMAll.32k_fs_LR.dscalar.nii'.format(HCP_subid))])<jupyter_output><empty_output><jupyter_text>Download the main dataset<jupyter_code>subids = ['sub-50005','sub-50007']

if not os.path.exists(src_data_dir):
    run(['mkdir','-p',src_data_dir])

for subid in subids:
    sub_fs_path = os.path.join('ds000030_R1.0.4','derivatives','freesurfer', subid)
if not os.path.exists(os.path.join(src_data_dir, sub_fs_path)):
    if not os.path.exists(os.path.join(src_data_dir, 
                                       os.path.basename(freesurfer_webtgz))):        
        run(['wget', '-P', src_data_dir, freesurfer_webtgz])

        run(['unzip', 
             os.path.join(src_data_dir, 
                          os.path.basename(freesurfer_webtgz)), 
             os.path.join(sub_fs_path,'*'),
             '-d', src_data_dir])

for subid in subids:
    sub_file = os.path.join('ds000030_R1.0.4','derivatives',
                            'fmriprep', subid,'func',
                            '{}_task-rest_bold_space-T1w_preproc.nii.gz'.format(subid))
        if not os.path.exists(os.path.join(src_data_dir,sub_file)):
            if not os.path.exists(os.path.join(src_data_dir, 
                                               os.path.basename(func_webtgz))):
                run(['wget', '-P', src_data_dir, func_webtgz])

                run(['unzip', 
                     os.path.join(src_data_dir, 
                                  os.path.basename(func_webtgz)), 
                     sub_file,
                     '-d', src_data_dir])

for subid in subids:
    sub_file = os.path.join('ds000030_R1.0.4','derivatives',
                            'fmriprep', subid,'func',
                            '{}_task-rest_bold_space-MNI152NLin2009cAsym_preproc.nii.gz'.format(subid))
    if not os.path.exists(os.path.join(src_data_dir,sub_file)):
        if not os.path.exists(os.path.join(src_data_dir, 
                                           os.path.basename(func_webtgz))):
            run(['wget', '-P', src_data_dir, func_webtgz])

            run(['unzip', 
                 os.path.join(src_data_dir, 
                              os.path.basename(func_webtgz)), 
                 sub_file,
                 '-d', src_data_dir])
run(['ciftify_recon_all', '--resample-to-T1w32k', '--hcp-data-dir', hcp_data_dir,
    '--fs-subjects-dir', fs_subjects_dir, 
    subids[0]])
run(['ciftify_recon_all', '--hcp-data-dir', hcp_data_dir,
    '--fs-subjects-dir', fs_subjects_dir, 
    subids[1]])
for subid in subids:
    run(['cifti_vis_recon_all', 'snaps', '--hcp-data-dir',hcp_data_dir, subid])
run(['cifti_vis_recon_all', 'index', '--hcp-data-dir', hcp_data_dir])
# for subid in ['sub-50004','sub-50006', 'sub-50008']:
#     run(['ciftify_recon_all', '--hcp-data-dir', hcp_data_dir,
#         '--fs-subjects-dir', fs_subjects_dir, 
#         subid])
# for subid in ['sub-50004','sub-50006', 'sub-50008']:
#     run(['cifti_vis_recon_all', 'snaps', '--hcp-data-dir',hcp_data_dir, subid])
# run(['cifti_vis_recon_all', 'index', '--hcp-data-dir', hcp_data_dir])<jupyter_output><empty_output><jupyter_text>Running ciftify_subject_fmri<jupyter_code>subid=subids[0]
native_func = os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subid,'func',
                 '{}_task-rest_bold_space-native_preproc.nii.gz'.format(subid))
mat_file = os.path.join(src_data_dir, 'ds000030_R1.0.4','derivatives',
                            'fmriprep', subid,'func',
                            '{}_task-rest_bold_T1_to_EPI.mat'.format(subid))

with open(mat_file, "w") as text_file:
    text_file.write('''1.03  -0.015  0.0025  -15.0
0.014  1.01  -0.005  -11.9
-0.007 0.01  0.99  2
0  0  0  1
''')

t1_func = os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subid,'func',
                 '{}_task-rest_bold_space-T1w_preproc.nii.gz'.format(subid))
if not os.path.exists(native_func):
    run(['flirt', '-in', t1_func, '-ref', t1_func, 
         '-out', native_func, '-init', mat_file, '-applyxfm'])

run(['ciftify_subject_fmri', '--SmoothingFWHM', '12', 
    '--hcp-data-dir', hcp_data_dir, 
    native_func, subid, 'rest_test1'])
subid=subids[0]
run(['cifti_vis_fmri', 'snaps', '--SmoothingFWHM', '12', '--hcp-data-dir',hcp_data_dir, 'rest_test1', subid])
subid=subids[0]
native_func_mean = os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subid,'func',
                 '{}_task-rest_bold_space-native_mean.nii.gz'.format(subid))

run(['fslmaths', native_func, '-Tmean', native_func_mean])

run(['ciftify_subject_fmri', '--hcp-data-dir', hcp_data_dir, 
    '--FLIRT-template', native_func_mean, native_func, subid, 'rest_test2'])

subid=subids[0]
run(['cifti_vis_fmri', 'snaps', '--smooth-conn', '12', '--hcp-data-dir',hcp_data_dir, 'rest_test2', subid])
subid = subids[1]
run(['ciftify_subject_fmri', '--SmoothingFWHM', '8', '--FLIRT-dof', '30',
    '--hcp-data-dir', hcp_data_dir, 
     '--OutputSurfDiagnostics',
    os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subid,'func',
                 '{}_task-rest_bold_space-T1w_preproc.nii.gz'.format(subid)),
    subid, 'rest_test_dof30'])
subid = subids[1]
run(['cifti_vis_fmri', 'subject', '--hcp-data-dir',hcp_data_dir, 'rest_test_dof30', subid])
subid = subids[1]
run(['ciftify_subject_fmri', '--already-in-MNI', '--SmoothingFWHM', '8', 
    '--hcp-data-dir', hcp_data_dir, 
    os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subid,'func',
                 '{}_task-rest_bold_space-MNI152NLin2009cAsym_preproc.nii.gz'.format(subid)),
    subid, 'rest_bad_transform'])
subid = subids[1]
run(['cifti_vis_fmri', 'snaps', '--hcp-data-dir',hcp_data_dir, 'rest_bad_transform', subid])
run(['cifti_vis_fmri', 'index', '--hcp-data-dir', hcp_data_dir])

dtseries_files = glob(os.path.join(hcp_data_dir,'*',
                                       'MNINonLinear', 'Results',
                                       '*', '*Atlas_s*.dtseries.nii'))
run(['cifti_vis_RSN', 'cifti-snaps',  
         '--hcp-data-dir',hcp_data_dir, 
         '--colour-palette', 'PSYCH-NO-NONE',
         dtseries_files[0], 
         os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(dtseries_files[0])))))])
    
for dtseries in dtseries_files[1:]:
    run(['cifti_vis_RSN', 'cifti-snaps',  
         '--hcp-data-dir',hcp_data_dir, dtseries, 
         os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(dtseries)))))])
run(['cifti_vis_RSN', 'index', 
     '--hcp-data-dir', hcp_data_dir])
run(['cifti_vis_RSN', 'index', '--hcp-data-dir', hcp_data_dir])
roi_dir = os.path.join(new_outputs, 'rois')
if not os.path.exists(roi_dir):
    run(['mkdir', roi_dir])
for dtseries in dtseries_files:
    run_seed_corr_fmri_test(dtseries, hcp_data_dir, roi_dir)
run(['cifti_vis_RSN', 'nifti-snaps', 
         '--hcp-data-dir',hcp_data_dir, 
         '--qcdir', os.path.join(hcp_data_dir, 'RSN_from_nii'),
         '--colour-palette', 'PSYCH-NO-NONE',
     
        os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subids[0],'func',
                 '{}_task-rest_bold_space-MNI152NLin2009cAsym_preproc.nii.gz'.format(subids[0])),
        subids[0]])

run(['cifti_vis_RSN', 'nifti-snaps',  
         '--hcp-data-dir',hcp_data_dir, 
         '--qcdir', os.path.join(hcp_data_dir, 'RSN_from_nii'),
        os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subids[1],'func',
                 '{}_task-rest_bold_space-MNI152NLin2009cAsym_preproc.nii.gz'.format(subids[1])),
        subids[1]])
    
run(['cifti_vis_RSN', 'index', 
     '--qcdir', os.path.join(hcp_data_dir, 'RSN_from_nii'),
     '--hcp-data-dir', hcp_data_dir])
groupmask_cmd = ['ciftify_groupmask', os.path.join(hcp_data_dir, 'groupmask.dscalar.nii')]
groupmask_cmd.extend(dtseries_files)

run(groupmask_cmd)<jupyter_output><empty_output><jupyter_text>Running PINT and related functions<jupyter_code>subid = subids[0]
run(['mkdir', '-p', os.path.join(new_outputs, 'PINT', subid)])

run(['ciftify_PINT_vertices', '--pcorr', 
     os.path.join(hcp_data_dir, subid,'MNINonLinear', 'Results',
                  'rest_test1', 'rest_test1_Atlas_s12.dtseries.nii'),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(ciftify.config.find_ciftify_global(), 'PINT', 'Yeo7_2011_80verts.csv'),
     os.path.join(new_outputs, 'PINT', subid, subid)])

subid = subids[0]
run(['cifti_vis_PINT', 'snaps', '--hcp-data-dir',  hcp_data_dir,
     os.path.join(hcp_data_dir, subid,'MNINonLinear', 'Results',
                  'rest_test1', 'rest_test1_Atlas_s12.dtseries.nii'),
     subid,
     os.path.join(new_outputs, 'PINT', subid, '{}_summary.csv'.format(subid))])
subid = subids[1]
run(['mkdir', '-p', os.path.join(new_outputs, 'PINT', subid)])

run(['ciftify_PINT_vertices',
     os.path.join(hcp_data_dir, subid,'MNINonLinear', 'Results',
                  'rest_test_dof30', 'rest_test_dof30_Atlas_s8.dtseries.nii'),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(ciftify.config.find_ciftify_global(), 'PINT', 'Yeo7_2011_80verts.csv'),
     os.path.join(new_outputs, 'PINT', subid, subid)])
run(['cifti_vis_PINT', 'snaps', '--hcp-data-dir',  hcp_data_dir,
     os.path.join(hcp_data_dir, subid,'MNINonLinear', 'Results',
                  'rest_test_dof30', 'rest_test_dof30_Atlas_s8.dtseries.nii'),
     subid,
     os.path.join(new_outputs, 'PINT', subid, '{}_summary.csv'.format(subid))])
subid = subids[1]
run(['mkdir', '-p', os.path.join(new_outputs, 'PINT', subid)])

run(['ciftify_PINT_vertices', '--outputall',
     os.path.join(hcp_data_dir, subid,'MNINonLinear', 'Results',
                  'rest_test_dof30', 'rest_test_dof30_Atlas_s8.dtseries.nii'),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(ciftify.config.find_ciftify_global(), 'PINT', 'Yeo7_2011_80verts.csv'),
     os.path.join(new_outputs, 'PINT', subid, '{}_all'.format(subid))])
run(['cifti_vis_PINT', 'snaps', '--hcp-data-dir',  hcp_data_dir,
     os.path.join(hcp_data_dir, subid,'MNINonLinear', 'Results',
                  'rest_test_dof30', 'rest_test_dof30_Atlas_s8.dtseries.nii'),
     subid,
     os.path.join(new_outputs, 'PINT', subid, '{}_all_summary.csv'.format(subid))])
run(['cifti_vis_PINT', 'index', '--hcp-data-dir',  hcp_data_dir])
summary_files = glob(os.path.join(new_outputs, 'PINT', '*','*_summary.csv'))
concat_cmd = ['ciftify_postPINT1_concat', '--debug',
           os.path.join(new_outputs, 'PINT', 'concatenated.csv')]
concat_cmd.extend(summary_files)
run(concat_cmd)
run(['ciftify_postPINT2_sub2sub', os.path.join(new_outputs, 'PINT', 'concatenated.csv'),
     os.path.join(new_outputs, 'PINT', 'ivertex_distances.csv')])
run(['ciftify_postPINT2_sub2sub', '--roiidx', '14',
     os.path.join(new_outputs, 'PINT', 'concatenated.csv'),
     os.path.join(new_outputs, 'PINT', 'ivertex_distances_roiidx14.csv')])<jupyter_output><empty_output><jupyter_text>Running ciftify_surface_rois<jupyter_code>vertices1_csv = os.path.join(src_data_dir, 'vertices1.csv')

with open(vertices1_csv, "w") as text_file:
    text_file.write('''hemi,vertex
L,11801
L,26245
L,26235
L,26257
L,13356
L,289
L,13336
L,13337
L,26269
L,13323
L,26204
L,26214
L,13326
L,13085
L,13310
L,13281
L,13394
L,13395
L,26263
L,26265
L,13343
L,77
L,13273
L,13342
L,26271
L,11804
L,13322
L,13369
L,13353
L,26268
L,26201
L,26269
L,68
L,13391
''')

subid = subids[0]
run(['mkdir', '-p', os.path.join(new_outputs, 'rois')])
run(['ciftify_surface_rois', vertices1_csv, '10', '--gaussian',
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)), 
     os.path.join(new_outputs, 'rois', 'gaussian_roi.dscalar.nii')])
subid = subids[0]
run(['cifti_vis_map', 'cifti-snaps', '--hcp-data-dir', 
     hcp_data_dir, 
     os.path.join(new_outputs, 'rois', 'gaussian_roi.dscalar.nii'),
     subid, 
     'gaussian_roi'])
run(['ciftify_peaktable', '--max-threshold', '0.05',      
    '--left-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
    '--right-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)),
    os.path.join(new_outputs, 'rois', 'gaussian_roi.dscalar.nii')])
run(['ciftify_dlabel_report',   
    '--left-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
    '--right-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)), 
   os.path.join(new_outputs, 'rois', 'gaussian_roi_clust.dlabel.nii')])
vertices2_csv = os.path.join(src_data_dir, 'vertices1.csv')

with open(vertices2_csv, "w") as text_file:
    text_file.write('''hemi,vertex
R,2379
R,2423
R,2423
R,2629
R,29290
R,29290
R,1794
R,29199
R,1788
R,2380
R,2288
R,29320
R,29274
R,29272
R,29331
R,29356
R,2510
R,29345
R,2506
R,2506
R,1790
R,29305
R,2630
R,2551
R,2334
R,2334
R,29306
R,2551
R,2422
R,29256
R,2468
R,29332
R,2425
R,29356
''')
    
run(['mkdir', '-p', os.path.join(new_outputs, 'rois')])
run(['ciftify_surface_rois', vertices2_csv, '6', '--probmap',
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
     os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)), 
     os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii')])
subid = subids[0]
run(['cifti_vis_map', 'cifti-snaps', '--hcp-data-dir', 
     hcp_data_dir, 
     os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii'),
     subid, 
     'probmap_roi'])
run(['ciftify_peaktable', '--max-threshold', '0.05',      
    '--left-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
    '--right-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)), 
   os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii')])
run(['ciftify_dlabel_report',   
    '--left-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
    '--right-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)), 
   os.path.join(new_outputs, 'rois', 'probmap_roi_clust.dlabel.nii')])
for hemi in ['L','R']:
    run(['wb_command', '-surface-vertex-areas',
         os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.{}.midthickness.32k_fs_LR.surf.gii'.format(subid, hemi)),
         os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.{}.midthickness_va.32k_fs_LR.shape.gii'.format(subid, hemi))])

run(['ciftify_peaktable', 
    '--outputbase', os.path.join(new_outputs, 'rois', 'probmap_roi_withva'),
    '--max-threshold', '0.05',      
    '--left-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness.32k_fs_LR.surf.gii'.format(subid)),
    '--right-surface', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness.32k_fs_LR.surf.gii'.format(subid)), 
    '--left-surf-area', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.L.midthickness_va.32k_fs_LR.shape.gii'.format(subid)),
    '--right-surf-area', os.path.join(hcp_data_dir, subid,'MNINonLinear','fsaverage_LR32k',
                  '{}.R.midthickness_va.32k_fs_LR.shape.gii'.format(subid)), 
   os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii')])
run(['ciftify_surface_rois',
      os.path.join(ciftify.config.find_ciftify_global(), 'PINT', 'Yeo7_2011_80verts.csv'),
      '6', '--vertex-col', 'tvertex', '--labels-col', 'NETWORK', '--overlap-logic', 'EXCLUDE',
      os.path.join(ciftify.config.find_HCP_S1200_GroupAvg(),
                'S1200.L.midthickness_MSMAll.32k_fs_LR.surf.gii'),
      os.path.join(ciftify.config.find_HCP_S1200_GroupAvg(),
                'S1200.R.midthickness_MSMAll.32k_fs_LR.surf.gii'),
      os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])
subid = subids[0]
run(['cifti_vis_map', 'cifti-snaps', '--hcp-data-dir', 
     hcp_data_dir, 
     os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii'),
     subid, 
     'tvertex'])<jupyter_output><empty_output><jupyter_text>Running ciftify_seed_corr<jupyter_code>class MeantsTest(object):
    def __init__(self, func, seed, sc_type, hcp_data_dir, subid, fisher_z, fixture_prefix, 
                 extra_args = None, outputdir = None, mask = None, skip_meants = False, debug = False):
        self.func = ciftify.meants.NibInput(func)
        self.seed = ciftify.meants.NibInput(seed)
        self.mask = mask
        self.outputdir = outputdir
        self.fixture_prefix = fixture_prefix
        self.prefix = self.get_output_prefix(sc_type)
        self.result_map, self.result_csv = self.get_result_paths()
        self.seed_corr_pass = self.test_ciftify_seed_corr(extra_args, fisher_z, debug)
        if not self.seed_corr_pass: return
        self.meants_pass = self.test_ciftify_meants(extra_args, skip_meants, debug)
        if not self.meants_pass: return
        self.vis_map_ran = self.run_vis_map(hcp_data_dir, subid)
        self.peaktable_pass = self.run_seedcorr_peaktable()
    
    def get_output_prefix(self, sc_type):
        ''' puts the other info together into an output prefix'''
        masked = "umasked" if self.mask == None else "masked" 
        prefix = "{}_{}_{}_{}".format(self.func.base,
                                     self.seed.base,
                                     sc_type,
                                     masked)
        return(prefix)
    
    def get_result_paths(self):
        ''' set outputdir to location of func if not speficified'''
        if self.outputdir:
            expected_path = self.outputdir
            outbase = self.prefix
        else:
            expected_path = os.path.dirname(self.func.path)
            outbase = '{}_{}'.format(self.func.base, self.seed.base)
        output_path = os.path.join(expected_path, outbase)
        if self.func.type == "cifti":
           result_map = "{}.dscalar.nii".format(output_path)
        elif self.func.type == "nifti":
           result_map = "{}.nii.gz".format(output_path)
        else:
          logger.error("func should be nifti or cifti")
        result_csv = "{}.csv".format(output_path)
        return(result_map, result_csv)
    
    def test_ciftify_seed_corr(self, extra_args, fisher_z, debug):
        '''run ciftify_seed_corr'''
        sc_cmd = ['ciftify_seed_corr', self.func.path, self.seed.path]
        if debug:
            sc_cmd.insert(1, '--debug')
        if extra_args:
            sc_cmd.insert(1, extra_args)
        if fisher_z:
            sc_cmd.insert(1, '--fisher-z')
        if self.outputdir:
            sc_cmd.insert(1, '--outputname')
            sc_cmd.insert(2, self.result_map)
        if self.mask:
            sc_cmd.insert(1, '--mask')
            sc_cmd.insert(2, self.mask)
        run(sc_cmd)
        return(os.path.exists(self.result_map))
    
    def test_ciftify_meants(self, extra_args, skip_meants, debug):
        ''' runs ciftify_meants'''
        if skip_meants: 
            return(None)
        meants_cmd = ['ciftify_meants', self.func.path, self.seed.path]
        if debug:
            meants_cmd.insert(1, '--debug')
        if extra_args:
            meants_cmd.insert(1, extra_args)
        if self.outputdir:
            meants_cmd.insert(1, '--outputcsv')
            meants_cmd.insert(2, self.result_csv)
        if self.mask:
            meants_cmd.insert(1, '--mask')
            meants_cmd.insert(2, self.mask)
        run(meants_cmd)
        return(os.path.exists(self.result_csv))
        
    def run_vis_map(self, hcp_data_dir, subid):
        ''' runs vis map to make visual of this process'''
        run(['cifti_vis_map', '{}-subject'.format(self.func.type), 
             '--hcp-data-dir', hcp_data_dir, 
             self.result_map, 
             subid, 
             self.prefix])
        return(True)

    def run_seedcorr_peaktable(self):
        ''' runs peaktable with correlation style threshold'''
        if self.func.type != "cifti": return(None)
        run(['ciftify_peaktable',  
             '--min-threshold', '-0.5', 
             '--max-threshold', '0.5', 
             '--no-cluster-dlabel', 
             self.result_map])
        return(True)
    
    
subid = subids[0]
smoothing = 12
func_vol = os.path.join(hcp_data_dir, subid, 'MNINonLinear', 'Results', 'rest_test1', 'rest_test1.nii.gz')
func_cifti_sm0 = os.path.join(hcp_data_dir, subid, 'MNINonLinear', 'Results', 'rest_test1', 'rest_test1_Atlas_s0.dtseries.nii')
func_cifti_smoothed = os.path.join(hcp_data_dir, subid, 'MNINonLinear', 'Results', 'rest_test1', 'rest_test1_Atlas_s{}.dtseries.nii'.format(smoothing))
atlas_vol =  os.path.join(hcp_data_dir, subid, 'MNINonLinear', 'wmparc.nii.gz')
seed_corr_dir = os.path.join(new_outputs, 'ciftify_seed_corr')
if not os.path.exists(seed_corr_dir):
    run(['mkdir', '-p', seed_corr_dir])
cifti_mask = os.path.join(seed_corr_dir, '{}_func_mask.dscalar.nii'.format(subid))
run(['wb_command', '-cifti-math', "'(x > 0)'", cifti_mask,
    '-var', 'x', func_cifti_sm0, '-select', '1', '1'])
### All results
# ciftify_peaktable - with va input
# cifti_vis_map
run(['extract_nuisance_regressors', 
     os.path.join(hcp_data_dir, subid, 'MNINonLinear'), 
     func_vol])

hipp_struct = 'LEFT-HIPPOCAMPUS'
hipp_vol_seed_mask = os.path.join(seed_corr_dir, '{}_{}_vol.nii.gz'.format(subid, hipp_struct))
run(['wb_command', '-volume-label-to-roi', atlas_vol, hipp_vol_seed_mask, '-name', hipp_struct])
testa_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_sub-50005_LEFT-HIPPOCAMPUS_vol'
testa_a = MeantsTest(func = func_vol, 
                   seed = hipp_vol_seed_mask, 
                   sc_type = "niftitoniftiZ", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = True, 
                   fixture_prefix = testa_fixture,
                   extra_args = None, 
                   outputdir = None, mask = None, debug = True)


testa_b = MeantsTest(func = func_vol, 
                   seed = hipp_vol_seed_mask, 
                   sc_type = "niftitoniftiZ", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = True, 
                   fixture_prefix = testa_fixture,
                   extra_args = None, 
                   outputdir = seed_corr_dir, mask = hipp_vol_seed_mask)
testa_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_sub-50005_LEFT-HIPPOCAMPUS_vol'
testa_c = MeantsTest(func = func_cifti_smoothed, 
                   seed = hipp_vol_seed_mask, 
                   sc_type = "niftitociftiZ", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = True, 
                   fixture_prefix = testa_fixture,
                   extra_args = None, 
                   outputdir = None, mask = None)

testa_d = MeantsTest(func = func_cifti_smoothed, 
                   seed = hipp_vol_seed_mask, 
                   sc_type = "niftitociftiZ", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = True, 
                   fixture_prefix = testa_fixture,
                   extra_args = None, 
                   outputdir = seed_corr_dir, mask = hipp_vol_seed_mask)
struct = 'RIGHT-PUTAMEN'
putamen_vol_seed_mask = os.path.join(seed_corr_dir, '{}_{}_vol.nii.gz'.format(subid, struct))
run(['wb_command', '-volume-label-to-roi', atlas_vol, putamen_vol_seed_mask, '-name', struct])
testb_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_sub-50005_RIGHT-PUTAMEN_vol'
testa_c = MeantsTest(func = func_vol, 
                   seed = putamen_vol_seed_mask, 
                   sc_type = "niftitonifti", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testb_fixture,
                   extra_args = None, 
                   outputdir = None, mask = None)

testa_d = MeantsTest(func = func_vol, 
                   seed = putamen_vol_seed_mask, 
                   sc_type = "niftitonifti", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testb_fixture,
                   extra_args = None, 
                   outputdir = seed_corr_dir, 
                   mask = os.path.join(hcp_data_dir, subid, 'MNINonLinear', 'brainmask_fs.nii.gz'))
testb_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_sub-50005_RIGHT-PUTAMEN_vol'
testa_c = MeantsTest(func = func_cifti_smoothed, 
                   seed = putamen_vol_seed_mask, 
                   sc_type = "niftitocifti", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testb_fixture,
                   extra_args = None, 
                   outputdir = None, mask = None)

testa_d = MeantsTest(func = func_cifti_smoothed, 
                   seed = putamen_vol_seed_mask, 
                   sc_type = "niftitocifti", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testb_fixture,
                   extra_args = None, 
                   outputdir = seed_corr_dir, 
                   mask = cifti_mask)
testb_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_sub-50005_RIGHT-PUTAMEN_vol'

putamen_cifti_seed_mask = os.path.join(seed_corr_dir, '{}_{}_cifti.dscalar.nii'.format(subid, struct))
run(['wb_command', '-cifti-create-dense-from-template',
     func_cifti_sm0, putamen_cifti_seed_mask,
     '-volume-all', putamen_vol_seed_mask])

testa_c = MeantsTest(func = func_cifti_smoothed, 
                   seed = putamen_cifti_seed_mask, 
                   sc_type = "ciftitocifti", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testb_fixture,
                   extra_args = None, 
                   outputdir = None, mask = None)

testa_d = MeantsTest(func = func_cifti_smoothed, 
                   seed = putamen_cifti_seed_mask, 
                   sc_type = "ciftitocifti", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testb_fixture,
                   extra_args = None, 
                   outputdir = seed_corr_dir, 
                   mask = cifti_mask)
testc_fixture = './ciftify_seed_corr/sub-50005_RIGHT-PUTAMEN_ciftitocifti_30TRs'

TR_file = os.path.join(new_outputs, 'rois','TR_file.txt')
with open(TR_file, "w") as text_file:
    text_file.write('''1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30''')

testc_a = MeantsTest(func = func_cifti_smoothed, 
                   seed = putamen_vol_seed_mask, 
                   sc_type = "ciftitocifti_30TRs", 
                   hcp_data_dir = hcp_data_dir, subid = subid, 
                   fisher_z = False, 
                   fixture_prefix = testc_fixture,
                   extra_args = '--use-TRs {}'.format(TR_file), 
                   outputdir = seed_corr_dir, mask = None,
                   skip_meants = True)
testd_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_gaussian_roi'

L_gaussian_roi = os.path.join(new_outputs, 'rois', 'gaussian_L_roi.shape.gii')

run(['wb_command', '-cifti-separate', 
     os.path.join(new_outputs, 'rois', 'gaussian_roi.dscalar.nii'),
     'COLUMN','-metric', 'CORTEX_LEFT', L_gaussian_roi])

testd_a = MeantsTest(func = func_cifti_smoothed, 
                   seed = os.path.join(new_outputs, 'rois', 'gaussian_roi.dscalar.nii'),  
                   sc_type = 'ciftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testd_fixture,
                   extra_args = '--weighted', 
                   outputdir = None, mask = None)

testd_b = MeantsTest(func_cifti_smoothed, 
                   os.path.join(new_outputs, 'rois', 'gaussian_roi.dscalar.nii'), 
                   sc_type = 'ciftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testd_fixture,
                   extra_args = '--weighted',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)

testd_c = MeantsTest(func = func_cifti_smoothed, 
                   seed = L_gaussian_roi,  
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testd_fixture,
                   extra_args = '--weighted --hemi L', 
                   outputdir = None, mask = None)

testd_d = MeantsTest(func_cifti_smoothed, 
                   seed = L_gaussian_roi, 
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testd_fixture,
                   extra_args = '--weighted --hemi L',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)
teste_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_probmap_roi'

R_probmap_roi = os.path.join(new_outputs, 'rois', 'probmap_R_roi.shape.gii')
                                   
run(['wb_command', '-cifti-separate', 
     os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii'),
     'COLUMN','-metric', 'CORTEX_RIGHT', R_probmap_roi])

teste_a = MeantsTest(func = func_cifti_smoothed, 
                   seed = os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii'),  
                   sc_type = 'ciftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = teste_fixture,
                   extra_args = '--weighted', 
                   outputdir = None, mask = None)

teste_b = MeantsTest(func_cifti_smoothed, 
                   seed = os.path.join(new_outputs, 'rois', 'probmap_roi.dscalar.nii'), 
                   sc_type = 'ciftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = teste_fixture,
                   extra_args = '--weighted',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)

teste_c = MeantsTest(func = func_cifti_smoothed, 
                   seed = R_probmap_roi,  
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = teste_fixture,
                   extra_args = '--weighted --hemi R', 
                   outputdir = None, mask = None)

teste_d = MeantsTest(func_cifti_smoothed, 
                   seed = R_probmap_roi, 
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = teste_fixture,
                   extra_args = '--weighted --hemi R',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)
testf_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_tvertex'

teste_a = MeantsTest(func = func_cifti_smoothed, 
                   seed = os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii'),  
                   sc_type = 'ciftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testf_fixture,
                   extra_args = '--roi-label 7', 
                   outputdir = None, mask = None)

teste_b = MeantsTest(func_cifti_smoothed, 
                   seed = os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii'), 
                   sc_type = 'ciftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testf_fixture,
                   extra_args = '--roi-label 7',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)
testg_fixture = './hcp/sub-50005/MNINonLinear/Results/rest_test1/rest_test1_Atlas_s12_tvertex_R_roi'

R_tvertex_roi = os.path.join(new_outputs, 'rois', 'tvertex_R_roi.shape.gii')

run(['wb_command', '-cifti-separate', 
     os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii'),
     'COLUMN','-metric', 'CORTEX_RIGHT', R_tvertex_roi])

testg_c = MeantsTest(func = func_cifti_smoothed, 
                   seed = R_tvertex_roi,  
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testg_fixture,
                   extra_args = '--roi-label 7 --hemi R', 
                   outputdir = None, mask = None)

testg_d = MeantsTest(func_cifti_smoothed, 
                   seed = R_tvertex_roi, 
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testg_fixture,
                   extra_args = '--roi-label 7 --hemi R',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)

run(['cifti_vis_map', 'index', '--hcp-data-dir', hcp_data_dir])<jupyter_output><empty_output><jupyter_text>ciftify_meants (atlas examples)<jupyter_code>subject_aparc = os.path.join(hcp_data_dir, subid,
                            'MNINonLinear', 'fsaverage_LR32k',
                            '{}.aparc.32k_fs_LR.dlabel.nii'.format(subid))
subject_thickness = os.path.join(hcp_data_dir, subid,
                            'MNINonLinear', 'fsaverage_LR32k',
                            '{}.thickness.32k_fs_LR.dscalar.nii'.format(subid))
run(['ciftify_meants', func_cifti_sm0, subject_aparc])

run(['ciftify_meants',  
     '--outputcsv', os.path.join(seed_corr_dir, 
                                 '{}_aparc_thickness_ciftitocifti_unmasked_meants.csv'.format(subid)),
     '--outputlabels', os.path.join(seed_corr_dir, 
                                    '{}_aparc_ciftitocifti_unmasked_labels.csv'.format(subid)),
         subject_thickness, subject_aparc])
run(['ciftify_meants', func_cifti_sm0, 
     os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])
run(['ciftify_meants', 
     '--mask', cifti_mask,
     '--outputcsv', os.path.join(seed_corr_dir, 
                                 '{}_tvertex_func_ciftitocifti_unmasked_meants.csv'.format(subid)),
     func_cifti_sm0, 
     os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])
## project wmparc to subject
wmparc_dscalar_d0 = os.path.join(seed_corr_dir, '{}_wmparc_MNI_d0.dscalar.nii'.format(subid))
run(['ciftify_vol_result', '--hcp-data-dir', hcp_data_dir,
    '--integer-labels', subid, atlas_vol, wmparc_dscalar_d0])
## project wmparc to subject
wmparc_dscalar = os.path.join(seed_corr_dir, '{}_wmparc_MNI_d10.dscalar.nii'.format(subid))
run(['ciftify_vol_result', 
     '--hcp-data-dir', hcp_data_dir,
     '--dilate', '10',
    '--integer-labels', subid, atlas_vol, wmparc_dscalar])
run(['ciftify_meants', 
     '--mask', os.path.join(hcp_data_dir, subid, 'MNINonLinear', 'brainmask_fs.nii.gz'),
     '--outputcsv', os.path.join(seed_corr_dir, 
                                 '{}_wmparc_func_niftitonifti_masked_meants.csv'.format(subid)),
     '--outputlabels', os.path.join(seed_corr_dir, 
                                 '{}_wmparc_func_niftitonifti_masked_labels.csv'.format(subid)),
     func_vol, atlas_vol])
run(['ciftify_meants', 
     '--mask', cifti_mask,
     '--outputcsv', os.path.join(seed_corr_dir, 
                                 '{}_wmparc_func_ciftitocifti_masked_meants.csv'.format(subid)),
     '--outputlabels', os.path.join(seed_corr_dir, 
                                 '{}_wmparc_func_ciftitocifti_masked_labels.csv'.format(subid)),
     func_cifti_sm0, wmparc_dscalar])
wmparc_dlabel = os.path.join(seed_corr_dir, '{}_wmparc_MNI.dlabel.nii'.format(subid))
run(['wb_command', '-cifti-label-import', '-logging', 'SEVERE',
     wmparc_dscalar, 
     os.path.join(ciftify.config.find_ciftify_global(), 'hcp_config', 'FreeSurferAllLut.txt'),
    wmparc_dlabel])
run(['ciftify_meants', 
     '--outputcsv', os.path.join(seed_corr_dir, 
                                 '{}_wmparc_func_ciftiltocifti_dlabel_meants.csv'.format(subid)),
     '--outputlabels', os.path.join(seed_corr_dir, 
                                 '{}_wmparc_func_ciftiltocifti_dlabel_labels.csv'.format(subid)),
     func_cifti_sm0, wmparc_dlabel])
import pandas as pd

csv_df = pd.read_csv(os.path.join(fixtures_dir, 'expected_csvs.csv'))

csv_df['num_rows'] = ''
csv_df['num_cols'] = ''
csv_df['exists'] = ''
csv_df['matches'] = ''
for row in csv_df.index:
    expected_csv = os.path.join(new_outputs, csv_df.loc[row, 'expected_output'])
    if os.path.isfile(expected_csv):
        compare_csv = os.path.join(fixtures_dir, csv_df.loc[row, 'compare_to'])
        header_col = 0
        if expected_csv.endswith('_meants.csv'): header_col = None
        if expected_csv.endswith('_labels.csv'): header_col = None
        if expected_csv.endswith('_CSF.csv'): header_col = None
        if expected_csv.endswith('_WM.csv'): header_col = None
        if expected_csv.endswith('_GM.csv'): header_col = None
        testdf = pd.read_csv(expected_csv, header = header_col)
        csv_df.loc[row, 'exists'] = True
        csv_df.loc[row, 'num_rows'] = testdf.shape[0]
        csv_df.loc[row, 'num_cols'] = testdf.shape[1]
        comparedf = pd.read_csv(compare_csv, header = header_col)
        try:
            csv_df.loc[row, 'matches'] = (comparedf == testdf).all().all()
        except:
            csv_df.loc[row, 'matches'] = False
    else:
        csv_df.loc[row, 'exists'] = False
csv_df.to_csv(os.path.join(new_outputs, 'csv_compare_results.csv'))
if csv_df.exists.all(): 
    logger.info('All expected csv were generated')
else:
    logger.error('Some expected csv outputs were not generated')
if csv_df.matches.all():
    logger.info('All expected csv outputs match expected')
else:
    logger.info('Some csv outputs do not match..see csv_compare_results.csv of more details')
logger.info(ciftify.utils.section_header('Done'))
csv_df.loc[csv_df.matches == False]
csv_df<jupyter_output><empty_output><jupyter_text>making things fail gracefully<jupyter_code>testg_d = MeantsTest(func_cifti_smoothed, 
                   seed = R_tvertex_roi, 
                   sc_type = 'giftitocifti', 
                   hcp_data_dir = hcp_data_dir, subid = subid, fisher_z = False,
                   fixture_prefix = testg_fixture,
                   extra_args = '--hemi R',
                   outputdir = seed_corr_dir,  
                   mask = cifti_mask)
run(['ciftify_meants', '/fake/path/', hipp_vol_seed_mask])

run(['ciftify_meants', func_vol, '/fake/seed/'])

run(['ciftify_seed_corr', func_vol, os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])

run(['ciftify_meants', func_vol, os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])

run(['ciftify_meants',  '--roi-label 20', func_cifti_smoothed, os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])

run(['ciftify_seed_corr',  '--roi-label 0', func_cifti_smoothed, os.path.join(new_outputs, 'rois', 'tvertex.dscalar.nii')])

run(['ciftify_seed_corr', func_vol, vertices2_csv])

run(['ciftify_meants', func_vol, vertices2_csv])

run(['ciftify_meants', 
     os.path.join(src_data_dir,'ds000030_R1.0.4','derivatives',
                 'fmriprep', subid,'func',
                 '{}_task-rest_bold_space-MNI152NLin2009cAsym_preproc.nii.gz'.format(subid)), 
     hipp_vol_seed_mask])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14973817549661855, 'fraction_numerical': 0.024020013144226082, 'mean_word_length': 2.7790418202211185, 'pattern_counts': {'":': 3, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 31, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '540786', 'license': 'MIT', 'n_tokens_mistral': 19159, 'n_tokens_neox': 17920, 'n_words': 2320, 'path': 'tests/integration/ciftify_integration_tests.ipynb', 'repo_name': 'Mathu-M/ciftify', 'size': '47169'}