Timeseries Analysis

CPAC.timeseries.create_surface_registration(wf_name='surface_registration')[source]

Workflow to generate surface from anatomical data and register the structural data to FreeSurfer anatomical and assign it to a surface vertex.

wf_name : string
name of the workflow
wflow : workflow object
workflow object

Source

Workflow Inputs:

inputspec.rest : string  (nifti file)
    path to input functional data
inputspec.brain : string (nifti file)
    path to skull stripped anatomical image
inputspec.recon_subjects : string
    path to subjects directory
inputspec.subject_id : string
    subject id 

Workflow Outputs:

outputspec.reconall_subjects_dir : string
    freesurfer subjects directory
outputspec.reconall_subjects_id : string
    subject id for which anatomical data is taken
outputspec.out_reg_file : string
    path to bbregister output registration file
outputspec.lh_surface_file : string (mgz file)
    path to left hemisphere cortical surface file 
outputspec.rh_surface_file : string (mgz file)
    path to right hemisphere cortical surface file 

Order of commands:

  • Generate surfaces and rois of structural data from T1 anatomical Image using FreeSurfer’s reconall . For details see ReconAll:

    recon-all -all -subjid 0010001 -sd working_dir/SurfaceRegistration/anat_reconall
    
  • Register input volume to the FreeSurfer anatomical using FreeSurfer’s bbregister. The input is the output of the recon-all command. For details see BBRegister:

    bbregister --t2 --init -fsl --reg structural_bbreg_me.dat --mov structural.nii --s 0010001
    
  • Assign values from a volume to each surface vertex using FreeSurfer’s mri_vol2surf . For details see mri_vol2surf:

    For left hemisphere
    mri_vol2surf --mov structural.nii --reg structural_bbreg_me.dat --interp trilin --projfrac 0.5 --hemi lh --o surface_file.nii.gz 
    
    For right hemisphere        
    mri_vol2surf --mov structural.nii --reg structural_bbreg_me.dat --interp trilin --projfrac 0.5 --hemi rh --o surface_file.nii.gz
    

High Level Workflow Graph:

workflows/../images/surface_registration.dot.png

Detailed Workflow Graph:

workflows/../images/surface_registration_detailed.dot.png
>>> import CPAC.timeseries.timeseries_analysis as t
>>> wf = t.create_surface_registration()
>>> wf.inputs.inputspec.rest = '/home/data/sub001/rest.nii.gz'
>>> wf.inputs.inputspec.brain = '/home/data/sub001/anat.nii.gz'
>>> wf.inputs.inputspec.recon_subjects = '/home/data/working_dir/SurfaceRegistration/anat_reconall'
>>> wf.inputs.inputspec.subject_id = 'sub001'
>>> wf.base_dir = './'
>>> wf.run() 
CPAC.timeseries.get_voxel_timeseries(wf_name='voxel_timeseries')[source]

Workflow to extract time series for each voxel in the data that is present in the input mask

wf_name : string
name of the workflow
wflow : workflow object
workflow object

Source

Workflow Inputs:

inputspec.rest : string  (nifti file)
    path to input functional data
inputspec.output_type : string (list of boolean)
    list of boolean for csv and npz file formats
input_mask.masks : string (nifti file)
    path to ROI mask

Workflow Outputs:

outputspec.mask_outputs: string (1D, csv and/or npz files)
    list of time series matrices stored in csv and/or
    npz files.By default it outputs mean of voxels 
    across each time point in a afni compatible 1D file.

High Level Workflow Graph:
>>> import CPAC.timeseries.timeseries_analysis as t
>>> wf = t.get_voxel_timeseries()
>>> wf.inputs.inputspec.rest = '/home/data/rest.nii.gz'
>>> wf.inputs.input_mask.mask = '/usr/local/fsl/data/standard/MNI152_T1_2mm_brain.nii.gz'
>>> wf.inputs.inputspec.output_type = [True,True]
>>> wf.base_dir = './'
>>> wf.run()
CPAC.timeseries.get_roi_timeseries(wf_name='roi_timeseries')[source]

Workflow to extract timeseries for each node in the ROI mask. For each node, mean across all the timepoint is calculated and stored in csv and npz format.

wf_name : string
name of the workflow
wflow : workflow object
workflow object

Source

Workflow Inputs:

inputspec.rest : string  (nifti file)
    path to input functional data
inputspec.output_type : string (list of boolean)
    list of boolean for csv and npz file formats
input_roi.roi : string (nifti file)
    path to ROI mask

Workflow Outputs:

