Detecting subcortical activity using Brainstorm

Hi !

My question is regarding the protocol for detecting deep brain activity described in:

Balderston, N. L., Schultz, D. H., Baillet, S., Helmstetter, F. J. How to Detect Amygdala Activity with Magnetoencephalography using Source Imaging. J. Vis. Exp. (76), e50212, doi:10.3791/50212 (2013).

More specifically the preprocess MRI volume part of the protocol. I am facing some challenges from step 12.3 of the protocol. The authors use a script (importsurfaces.csh) to help with this step that I dont have access to.
Can some one elaborate on how to convert the subcortical structure volumes into surfaces using Slicer3 and Paraview ?

Thanks in advance.

Shrikanth

Hi Shrikanth,

I’m transferring your message to Nick Balderston.

In Brainstorm you can now directly import the sub-cortical atlas generated by FreeSurfer, as illustrated here:
http://neuroimage.usc.edu/brainstorm/Tutorials/LabelFreeSurfer

Cheers,
Francois

Hi Shrikanth,

The method and scripts I used are pretty old, and tailored to my computer, so I would also recommend using the built in functionality in brainstorm. However, if that is not an option, here are copies of the scripts that I used originally. They run in tcsh, and they might have to be changed depending on what versions of the software you use.

Hope this helps.
-nick

The basic steps are as follows:

  1. Run 01.segmentation.csh to generate the aseg file.
  2. Import the aseg file into 3dslicer. <-- running 02.import_surface.csh will probably do this, but at this point, it might be easier to import it manually.
  3. Use the model maker module in 3dslicer to generate the surfaces.
  4. Save the surfaces as .vtk files.
  5. Import the .vtk files into paraview.
  6. Generate surface normals.
  7. Save the surfaces as .ply (ascii) files. This will give you the faces and vertices needed to create the brainstorm surfaces, but they are in the wrong format.
  8. Convert the .ply files into brainstorm surfaces. <-- Running 02.import_surfaces.csh again should take care of this, but it might be better to apply your own solution.

01.segmentation.csh


#!/bin/tcsh

##########must be changed##########
setenv subfolder /GOLGI/MEG_db/MEG_clinic/maskcond/fMRI #root folder where subjects' T1 images will be stored
setenv scriptfolder /GOLGI/MEG_db/MEG_clinic/maskcond/SCRIPTS #folder where this script and other scripts will be stored
setenv SUBJECTS_DIR /GOLGI/MEG_db/MEG_clinic/maskcond/fMRI/SEGMENTATION #root folder where subjects' segmented anatomy will be stored

foreach subject ( `ls ${subfolder}` )

echo "Perform freesurfer segmentation"

if (-e ${subfolder}/${subject}/skip ) then
	echo "${subfolder}/${subject} is not a subject directory"
else if (-e ${SUBJECTS_DIR}/${subject}/SUMA) then
	echo "${subject} segmentation complete"
else

mkdir ${SUBJECTS_DIR}/${subject}

cp ${subfolder}/${subject}/${subject}.anat+orig.* ${SUBJECTS_DIR}/${subject}/

recon-all -subject ${subject} -i ${subject}.anat+orig.BRIK -force -autorecon1 >> autorecon1.txt
recon-all -subject ${subject} -autorecon2 >> autorecon2.txt
recon-all -subject ${subject} -autorecon3 >> autorecon3.txt

mri_watershed -useSRAS -LABEL -T1 ${SUBJECTS_DIR}/${subject}/mri/T1.mgz ${SUBJECTS_DIR}/${subject}/mri/T12.mgz

rename _ lh. _*
mv lh.* surf

echo "Create AFNI readable files"

@SUMA_Make_Spec_FS \
-sid ${subject} \
-fspath ${SUBJECTS_DIR}/${subject}

endif

02.importsurface.csh


#!/bin/csh

#########requirements
	#SUBJECTS_DIR	must have subfolders with each subject's standard freesurfer output + a SUMA directory with aseg.nii and brain.nii files
	#BRAINSTORM_DIR	must be a folder within your brainstorm_db folder. also, subjects must be created in brainstorm prior to running this script. 
	#SCRIPTS_DIR	where this script is run from. 
	#subject	this is the list of subjects that you want to run, which is defined in the 'foreach subject loop'
	#3dSlicer - 	http://www.slicer.org/
	#paraview - 	http://www.paraview.org/
	#freesurfer
	#afni
	#caveat -	this script was designed to import the folloing things into brainstorm 'outer skin surface' 'outer skull surface' 
	#		'left and right pial surfaces' 'left and right amygdala' 'left and right hippocampi'
	#		If you want to import surface models from other subcortical structures, you will need to manually make them in 
	#		slicer and paraview. You will then need to save an alternate importsurfaces.mrml file and update the 'foreach model()' loop
	#		If you want to import other freesurfer surfaces, you will need to update the 'foreach surf ()' loop

