Simple walkthrough and example code (python) to extract timeseries vectors, from a dense timeseries (dtseries) file, using a parcel set's dlabel file.
The most basic of needs for any analyses is a bit different using surface files. Here is an example in the most basic of scenarios. You have a dense timseries file created from the core HCP pipeline (or any offshoot, such as from DCAN lab or using fMRIPrep). Below is how you would:
- Create a ptseries (parcellated timeseries) file. This is the average value of all vertices within each surface parcel, for all TRs (repetition time).
- Extract the timeseries vectors from that ptseries file (to a .txt file use in any script), using the 333 cortical surface parcels in the Gordon 333 parcellation set.
Note: This ptseries (parcellated timeseries file) file can be used with other workbench commands, etc.
# the dtseries file you want to extract
dt_path = <PATH TO>'/your_dense_timeseries_file.dtseries.nii'
# whatever parcel set you want to use
parc_path = <PATH TO>'/Gordon333_Parcels_LR.dlabel.nii'
# output path to the ptseries you want to create -
pt_path = <PATH TO>'/your_parcellated_timeseries_file.ptseries.nii'
pt_comm = ' '.join(['wb_command',
'-cifti-parcellate',
dt_path,
parc_path,
'COLUMN',
pt_path
])
try:
subprocess.call(pt_comm, shell=True)
except subprocess.CalledProcessError as err:
print('ERROR:', err)
# output path to the .txt - this will have one vector, per line.
# NOTE: Each line is a parcel (in the order the dlabel file has them labeled).
# Each vector has one value for each TR of the scan.
tc_path = <PATH TO>'/your_timeseries_text_file.txt'
tcext_comm = ' '.join(['wb_command',
'-cifti-convert',
'-to-text',
pt_path,
tc_path
])
try:
subprocess.call(tcext_comm, shell=True)
except subprocess.CalledProcessError as err:
print('ERROR:', err)