Beauchamp:ALICE: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
No edit summary
No edit summary
Line 14: Line 14:
   Aligning CT to MRI... This might take several minutes. Please wait...
   Aligning CT to MRI... This might take several minutes. Please wait...
   tcsh -x alignCTtoT1_shft_res.csh -CT_path CT_highresRAI.nii -T1_path../MRI/YBK_T1.nii
   tcsh -x alignCTtoT1_shft_res.csh -CT_path CT_highresRAI.nii -T1_path../MRI/YBK_T1.nii
This shell script contains the following steps
This shell script contains the following steps:
   @Align_Centers -base $t1  -dset $ct
   @Align_Centers -base $t1  -dset $ct
   3dresample -input CT_highresRAI_shft.nii -prefix CT_highresRAI_res_shft.nii  -master $t1  -dxyz 1 1 1 -rmode NN
   3dresample -input CT_highresRAI_shft.nii -prefix CT_highresRAI_res_shft.nii  -master $t1  -dxyz 1 1 1 -rmode NN
Line 44: Line 44:
   echo "Table of coordinates saved as clst.1D"
   echo "Table of coordinates saved as clst.1D"


The electrodes were manually selected using the 3-D clustering image in SUMA. Electrodes were selected in order.  
The electrodes were manually selected using the 3-D clustering image in SUMA. Electrodes were selected individually and in order. SUMA was quit after selection was completed.
This script contains the following commands for electrode selection:  
This script contains the following commands for electrode selection:  
   #get the xyz coordinate in the volume
   #get the xyz coordinate in the volume
   # really only need this for the afni_sphere case
   # really only need this for the afni_sphere case

Revision as of 11:57, 21 July 2017

This page shows the steps used by the ALICE package to localize electrodes. These steps are called from within a Matlab GUI.


The GUI has three steps. Here is the log file from the first step (an edited version of /Volumes/data/UT/YBK/ALICE/log_info/Step1_log.txt with comments added )

 MRI scan selected: /Users/fosterlab/Documents/MATLAB/CTMR/DATA/YBK/ALICE/data/MRI/YBK_T1.nii
 FS segmentation selected: /Users/fosterlab/Documents/MATLAB/CTMR/DATA/YBK/ALICE/data/FreeSurfer/t1_class.nii

This file was originally called YBK_fs_ribbon_rh_class.nii (renamed version of rh.ribbon.nii)

 CT scan selected: /Users/fosterlab/Documents/MATLAB/CTMR/DATA/YBK/ALICE/data/CT/CT_highresRAI.nii

This file was originally called YBK_CT.nii

  Aligning CT to MRI... This might take several minutes. Please wait...
  tcsh -x alignCTtoT1_shft_res.csh -CT_path CT_highresRAI.nii -T1_path../MRI/YBK_T1.nii

This shell script contains the following steps:

 @Align_Centers -base $t1  -dset $ct
 3dresample -input CT_highresRAI_shft.nii -prefix CT_highresRAI_res_shft.nii  -master $t1  -dxyz 1 1 1 -rmode NN
 align_epi_anat.py -dset1 $t1 -dset2  CT_highresRAI_res_shft.nii -dset1_strip None -dset2_strip None -dset2to1 -suffix _al  -feature_size 1  -overwrite -cost nmi -giant_move -rigid_body > status.txt
 3dcopy  CT_highresRAI_res_shft_al+orig CT_highresRAI_res_al.nii
 3dcopy $t1 ./temp_ANAT.nii
 afni -com "SWITCH_UNDERLAY temp_ANAT.nii" -com "SWITCH_OVERLAY CT_highresRAI_res_al.nii"


The log file from the second step does not contain the called commands, the list below has been extracted from the Matlab file ctmrGUI.m Three parameters are set in the GUI: electrode max intensity, electrode volume, inter electrode space. For subject YBK, the max intensity that worked best was 3500. Electrode volume was set to “2”, space was set to “1”. The GUI then calls this script:

 tcsh -x 3dclustering.csh -CT_path ../CT/CT_highresRAI.nii -radius ' num2str(obj.settings.R) ' -interelectrode_space ' num2str(obj.settings.IS) ' -clip_value ' num2str(obj.settings.CV)]);