##########must be changed##########
setenv subfolder /GOLGI/MEG_db/MEG_clinic/maskcond/fMRI #root folder where subjects' T1 images will be stored
setenv SUBJECTS_DIR /GOLGI/MEG_db/MEG_clinic/maskcond/fMRI/SEGMENTATION #root folder where subjects' segmented anatomy will be stored
setenv BRAINSTORM_DIR /GOLGI/MEG_db/brainstorm/maskcond/anat #root folder where brainstorm stores matlab formatted anatomy files 
setenv SCRIPTS_DIR /GOLGI/MEG_db/MEG_clinic/maskcond/SCRIPTS #folder where this script and other scripts will be stored

foreach sub ( `ls ${subfolder}` )

setenv subject $sub

if (-e ${subfolder}/${subject}/skip ) then
	echo "${subfolder}/${subject} is not a subject directory"
else if (-e ${BRAINSTORM_DIR}/${subject}/tess_l_amy.mat) then
	echo "${subject} anatomy has been successfully exported"
else if (-e ${SCRIPTS_DIR}/${subject}.lock) then

${SCRIPTS_DIR}/step2.importsurface.csh

else

${SCRIPTS_DIR}/step1.importsurface.csh

endif
end


step1.importsurface.csh


#!/bin/csh

echo "Copy surfaces and volumes to model directory. Create 3dslicer settings file (importsurface.mrml)"

echo "this is the first run" > ${SCRIPTS_DIR}/${subject}.lock
mkdir ${SUBJECTS_DIR}/${subject}/MODEL
cd  ${SUBJECTS_DIR}/${subject}/MODEL

##########must be changed if you want to work with other freesurfer surfaces##########
foreach surface (lh.pial rh.pial lh.outer_skin_surface lh.outer_skull_surface)
	cp ${SUBJECTS_DIR}/${subject}/surf/${surface} .
end

foreach volume (aseg.nii brain.nii)
	cp ${SUBJECTS_DIR}/${subject}/SUMA/${volume} .
end

step2.importsurface.csh


#!/bin/csh


echo "Convert surfaces to matlab/brainstorm files."

cd  ${SUBJECTS_DIR}/${subject}/MODEL

##########must be changed if you want to work with different subcortical volumes##########
rename 17 l_hipp 17.ply
rename 18 l_amy 18.ply
rename 53 r_hipp 53.ply
rename 54 r_amy 54.ply

rm -f ${SCRIPTS_DIR}/${subject}.lock

foreach model (l_hipp l_amy r_hipp r_amy)
	if (-e l_hipp.1D.topo) then
		set allsurfs="${allsurfs}', '${model}"
	else
		set allsurfs="surfarray = {'${model}"
	endif
	ConvertSurface -i ${model}.ply -o_1D ${model}.1D.coord ${model}.1D.topo
end

##########must be changed if you want to work with different freesurfer surfaces##########
foreach surf (lh.pial rh.pial lh.outer_skin_surface lh.outer_skull_surface)
	mris_convert ${surf} ${surf}.asc
	ConvertSurface -i ${surf}.asc -o_1D ${surf}.1D.coord ${surf}.1D.topo
	set allsurfs="${allsurfs}', '${surf}"
end

set allsurfs="${allsurfs}'}"

echo "function importsurface" > ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "cd  ${SUBJECTS_DIR}/${subject}/MODEL;" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "${allsurfs};" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "for i = 1:length(surfarray);" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "    surface = surfarray{i};" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "    fprintf(surface);" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "coord = '.1D.coord';" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "topo = '.1D.topo';" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "Vertices = importdata(strcat(surface, coord)) / 1000;" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "Faces = importdata(strcat(surface, topo)) + 1;" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "Comment = surface;" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "tessfile = strcat('tess_', surface, '.mat');" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "save(tessfile, 'Faces', 'Vertices', 'Comment');" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
echo "end" >> ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m

chmod a+rwx ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m
matlab -nodesktop -nosplash -nodisplay -r "run ${SUBJECTS_DIR}/${subject}/MODEL/importsurface.m ; quit;"
cp *.mat ${BRAINSTORM_DIR}/${subject}
cp ${SUBJECTS_DIR}/${subject}/mri/T1.mgz ${BRAINSTORM_DIR}/${subject}


Hi Nick and Francois,

Thanks for the information. However, if there is built in functionality in brainstorm to detect subcortical activity I would be glad to try it. Are there any documentation/tutorial on this topic ?

I’ve created the subcortical surfaces(basal ganglia components) from the aseg atlas as described in the tutorial. Now, how do I proceed with the creating the forward model & inverse model from the cortex surface(cortex_15000V) and the subcortical surface(basal ganglia components).

Cheers,
Shrikanth

Hi Shrikanth,

You can can extract the structures you are interested in from the Aseg atlas: select them in the list and click on the menu Scout > Edit surface > Keep only selected scouts.
Then group them with your cortex surface: select them at the same time in the list > Merge.
Then you can calculate forward and inverse models using this surface (prefer an unconstrained source models, with no orientation prior).

This is not a very good solution since it does not use the best possible sets of contraints for all the structures at the same time.
Yohan Attal is currently working on implementing in Brainstorm his methods for minimum norm source estimation in the deep brain structures, but I don’t know when it is going to be available: http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0059856

Cheers,
Francois