outputspec.roi_outputs : string (list of files)
    Voxel time series stored in 1D (column wise timeseries for each node), 
    csv and/or npz files. By default it outputs timeseries in a 1D file.
    The 1D file is compatible with afni interfaces.
>>> import CPAC.timeseries.timeseries_analysis as t
>>> wf = t.get_roi_timeseries()
>>> wf.inputs.inputspec.rest = '/home/data/rest.nii.gz'
>>> wf.inputs.input_roi.roi = '/usr/local/fsl/data/atlases/HarvardOxford/HarvardOxford-cort-maxprob-thr0-2mm.nii.gz'
>>> wf.inputs.inputspec.output_type = [True,True]
>>> wf.base_dir = './'
>>> wf.run()
CPAC.timeseries.get_vertices_timeseries(wf_name='vertices_timeseries')[source]

Workflow to get vertices time series from a FreeSurfer surface file

wf_name : string
name of the workflow
wflow : workflow object
workflow object

Source

Workflow Inputs:

inputspec.lh_surface_file : string (nifti file)
    left hemishpere surface file
inputspec.rh_surface_file : string (nifti file)
    right hemisphere surface file

Workflow Outputs:

outputspec.surface_outputs: string (csv and/or npz files)
    list of timeseries matrices stored in csv and/or
    npz files
>>> import CPAC.timeseries.timeseries_analysis as t
>>> wf = t.get_vertices_timeseries()
>>> wf.inputs.inputspec.lh_surface_file = '/home/data/outputs/SurfaceRegistration/lh_surface_file.nii.gz'
>>> wf.inputs.inputspec.rh_surface_file = '/home/data/outputs/SurfaceRegistration/rh_surface_file.nii.gz'
>>> wf.base_dir = './'
>>> wf.run()
CPAC.timeseries.gen_vertices_timeseries(rh_surface_file, lh_surface_file)[source]

Method to extract timeseries from vertices of a freesurfer surface file

rh_surface_file : string (mgz/mgh file)
left hemisphere FreeSurfer surface file
lh_surface_file : string (mgz/mgh file)
right hemisphere FreeSurfer surface file
out_list : string (list of file)
list of vertices timeseries csv files
CPAC.timeseries.gen_voxel_timeseries(data_file, template, output_type)[source]

Method to extract timeseries for each voxel in the data that is present in the input mask

datafile : string (nifti file)
path to input functional data
template : string (nifti file)
path to input mask in functional native space
output_type :list
list of two boolean values suggesting the output types - numpy npz file and csv format
out_list : list of files
Based on ouput_type options method returns a list containing path to npz and csv file having timeseries of each voxel in the data that is present in the input mask.The row header corresponds to voxel’s xyz cordinates and column headers corresponds to the volume index in the csv. By default it outputs afni compatible 1D file with mean of timeseries of voxels across timepoints.

Exception

CPAC.timeseries.gen_roi_timeseries(data_file, template, output_type)[source]

Method to extract mean of voxel across all timepoints for each node in roi mask

datafile : string
path to input functional data
template : string
path to input roi mask in functional native space
output_type : list
list of two boolean values suggesting the output types - numpy npz file and csv format
out_list : list
list of 1D file, txt file, csv file and/or npz file containing mean timeseries for each scan corresponding to each node in roi mask

Exception

CPAC.timeseries.get_spatial_map_timeseries(wf_name='spatial_map_timeseries')[source]

Workflow to regress each provided spatial map to the subjects functional 4D file in order to return a timeseries for each of the maps

wf_name : string
name of the workflow
wflow : workflow object
workflow object

Source

Workflow Inputs:

inputspec.subject_rest : string  (nifti file)
    path to input functional data
inputspec.subject_mask : string (nifti file)
    path to subject functional mask
inputspec.spatial_map : string (nifti file)
    path to Spatial Maps
inputspec.demean : Boolean
    control whether to demean model and data

Workflow Outputs:

outputspec.subject_timeseries: string (txt file)
    list of time series stored in a space separated
    txt file
    the columns are spatial maps, rows are timepoints
>>> import CPAC.timeseries.timeseries_analysis as t
>>> wf = t.get_spatial_map_timeseries()
>>> wf.inputs.inputspec.subject_rest = '/home/data/rest.nii.gz'
>>> wf.inputs.inputspec.subject_mask = '/home/data/rest_mask.nii.gz'
>>> wf.inputs.inputspec.ICA_map = '/home/data/spatialmaps/spatial_map.nii.gz'
>>> wf.inputs.inputspec.demean = True
>>> wf.base_dir = './'
>>> wf.run()