This script contains the following commands:

 3dclust -savemask 3dclusters_r${r}_is${is}_thr${cv}.nii -overwrite -1Dformat -1clip $cv $is $r $ct  > clst.1D 
 # make sure the clusters all show up in afni with distinct colors
 3drefit -cmap INT_CMAP 3dclusters_r${r}_is${is}_thr${cv}.nii 
 # now resample the clusters, erode, dilate and cluster again
 # this helps separate the clusters that overlap
 3dresample -prefix temp_clusts_rs0.5 -overwrite -rmode NN -dxyz 0.5 0.5 0.5 -inset 3dclusters_r${r}_is${is}_thr${cv}.nii
 3dmask_tool -dilate_inputs -1 +2 -prefix temp_clusts_rs0.5_de2 -overwrite -inputs temp_clusts_rs0.5+orig
 3dclust -savemask 3dclusters_r${r}_is${is}_thr${cv}.nii -overwrite -1Dformat -1clip $cv $is $r temp_clusts_rs0.5_de2+orig > clst.1D 
 3drefit -cmap INT_CMAP 3dclusters_r${r}_is${is}_thr${cv}.nii 
 rm temp_clusts*.HEAD temp_clusts*.BRIK*
 IsoSurface -isorois+dsets -mergerois+dset -autocrop -o_gii 3dclusters_r${r}_is${is}_thr${cv}.gii -input 3dclusters_r${r}_is${is}_thr${cv}.nii  
 echo "Clustered dataset saved as 3dclusters_r${r}_is${is}_thr${cv}.nii"
 echo "Table of coordinates saved as clst.1D"

The electrodes were manually selected using the 3-D clustering image in SUMA. Electrodes were selected individually and in order. SUMA was quit after selection was completed. This script contains the following commands for electrode selection:

 #get the xyz coordinate in the volume
 # really only need this for the afni_sphere case
 # could be a tiny bit faster without this check most of the time
  plugout_drive  $NPB                                         \
  -com 'GET_DICOM_XYZ'                               \
  -quit
 # have suma report its current surface label - which cluster
 DriveSuma $NPB -com "get_label"
 set clustindex = `tail -2 $sumasurf|head -1` #v2.0. old version=-1 $sumasurf`
 set xyzstr = `tail -1 $surfcoords`
 # output from plugout is of form "RAI xyz: x y z"
 # we can use just part of that
 # if we are using the exact location for a sphere, let's mark that here
 echo $electrode_i $clustindex $xyzstr[3-5] $afni_sphere >> $surfcoords_i
 set clustval = `echo $clustindex | sed  's/roi//' |sed 's/(I,T,B)R=//'|\
         sed 's/(I,T,B)numeric=//'`
 # make 1/3 bright and add it to the list
 # this doesn't change the data in any way here
 # much smaller memory leak, 1000 iterations less that 256MB total for suma
 set roistr = `ccalc -form "roi%3.3d" $clustval`
 # commented lines only useful for checking if roi's have already been recolored
 # for coloring with white, gray or other constant color, skip these lines
 # use grep to be sure this cluster number is legit and to check status
 # don't put any commands beween the grep and status check
 #      grep $roistr temproilist.txt
 # If first time cluster has been identified, recolor to 1/3 brightness
 #  could make else condition, rebrighten electrode
 #      if ($status) then
 set roirgb = `grep $roistr tempcmap.niml.cmap`
 set rgbout =  ("1.0" "1.0" "1.0")         #old version: `1deval -a "1D:$roirgb[1-3]" -expr a/3`
 # change niml file (redirect, then rename rather than in place with "sed -i ..." because of MacOS oddities)
 cat tempcmap.niml.cmap | sed "s/$roirgb/$rgbout 1 $roirgb[5] ${roistr}/" > tempcmap2.niml.cmap
 mv tempcmap2.niml.cmap tempcmap.niml.cmap
 #          DriveSuma $NPB -com surf_cont -switch_dset temp_marked_clusters.1D.dset 
 DriveSuma $NPB -com surf_cont -load_cmap tempcmap.niml.cmap
 #          echo $roistr >> temproilist.txt
 #      endif