Test HCP data relevant scripts with ciftify


In [1]:
import ciftify
from ciftify.utils import run
import os
import datetime
import logging
from glob import glob

In [2]:
#working_dir = '/home/edickie/Documents/ciftify_tests/'
working_dir = '/scratch/edickie/ciftify_intergration_tests/'
src_data_dir= os.path.join(working_dir,'src_data')
#work_from = '/home/edickie/Documents/ciftify_tests/run_2017-09/'
work_from = '/scratch/edickie/ciftify_intergration_tests/run_2018-04-16/'
#work_from = None

fixtures_dir = '/projects/edickie/code/ciftify/tests/integration/fixtures/'

if work_from:
    new_outputs = work_from
else:
    new_outputs= os.path.join(working_dir,'run_{}'.format(datetime.date.today()))
DEBUG = True
DRYRUN = True

## getting the data

freesurfer_webtgz = 'https://s3.amazonaws.com/openneuro/ds000030/ds000030_R1.0.4/compressed/ds000030_R1.0.4_derivatives_freesurfer_sub50004-50008.zip'
func_webtgz = 'https://s3.amazonaws.com/openneuro/ds000030/ds000030_R1.0.4/compressed/ds000030_R1.0.4_derivatives_sub50004-50008.zip'

subids = ['sub-50005','sub-50007']
#subids = ['sub-50005','sub-50006']

logger = logging.getLogger('ciftify')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

# Get settings, and add an extra handler for the subject log
fh = logging.FileHandler(os.path.join(working_dir, 'ciftify_tests.log'))
logger.addHandler(fh)

fs_subjects_dir = os.path.join(src_data_dir, 'ds000030_R1.0.4',
                               'derivatives','freesurfer')
hcp_data_dir = os.path.join(new_outputs, 'hcp')

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

In [3]:
def download_file(web_address, local_filename):
    '''download file if it does not exist'''
    if not os.path.isfile(local_filename):
        run(['wget', web_address, '-O', local_filename])
    if not os.path.getsize(local_filename) > 0:
        os.remove(local_filename)

In [4]:
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))])


Running: mkdir -p /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP
Running: ciftify_vol_result --debug --HCP-Pipelines --resample-nifti --hcp-data-dir /scratch/edickie/ciftify_intergration_tests/src_data/HCP --integer-labels 100307 /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.aparc+aseg.32k_fs_LR.dscalar.nii
[ciftify_vol_result] INFO: 

            .|';   ||          .|';
       ''   ||     ||     ''   ||
.|'',  ||  '||'  ''||''   ||  '||'  '||  ||`
||     ||   ||     ||     ||   ||    `|..||
`|..' .||. .||.    `|..' .||. .||.       ||
                                      ,  |'
                                       ''   
-------------------------------------------------------------
2018-04-23 16:59:06.385333 : Starting ciftify_vol_result
-------------------------------------------------------------

[ciftify.utils] INFO: Arguments:
    !!python/object/new:docopt.Dict
    dictitems:
      --HCP-MSMAll: false
      --HCP-Pipelines: true
      --ciftify-work-dir: null
      --debug: true
      --dilate: null
      --dry-run: false
      --hcp-data-dir: /scratch/edickie/ciftify_intergration_tests/src_data/HCP
      --help: false
      --integer-labels: true
      --resample-nifti: true
      --subcortical-vol: null
      --surface-vol: null
      <output.dscalar.nii>: /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.aparc+aseg.32k_fs_LR.dscalar.nii
      <subject>: '100307'
      <vol.nii.gz>: /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz
    
[ciftify.utils] WARNING: Argument --hcp-data-dir has been deprecated. Please instead use --ciftify-work-dir in the future.
[ciftify_vol_result] INFO: Creating tempdir:/tmp/tmp8oufi1_q on host:kandel.camhres.ca
[ciftify.utils] INFO: Running: wb_command -volume-to-surface-mapping /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/fsaverage_LR32k/100307.L.midthickness.32k_fs_LR.surf.gii /tmp/tmp8oufi1_q/L.func.gii -enclosing
[ciftify.utils] INFO: Running: wb_command -volume-to-surface-mapping /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/fsaverage_LR32k/100307.R.midthickness.32k_fs_LR.surf.gii /tmp/tmp8oufi1_q/R.func.gii -enclosing
[ciftify.utils] INFO: Running: wb_command -volume-affine-resample /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz /opt/quarantine/FSL/5.0.10/build/etc/flirtsch/ident.mat /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/ROIs/Atlas_ROIs.2.nii.gz ENCLOSING_VOXEL /tmp/tmp8oufi1_q/input_nii_r.nii.gz
[ciftify.utils] INFO: Running: wb_command -cifti-create-dense-scalar /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.aparc+aseg.32k_fs_LR.dscalar.nii -volume /tmp/tmp8oufi1_q/input_nii_r.nii.gz /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/ROIs/Atlas_ROIs.2.nii.gz -left-metric /tmp/tmp8oufi1_q/L.func.gii -roi-left /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/fsaverage_LR32k/100307.L.atlasroi.32k_fs_LR.shape.gii -right-metric /tmp/tmp8oufi1_q/R.func.gii -roi-right /mnt/tigrlab/scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/fsaverage_LR32k/100307.R.atlasroi.32k_fs_LR.shape.gii
[ciftify_vol_result] INFO: 
-------------------------------------------------------------
2018-04-23 16:59:11.071605 : Done ciftify_vol_result
-------------------------------------------------------------



In [5]:
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--HCP-MSMAll','--resample-nifti',
         '--ciftify-work-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))])


Running: ciftify_vol_result --HCP-Pipelines --HCP-MSMAll --resample-nifti --ciftify-work-dir /scratch/edickie/ciftify_intergration_tests/src_data/HCP --integer-labels 100307 /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.aparc+aseg_MSMAll.32k_fs_LR.dscalar.nii

In [6]:
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--HCP-MSMAll','--resample-nifti',
         '--ciftify-work-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))])


Running: ciftify_vol_result --HCP-Pipelines --HCP-MSMAll --resample-nifti --ciftify-work-dir /scratch/edickie/ciftify_intergration_tests/src_data/HCP --integer-labels 100307 /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/aparc+aseg.nii.gz /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.aparc+aseg_MSMAll.32k_fs_LR.dscalar.nii

In [7]:
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--resample-nifti',
         '--ciftify-work-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))])


Running: ciftify_vol_result --HCP-Pipelines --resample-nifti --ciftify-work-dir /scratch/edickie/ciftify_intergration_tests/src_data/HCP 100307 /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/T2w_restore.nii.gz /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.T2w_restore.32k_fs_LR.dscalar.nii

In [8]:
if run_HCP_tests:
    run(['ciftify_vol_result','--HCP-Pipelines', '--HCP-MSMAll',
         '--ciftify-work-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))])


Running: ciftify_vol_result --HCP-Pipelines --HCP-MSMAll --ciftify-work-dir /scratch/edickie/ciftify_intergration_tests/src_data/HCP 100307 /scratch/edickie/ciftify_intergration_tests/src_data/HCP/100307/MNINonLinear/T2w_restore.2.nii.gz /scratch/edickie/ciftify_intergration_tests/run_2018-04-16/HCP/100307.T2w_restore_MSMAll.32k_fs_LR.dscalar.nii