In the previous post I used matlab and ran wb_command from the command prompt (on Windows, by opening a command window in the directory with wb_command.exe, then using full paths to the input and output files). Here, I use R, and call wb_command from within R using its system() function. You may need to adjust system for other operating systems, or simply replace it with print and copy-paste the full line to the command prompt.
rm(list=ls()); # clear R's memory
setwd("d:/Workbench/workbench-v1.2.3/bin_windows64/"); # location of wb_command.exe, to call wb_command functions via system() within R
local.path <- "d:/temp/"; # local directory for reading and writing files
s1200.path <- "d:/Workbench/HCP_S1200_GroupAvg_v1/"; # HCP S1200 Group Average Data Release
template.fname <- "MMPtemplate.pscalar.nii"; # filename for the template we'll make
# make a template pscalar.nii from the MMP atlas
system(paste0("wb_command -cifti-parcellate ", s1200.path, "S1200.thickness_MSMAll.32k_fs_LR.dscalar.nii ",
s1200.path, "Q1-Q6_RelatedValidation210.CorticalAreas_dil_Final_Final_Areas_Group_Colors.32k_fs_LR.dlabel.nii COLUMN ",
local.path, template.fname));
if (!file.exists(paste0(local.path, template.fname))) { stop(paste0("missing: ", local.path, template.fname)); }
# you can make a text version of the template, which has 360 rows, but the values in each row aren't the parcel numbers.
# system(paste0("wb_command -cifti-convert -to-text ", local.path, template.fname, " ", local.path, "temp.txt"));
# the text file needs to be arranged with the 180 right hemisphere parcels in the first 180 rows (in order),
# then the 180 parcels for the left hemisphere.
# build a text file with the values to plot.
out.vec <- rep(0,360);
out.vec[c(1,10,15)] <- 1; # right hemisphere parcels given value 1
out.vec[c(180+1,180+10,180+15)] <- 2; # corresponding left hemisphere parcels given value 2
write.table(out.vec, paste0(local.path, "plotDemo.txt"), col.names=FALSE, row.names=FALSE);
# create a CIFTI from the text file for viewing in Workbench
system(paste0("wb_command -cifti-convert -from-text ", local.path, "plotDemo.txt ", local.path, template.fname, " ", local.path, "plotDemo.pscalar.nii"));
if (!file.exists(paste0(local.path, "plotDemo.pscalar.nii"))) { stop(paste("missing:", local.path, "plotDemo.pscalar.nii")); }
And here is the resulting image, with parcels 1, 10, and 15 plotted in pink on the right hemisphere (1), and yellow on the left (2). Instructions for generating this view are below the jump.