Cortical Surface Analysis Cortical Surface Asymmetry Analysis Statistical Tests and Netfiles

Cortical Surface Analysis

After sulcal lines have been drawn for all subjects, cortical surface analysis can be done.  The first step of the process is to create flatmaps that represent the cortex for each subject.  The flattened sulci of all the subjects included in the analysis are then averaged.  Using these average sulci as anchors, the flatmaps of each individual are warped so that cortical anatomy matches exactly across subjects.  An average cortex is then created.  Measures of gray matter density and brain size are gathered at each surface point.  Details about how to carry out each of these steps are provided below.  A copy of all scripts used in this process can be found in /loni/edevel/bin/CREATE_FLATMAPS.



Flatmaps

1)  When cortical surface analysis is begun, make a new directory.  Under this new directory, create a subdirectory to hold the sulcal lines for all the subjects in the project and copy the lines to it.

mkdir /loni/edevel/EXAMPLE_PROJECT
cd /loni/edevel/EXAMPLE_PROJECT
mkdir OBJS

 2)  Run the script 1_analyze.csh.  This script converts the sulcal line objs into ucfs and stores them in a UCFs subdirectory under the directory on which it is run.  It reslices the ucfs into rsps by dividing the ucfs into an equal number of points and stores these in an RSPs subdirectory under the directory on which is is run.  It computes the average position and variance in position of each line and stores them in AVG and VAR subdirectories.  To run this script, type 1_analyze.csh followed by the path of the directory containing the objs for all subjects that was created in step 1.

cp /loni/edevel/bin/CREATE_FLATMAPS/1_analyze.csh /loni/edevel/EXAMPLE_PROJECT
cd  /loni/edevel/EXAMPLE_PROJECT
1_analyze.csh  /loni/edevel/EXAMPLE_PROJECT/OBJS

3)  Run the script 2_makeSHORT.csh.  This script shortens the RSPs created in step 2, outputting a SHORTRSP3 file for each line for each subject.  If there is a large number of subjects, the script may not be able to run on all of them at once.  This script must be run in the directory in which the RSPs live.

cp /loni/edevel/bin/CREATE_FLATMAPS/2_makeSHORT.csh /loni/edevel/EXAMPLE_PROJECT/OBJS/RSPs
/loni/edevel/EXAMPLE_PROJECT/OBJS/RSPs/2_makeSHORT.csh

4)  Create a directory called "flatmaps" under the main directory for the project.  Under it, create a directory for each subject. Under each subject's directory in flatmaps, create a "CORT" directory.

cd /loni/edevel/EXAMPLE_PROJECT
mkdir flatmaps
cd flatmaps

foreach x (put list of subject numbers here)
mkdir {$x}
cd {$x}
mkdir CORT
cd ../
end

5)  For each subject, copy the SHORTRSPs created in step 3 into the CORT directory under the subject number.  Copy the colored object (subjectnumber_clrd.obj) into the CORT directory under the subject number as well.

cd /loni/edevel/EXAMPLE_PROJECT/OBJS/RSPS
foreach x (put list of subject numbers here)
cp SHORT*_{$x}_*ucf ../../flatmaps/{$x}/CORT
end

6)  After the colored objects and shortened RSPs are in place, run 3_flatten_script.csh.  This script should output a FLAT_SHORTRSP3 file for each line for each subject and other files related to the surface.  This script should be run from the flatmaps directory.

cp /loni/edevel/bin/CREATE_FLATMAPS/3_flatten_script.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
nedit /loni/edevel/EXAMPLE_PROJECT/flatmaps/3_flatten_script.csh to change subject numbers
/loni/edevel/EXAMPLE_PROJECT/flatmaps/3_flatten_script.csh

7)  The flatmaps are now complete.  Use seg to view the flatmaps.  To view the lines on the flatmap, select either Level #2 for the left hemisphere or Level #3 for the right hemisphere.  On the Image Display Window, select x3 from the Zoom menu.  In the window for each line, select Level #0.  An Editing Controls window should pop up.  Select "End Edit Session".  To change the color that the line is shown in, double click on the patch of color to the right of "Current Color" in the window for each line.  A "Current Contour" window will pop up.  Slide the bars around to select a new color.  Select OK, then Close.  Minimize the window for each line, since closing them will make the line disappear.  A flatmap with all its lines looks like this.  The numbers correspond to the numbers of the sulcal lines.

cd /loni/edevel/EXAMPLE_PROJECT/flatmaps/subjectnumber/CORT
seg -line 3 flat.uvl FLAT*L.ucf
seg -line 3 flat.uvl FLAT*R.ucf



Average Sulci

1)  Create a directory named AVG_FLAT under the main directory for the project. Move the FLAT_SHORTRSP3 files created in step 6 above from each subject's CORT directory into the AVG_FLAT directory.

cd /loni/edevel/EXAMPLE_PROJECT
mkdir AVG_FLAT

foreach x (put list of subject numbers here)
cd $x/CORT
mv FLAT_SHORT*ucf ../../../AVG_FLAT
cd ../../
end

2)  After the FLAT_SHORTRSP3s are in the AVG_FLAT directory, run 4_flat_map_average_script.csh.  This script reslices the FLAT_SHORTRSPs and creates flattened averages for each sulcal line.  These average lines will be used as the targets for the warping of each individual.  The script should be run from the main directory for the project.

cp /loni/edevel/bin/CREATE_FLATMAPS/4_flat_map_average_script.csh  /loni/edevel/EXAMPLE_PROJECT
cd  /loni/edevel/EXAMPLE_PROJECT
4_flat_map_average_script.csh

3)  The average and variance of the flattened sulcal lines have been computed.  The files in the AVG_FLAT directory with "3D_flatVAR" at the beginning of their names are the average flattened lines.  The files in the AVG_FLAT directory with "4D_flatVAR" at the beginning of their names have the variance at each point along the average line the 4th number in each line of text.




Warping

1)  Copy the files ord_decimal.uif and precise_flat.uvl into the flatmaps directory.  These files allow viewing of the warped flatmaps and will be copied into each individual subject's directory in a subsequent script.

cp /loni/edevel/bin/CREATE_FLATMAPS/ord_decimal.uif /loni/edevel/EXAMPLE_PROJECT/flatmaps
cp /loni/edevel/bin/SCRIPTS/CREATE_FLATMAPS/precise_flat.uvl /loni/edevel/EXAMPLE_PROJECT/flatmaps

2)  Edit the script 5_warp_script_subjectnumbers.csh so that the target and project directories are correct.  Usually, the target will be the average of the subjects in the analysis and the "directory" and "target" will be the same, but a different target can be specified.  Subjects must be grouped according to lines they are missing (lines 20, 22, and 2c from either hemisphere can be missing in any combination).  A script must be created for each group of subjects that includes all and only the sulcal lines that were drawn in the lists following "rightlines" and "leftlines" near the beginning of the script.   Subjects missing the same lines can be grouped together, but avoid putting more than 3 subjects into each batch because the computer will be overwhelmed by too many subjects at a time.  The edited script for each batch of subjects should be saved with the subject numbers included in the name (5_warp_script_subjectnumbers1.csh, 5_warp_script_subjectnumbers2.csh, etc.).

cp /loni/edevel/bin/CREATE_FLATMAPS/5_warp_script_subjectnumbers.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
nedit /loni/edevel/EXAMPLE_PROJECT/flatmaps to change the path, subject numbers, and lines included.
Save the edited scripts into loni/edevel/EXAMPLE_PROJECT/flatmaps, including subject numbers in the new names.

3)  Run 5_warp_script_subjectnumbers.csh for each group of subjects from inside the flatmaps directory.  Type
"top" in the window in which the script was run to see the processes completing.  As the jobs finish, they will disappear from the list of processes.  Because using the top command takes up a processor, be sure to type "q" when done checking on processes.

cd  /loni/edevel/EXAMPLE_PROJECT/flatmaps
5_warp_script_subjectnumbers1.csh
5_warp_script_subjectnumbers2.csh, etc.

4)  When the jobs have disappeared from the list of running processes, the warped flatmaps have been created.  If a subject's flatmap does not look correct (it has holes or a violent, swirly warp), it is most likely a problem with the lines.   As we are using a "no-holes" version of the commands, it is more likely that the script will break and leave a core file than that it will create the warped flatmaps with holes in them.   Check to be sure that the flatmaps do not have problems by going to each subject's CORT/WARP directory and examining the flatmaps using seg.  The files that are most important to us are the  prEw_ordL.uif and  prEw_ordR.uif for each individual, which are listed as levels 1 and 4.  See Troubleshooting for more information.

cd /loni/edevel/EXAMPLE_PROJECT/flatmaps/subjectnumber/CORT/WARP
seg precise_flat.uvl
Click on files in the "theUvl" window to make them appear in the "Image Display" window.




Average Cortex

1)   When the flatmaps have been checked for each individual, run 6_RGB_to_3Dcortex_script.csh to inflate the warped flatmap to a 3D cortical shell.  The correct subject numbers must be added to the script.  6_RGB_to_3Dcortex_script.csh must be run from inside the flatmaps directory.  The resulting files are elastically warped surfaces named 0prEw_hem_L.ucf, 0prEw_hem_R.ucf, 0prHEw_hem_L.ucf, and 0prHEw_hem_R.ucf.  The files with "H" in them have tubes running through them horizontally and those without the "H" have tubes running through them vertically.  The files with the lines running vertically (0prEw_hem_L.ucf and 0prEw_hem_R.ucf) are extremely important as they will be used for much of the further analysis.

cp /loni/edevel/bin/CREATE_FLATMAPS/6_RBG_to_3Dcortex_script.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
nedit  /loni/edevel/EXAMPLE_PROJECT/flatmaps/6_RBG_to_3Dcortex_script.csh to change the subject numbers
/loni/edevel/EXAMPLE_PROJECT/flatmaps/6_RBG_to_3Dcortex_script.csh

2)  7_make_average_surface.csh will make an average cortex shell for all the subjects in the analysis.  It will also convert the average ucfs into objs, which can be viewed in Display.  For each hemisphere and ucf, the code will make 2 objs (one named the same as the ucf and the other with "RR" before the name of the ucf) which must both be pulled up in Display to see the whole hemisphere.  Change the directories and names of output files in the script to match those of the project.

cp /loni/edevel/bin/CREATE_FLATMAPS/7_make_average_surface.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
nedit  /loni/edevel/EXAMPLE_PROJECT/flatmaps/7_make_average_surface.csh to change the paths and names of files
/loni/edevel/EXAMPLE_PROJECT/flatmaps/7_make_average_surface.csh

3)  The average cortical shell should be viewed to check for problems.  The files live in an AVG_SURFACE directory created by the previous script.  Use ctrview or vu to check each hemisphere's shape as a ucf and Display to view the objs.

cd  /loni/edevel/EXAMPLE_PROJECT/AVG_SURFACE
ctrview avg_EXAMPLE_PROJECT_prEw_hem_L.ucf
ctrview avg_EXAMPLE_PROJECT_prEw_hem_R.ucf
or
~thompson/vu avg_EXAMPLE_PROJECT_prEw_hem_L.ucf
~thompson/vu avg_EXAMPLE_PROJECT_prEw_hem_L.ucf

Display *obj



Gray Matter Distribution

Gray matter distribution maps require clamped gray matter minc files and the warped cortical surfaces created earlier.  Essentially, a count of the number of voxels classified as gray matter within a sphere centered at each surface point is taken over the surface of the brain for each individual.  The steps below explain exactly how this analysis is done.

1)  The script 1a_binary_gray_images.csh makes binary gray minc files.  The segmented image is clamped so that gray matter is assigned a value of 1 and everything else (white matter, CSF, non-brain tissue) is assigned a value of 0.  This binary image is then transformed into 305 space.  The directories and subject numbers must be modified in this script.

cp /loni/edevel/bin/CREATE_FLATMAPS/1a_binary_gray_images.csh /loni/edevel/EXAMPLE_PROJECT
nedit  /loni/edevel/EXAMPLE_PROJECT/1a_binary_gray_images.csh to change the subject numbers and paths
 /loni/edevel/EXAMPLE_PROJECT/1a_binary_gray_images.csh

2)  The script 2a_ucf_eat_vol_gray.csh calculates the percentage of gray matter in a sphere centered at each surface point.  The script uses the 0prEw_hem_R.ucf and 0prEw_hem_L.ucf files created during warping to determine the coordinates to sample in the binary gray image created above.  The directories and subject numbers must be modified in the script.  The diameter of the sphere used can be set in the script as well.  The output files, placed into each subject's CORT/WARP directory, are called grey15_305_subjectnumber_0prEw_hem_L.ucf and grey15_305_subjectnumber_0prEw_hem_R.ucf.  They are 4 dimensional ucfs in which the fourth dimension is the percentage of gray matter in the sphere centered at each surface point.

cp /loni/edevel/bin/CREATE_FLATMAPS/2a_ucf_eat_vol_gray.csh /loni/edevel/EXAMPLE_PROJECT
nedit  /loni/edevel/EXAMPLE_PROJECT/2a_ucf_eat_vol_gray.csh to change the subject numbers and paths
/loni/edevel/EXAMPLE_PROJECT/2a_ucf_eat_vol_gray.csh

3)  Averages, increase maps, and statistical maps can be made from these gray matter distribution maps.   See Statistical Tests and Netfiles for details.



Distance from Center/Zero

Distance from center (or zero) is used as a measure of local brain size.  If one brain is larger than another, the distance from the center of the brain (0, 0, 0 in the coordinate system) to the surface will be greater in the larger brain.  This measure can be obtained at all of the surface points in the warped ucfs.

1)  The script 1b_calculate_dfz.csh computes the distance from the center of the brain to each cortical surface point.  The 3 dimensional distance from the center of the brain to the cortex at each location is recorded as the fourth dimension of the output.  The script path and subject number must be modified in the script.

cp /loni/edevel/bin/CREATE_FLATMAPS/1b_calculate_dfz.csh /loni/edevel/EXAMPLE_PROJECT
nedit  /loni/edevel/EXAMPLE_PROJECT/1b_calculate_dfz.csh to change the subject numbers and path
/loni/edevel/EXAMPLE_PROJECT/1b_calculate_dfz.csh

2)  Averages, increase maps, and statistical maps can be made from these DFZ maps.  See Statistical Tests and Netfiles for details.



Troubleshooting

It is not uncommon for problems to come up during the process of following this protocol.   The most frequent sign that something is wrong is warped flatmaps with holes or excessive swirling, which look like these maps:  Fig1   Fig2.  The following tips might help to determine the source of the problem.
 

  • Flatmapping and warping depend upon only the sulcal lines that were drawn and the object model on which they were drawn.  If there is a problem with one of these step, these are the files to check.
  • If a particular line is suspected to be a problem, re-run the warping script without that line.  If the flatmap is fixed, it is likely that that line was drawn or flattened incorrectly; if not, another issue exists.
  • If a line is called on in the script that was not drawn for that subject, there will be warping problems as the script tries to warp the target from the missing line to the next line that was drawn for the subject, even though the anatomy might be way off.  If this is the problem, there will be a "No match" error following the echoed lines "DOING LEFT Hem first...setting filenames" or "DOING RIGHT Hem next...setting filenames"  in the UNIX window.
  • Warping problems can occur if the filenames or paths given in warping script are incorrect.  The reference ucfs (the lines for each subject) should come from the directory pointed to in lines 30 and 37 of the warping script and the target ucfs (the average lines) should come from the directory pointed to in lines 43 and 49.  Check to be sure these directories exist and hold the files they're expected to.  In lines 54 through 63, the files are renamed from their original names to simplified names.  Check to be sure that the correct file is targeted and moved.  If a problem is occurring with copying the lines, the window in which the script was run should show "no match" errors after the echo information about copying the ucfs ("Copying REFERENCE ucfs- Left hemisphere", "Copying REFERENCE ucfs- Right hemisphere", "Copying target ucfs- RSP files - Left hemisphere", or "Copying target  ucfs - RSP files - Right hemisphere").  If the filenames are incorrect, there will be a string of "No match" errors following the echoed lines "DOING LEFT Hem first...setting filenames" or "DOING RIGHT Hem next...setting filenames" .
  • A problem in warping can occur any time that target lines and reference lines are not matched properly.  To determine if this is the problem, list the lines that are used in warping into a text file.  Once the warping script has been run, go into the directory of the problem subject.  Open the files in nedit to see that they are paired properly (that a target and reference exist for each line).

  • ls ??L.ucf ???L.ucf > Left_match.txt
    ls ??R.ucf ???R.ucf > Right_match.txt
    nedit Left_match.txt Right_match.txt
  • Lines must fall correctly on the object model.  The lines and objects must be in the same space.  If the object model has been recreated and lines have not been withdrawn, they may fall underneath the surface or hover above it.  While the commands have a built-in step which sucks the lines onto the surface, an extreme case might still cause problems.  To check for this, load the lines and surfaces in Display.  Redraw lines as necessary.
  • Lines must not cross.  When lines cross, it means that the same point is labeled as two separate pieces of anatomy.  When warping occurs and the anatomy is directed in separate ways, the map can be torn.  Check for crossing lines in Display.  Even if lines do not cross on the object model, they may cross when flattened.  Pull up the flattened lines over the non-warped flatmap to check for this.  If two lines are suspected of crossing, try re-warping using only one of the lines.  If the problem is fixed, redraw the lines and warp again using all the lines.
  • Lines must not be drawn backwards.  If a line is drawn backward, the first point of that subject's line is directed to the last point of the average line, and the violence of that movement can cause swirling or holes.  To check for backward lines, create markers out of the starting point of each line by running the script make_markers_at_start.csh.   Open the lines and markers for all objects, one line at a time.  If lines have been drawn backwards, the green markers at their starting points will be at the opposite end of the mass of lines from the rest of the markers.  The exact lines which have been drawn backward can be determined by making each subject's marker invisible and noting which subject was different.
  • Ucfs can be viewed with either ~thompson/vu or ctrview.  The flattened target and reference lines for a subject can be shown this way.  For a given sulcus, the target and reference UCF should be fairly close to each other.  The re-inflated ucf representing the whole brain can also be shown using vu or ctrview.  A hole in the flatmap will frequently show up as lines extending from the surface of the brain in the UCF, like Fig 3.
  • Gray matter maps depend on the lines, the object, and the binary gray image.  If the warped flatmap looks correct, but a problem exists with the gray matter maps, the binary gray image is likely the problem.  To check to make sure that the binary gray image is in the same space, pull up the object model and binary gray image in Display.  Select R (Objects) then W (Scan Object to Vol).  A red line should appear on the gray image.  The line shows how the object model falls on the surface.  It should follow the outside border of the gray matter fairly closely, like Fig 4.
  • The first 3 numbers in each line of the gray matter ucf for each subject should match the numbers in the same line in 0prEw_hem_R.ucf or 0prEw_hem_L.ucf .  If the numbers do not match, the eat volume script is grabbing the wrong input.



  • Cleaning

    The process of flatmapping creates many files in each subject's CORT and WARP directories which are duplicates of files that exist elsewhere.  To conserve space, these duplicated files are removed.

    1)  The script 8_clean_script.csh removes files from each subject's CORT and WARP directories which exist elsewhere.  The shortened UCFs are removed from the CORT directory, but they remain in the RSPs directory under the directory holding all the lines.  The object is removed from the CORT directory, but it remains in the CLRD directory under the directory holding all the lines.  The flattened lines are removed from the WARP directory, but they remain in the AVG_FLAT directory.


    Cortical Surface Asymmetry Analysis

    Once flatmaps have been created, asymmetry analysis can be done (See Flatmaps for more information).  For asymmetry measures to be correct, brain anatomy must be matched between hemispheres as well as between subjects.  Because there are normal structural asymmetries in the brain, the average sulcal lines from the left hemisphere are different from the average sulcal lines from the right hemisphere and if each hemisphere was to be warped to its own target, surface asymmetry would be underestimated.  Therefore, target lines used in warping the right hemisphere must be identical except in x-coordinate to those used in warping the left hemisphere.  To create this set of target lines, the flattened sulcal lines of the left hemisphere are reflected so that they are located in the space of the right hemisphere but are identical in shape to the lines in the left hemisphere.  The flatmaps representing the right hemisphere are warped to the reflected left target lines and the flatmaps representing the left hemisphere are warped to the normal left target lines.  The resulting warped flatmaps are therefore matched anatomically between hemispheres and between subjects and can be used to measure surface and gray matter asymmetries.  Details about how to carry out the analysis are provided below.  A copy of all scripts used in this process can be found in /loni/edevel/bin/ASYMMETRY.



    Flipping Target Sulci

    1)  Once average sulcal lines have been created (see Average Sulci), run 1_flat_target_curve_reflect.csh.  This script multiplies the x-dimension of the average flattened sulcal lines for the left hemisphere by -1 and shifts the lines into the right hemisphere's space.   These reflected left lines will serve as the target for warping the right hemisphere.    This script will create the directory REFLECTED_TARGET_UCFS in the AVG_FLAT directory and put the reflected lines into it.  The directory called upon in the script needs to be changed to match the directory used as the target in script 5_warp_script_subjectnumbers.csh.  Often, this directory will be the AVG_FLAT directory of the project.

    cp /loni/edevel/bin/ASYMMETRY/1_flat_target_curve_reflect.csh /loni/edevel/EXAMPLE_PROJECT
    nedit  /loni/edevel/EXAMPLE_PROJECT/1_flat_target_curve_reflect.csh to change the path
    /loni/edevel/EXAMPLE_PROJECT/1_flat_target_curve_reflect.csh



    Warping to Analyze Asymmetry

    1)  Edit the script 2_asym_precise_warp_subjectnumbers.csh so that the target and project directories are correct.  The path after "rtargdir" should be the location of the reflected left lines that will serve as the target lines for the right hemisphere.  The path after "ltargdir" should be the location of the non-reflected left lines that will serve as the target lines for the left hemisphere.  The path after "directory" should be the location of the AVG_FLAT directory for the project.  In many case, the average lines of the subjects in the project will be the target, so the "ltargdir" and "directory" paths will be the same.  Like the script 5_warp_script_subjectnumbers.csh from the flatmapping process, a new version of the script must be created for each group of subjects that includes all and only the lines that they have in the lists following "rightlines" and "leftlines" near the beginning of the script.  The scripts should be saved with the subject numbers it was designed for in the name
    ( 2_asym_precise_warp_subjectnumbers1.csh, 2_asym_precise_warp_subjectnumbers2.csh, etc. ).

    cp /loni/edevel/bin/ASYMMETRY/2_asym_precise_warp_subjectnumbers.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
    nedit /loni/edevel/EXAMPLE_PROJECT/flatmaps/2_asym_precise_warp_subjectnumbers.csh to change the paths, subject numbers, and lines used
    Save the edited script into loni/edevel/EXAMPLE_PROJECT/flatmaps, including subject number in the new name.

    2)  Run 2_asym_precise_warp_subjectnumbers.csh for each group of subjects from inside the flatmaps directory.  Type "top" in the window in which the script was run to see the processes running.  As the jobs finish, they will disappear from the list of processes. Because using top takes up a processor, be sure to type "q" when checking on the progress of scripts.

    cd  /loni/edevel/EXAMPLE_PROJECT/flatmaps
    2_asym_precise_warp_subjectnumbers1.csh
    2_asym_precise_warp_subjectnumbers2.csh, etc.

    3)  When the jobs disappear from the list displayed by typing "top" in the window, the warped flatmaps have been created.  Once again, the script uses a "no-holes" version of the warping command, so it may occasionally find and fix small holes in the flatmaps.   Check to be sure that the flatmaps do not have problems by going to each subject's CORT/ASYM_WARP directory and examining the warped flatmaps using seg.  As with normal warping, the files that are most important to us are the prEw_ordL.uif and  prEw_ordR.uif for each individual which are listed as levels 1 and 4.

    cd /loni/edevel/EXAMPLE_PROJECT/flatmaps/subjectnumber/CORT/ASYM_WARP
    seg precise_flat.uvl
    Click on files in the "theUvl" window to make them appear in the "Image Display" window.



     Surface Asymmetry

    1) When the flatmaps in ASYM_WARP have been checked for each individual, run 3_ASYM_decode_avg_flip.csh.  This script inflates the warped flatmaps that live in ASYM_WARP into 3-D cortical shells.  The resulting files are elastically warped surfaces named 0prEw_hem_L.ucf and 0prEw_hem_R.ucf that will be used in much of the further analysis.  This script then averages the warped surfaces for each hemisphere across all subjects in the analysis, outputting maps of the average surface location and variance around that location.  The script then flips each hemisphere's average flatmap and reverses the level orders.  The level orders must be reversed because the points run from back to front in one hemisphere and from front to back in the other (originally, the points were taken in circles as if the whole brain was a sphere).  The script then calculates the distance from each point on the normal average right surface to the anatomically match point on the flipped and reversed average left surface and from the normal average left to the flipped and reversed average right.  These maps show surface asymmetry as the distance in millimeters between anatomically matched points in the two hemispheres.  The script converts them from ucfs to dx files and puts them in a new directory called CORT_AVERAGING.  The paths and subject numbers must be modified in this script.  The output files will include the text that follows "name" in the filename, so this should be changed to reflect the project's name.

    cp /loni/edevel/bin/ASYMMETRY/3_ASYM_decode_avg_flip.csh  /loni/edevel/EXAMPLE_PROJECT/flatmaps
    nedit /loni/edevel/EXAMPLE_PROJECT/flatmaps/3_ASYM_decode_avg_flip.csh to change the name, paths, and subject numbers
    /loni/edevel/EXAMPLE_PROJECT/3_ASYM_decode_avg_flip.csh

    2)  The average surface asymmetry for all subjects in an analysis can be seen using opendx.  The dx files created by 3_ASYM_decode_avg_flip.csh should be put into a .net file designed to show surface asymmetry.  See Averaging 4 Dimensional UCFs for details.

    3)  If surface asymmetry is to be compared between groups, it will need to be calculated on an individual basis.  The script 1a_individual_surface_asym.csh flips each individual's warped surface and reverses the level order.  It then finds the distance between corresponding points on the right hemisphere and flipped and reversed left hemisphere and vice versa.  The output files, which show the surface asymmetry in millimeters for each subject, are called ind_surf_asym_subjectnumber_prEw_L.ucf and ind_surf_asym_subjectnumber_prEw_L.ucf.  The first three dimensions represent the location of each surface point and the fourth dimension represents the distance from that point in one hemisphere to the anatomically matched point in the other hemisphere.  The path and subject numbers in the script must be changed.

    cp /loni/edevel/bin/ASYMMETRY/1a_individual_surface_asym.csh  /loni/edevel/EXAMPLE_PROJECT/flatmaps
    nedit /loni/edevel/EXAMPLE_PROJECT/flatmaps/1a_individual_surface_asym.csh to change the path and subject numbers
    /loni/edevel/EXAMPLE_PROJECT/1a_individual_surface_asym.csh

    4)  The ind_surf_asym_subjectnumber_prEw_L.ucf and ind_surf_asym_subjectnumber_prEw_L.ucf files can be used to compare surface asymmetry between groups.  See Correlation Maps for details.

    5)  To calculate the significance of surface asymmetry within a group, a single measure of surface asymmetry is needed in the 4th dimension for each hemisphere.  Since previous work has shown that much of the surface asymmetry is the y-direction (front-back), the y-coordinate is frequently used as the measure of surface position at each point within a hemisphere.  The script put_y_in_4th_dim.csh will put the y-cooridinate into the 4th dimension of the ucfs for the right and left hemispheres.  The files that this script outputs will have "forR" or "forL" in their names, so that the coordinates from the normal UCF for one hemisphere will be compared to the coordinates from the flipped and reversed UCF for the other hemipshere.  These maps can then be compared using a Paired T-Test.



    Gray Matter Asymmetry

    1)  If gray matter analysis has been done for the project, binary gray images will already exist.  If not, the script
    1a_binary_gray_images.csh makes binary gray minc files.  See step 1 under Gray Matter Distribution for details on how to run the script.

    2)  Because a 4 dimensional ucf can not have its levels reversed properly (the code expects a 3 dimensional ucf), the gray matter density will need to be sampled from both normal and reversed-level ucfs.  The script 1b_ucf_eat_vol_asym.csh reverses the level order of the ucf for each hemisphere and calculates the percentage of gray matter in a sphere centered at each surface point in both normal and reversed-level ucf for each hemisphere.  The directories and subject numbers must be modified in the script.  The size of the sphere used can be set in the script as well.  The output files, placed into each subject's CORT/ASYM_WARP directory,  are called grey15_305_subjectnumber_0prEw_hem_L.ucf, grey15_sulcal_14_RE0prEw_hem_L.ucf, grey15_305_subjectnumber_0prEw_hem_R.ucf, and grey15_sulcal_14_RE0prEw_hem_L.ucf.  They are 4 dimensional ucfs in which the fourth dimension is the percentage of gray matter in the sphere centered at each surface point.

    cp /loni/edevel/bin/ASYMMETRY/1b_ucf_eat_vol_asym.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
    nedit  /loni/edevel/EXAMPLE_PROJECT/flatmaps/1b_ucf_eat_vol_asym.csh to change the subject numbers and paths
    /loni/edevel/EXAMPLE_PROJECT/flatmaps/1b_ucf_eat_vol_asym.csh

    3)  To compare gray matter density in the right hemisphere to gray matter density in the left hemisphere at analogous surface points, ratios will be computed.  The script 2b_grey_asym_ratio.csh computes the ratio of gray matter in the left hemisphere to gray matter in the right hemisphere at each surface point.  To compare the correct anatomy and display the maps correctly, ratio must use the normal gray matter map for one hemisphere and the gray matter map made from the file with reversed levels for the other hemisphere.  The ratio can then be transferred to a ucf containing the correct positional information.  The path and subject numbers must be modified in the script.

    cp /loni/edevel/bin/ASYMMETRY/2b_grey_asym_ratio.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
    nedit /loni/edevel/EXAMPLE_PROJECT/2b_grey_asym_ratio.csh to change the path and subject numbers
    /loni/edevel/EXAMPLE_PROJECT/2b_grey_asym_ratio.csh

    4)  To compare gray matter between hemispheres within groups, new gray matter maps will be created from existing information.  Gray matter maps created after the levels were reversed for one hemisphere have the levels in the same order as the maps created from normal ucfs in the other hemisphere (the anatomy is the same).  However, the first 3 dimensions of the reversed left hemisphere are not correct for display (they will make a flattened hemisphere if they are not flipped). Therefore, the script 3b_combine_gray.csh was created to combine the first 3 dimensions of the flipped ucf with reversed levels with the 4th dimension of the flipped ucf without reversed levels.  The path and subject numbers must be modified at the top of the script.  The resulting files will have "forR" or "forL" in their names.  These are the files that should be used for analysis of gray matter differences between hemispheres within a group.  See Paired T-Tests for details.

    cp /loni/edevel/bin/ASYMMETRY/3b_combine_gray.csh /loni/edevel/EXAMPLE_PROJECT/flatmaps
    nedit  /loni/edevel/EXAMPLE_PROJECT/flatmaps/3b_combine_gray.csh to change the subject numbers and path
    /loni/edevel/EXAMPLE_PROJECT/flatmaps/3b_combine_gray.csh



    Cleaning ASYM_WARP Directories

    The process of flatmapping creates files in each subject's ASYM_WARP directory which are duplicates of files that exist elsewhere.  To conserve space, these duplicated files are removed.

    1)  The script 4_clean_script.csh removes the flattened lines from each subject's ASYM_WARP, but they remain in the AVG_FLAT directory.


    Statistical Tests and Netfiles

    The code used for creating averages, increase and percentage maps, and statistical maps expects 4 dimensional ucfs.  In these files, the position in space of each point along the surface is represented by the first three numbers in each line of the ucf and the value of a variable (Gray Matter Distribution, Distance from Center/Zero, Surface Asymmetry, or Gray Matter Asymmetry ) at each point is the fourth number in each line.  In netfiles, the files read by opendx, the 4th dimension can be interpreted as color and displayed on a cortical shell. If correlations or multiple regression analyses  are to be run, a variable (age, gender, diagnosis) needs to be inserted into the ucf.  Code exists to run correlations, one-sample t-tests, paired t-tests, non-linear correlations, and multiple regression analyses at each point on the cortical surface.  Because statistical analysis of the surface involves over 65,000 separate tests, permutations must be done to correct for multiple comparisons before results are interpreted.  Comparisons can also be done on single lines of data or on brain volumes in Systat.  A set of sample scripts and netfiles is located in /loni/edevel/bin/STATS.  These templates will need to be modified for each new measure or data set.



    Using Data Explorer

    Data explorer is used to view results.  Color, representing some measure (average, P-value, etc.), is displayed on a cortical shell.  Data Explorer uses .net files, which are small programs that put files through groups of commands.  For many of the commonly made maps, template .net files line in /loni/edevel/bin/STATS.

    1)  The netfiles that Data Explorer uses read in .dx files.  A ucf can be converted into a dx file with one of two commands - ucf_to_dx for a 3 dimensional ucf or ucdx for a  4 dimensional ucf.

    ucf_to_dx 3D_ucf.ucf will output 3D_ucf.dx
    ucdx 4D_ucf.ucf will output 4D_ucf.dx

    2)  Data explorer should be run from an autarch or inire window.  It can be run locally, but it takes a lot of memory.

    In an autarch window, type "opendx -memory 500"

    3) When the Data Explorer window pops up, click on "Edit Visual Programs" and browse for and select the desired .net file.

    3)  Typically, the netfile will have the following components connected to each other:

    The "File Selector" boxes specify which .dx files the program will read.  To change these, double click on them to open a control panel.   To the left of the filename, in the green box, click on the "...".  This will open a new window in which the new filenames can be browsed for and selected.  The filename can also be changed in the green box itself by typing into it and hitting Enter on the keyboard.

    The "Import" boxes read the files selected in the "File Selector" boxes into the program.

    The "Tube" boxes increase the diameter of the lines in the file to make the surface look more smooth and continuous.  If one file is to be overlaid on another, the diameter of the file to go on top should be made larger than the diameter of the other file.

    The "Collect" boxes feed the input from multiple files (maps of the left and right, for example) into the same path.

    The "Colormap" boxes determine how the values that come into the program will be translated to color.   If the image appears to have large holes the minimum value of the data might be lower than the minimum value assigned a color, or the maximum of the data might be higher than the maximum value assigned a color.  To edit the Colormap, double click on the box.  To change to maximum value assigned a color, click in the gray box just to the right of the bar, type in the new value, and hit "Enter" on the keyboard (this is how the threshold of the p-value shown on the map can be changed).  The minimum value assigned a color can be changed in the gray box below the bar.  To change the range of colors used, change the slope of the lines in the "Hue" box.  For a step-like appearance, control points can be added by going to the "Edit" menu and selecting "Add Control Points" and providing values.  The "Constrain Horizontal" option from the Edit menu can be used to keep the values consistent while the colors are changed.  For a more gradual transition between colors, change the slope of the line without adding control points.

    The "Color" boxes apply the colors selected using the Colormap menu to the data.

    The "ColorBar" boxes display the color bar used by the Colormap as part of the output images.  The color of the text use can be changed by clicking on the "Expand" button at the bottom of the box, then scrolling down the list of inputs to "colors" and typing the new color's name in the box at the right across from the "colors" option.  The size can be changed using the values that line up with the "shape" option.

    The "Image" boxes display the final images.  To ensure that different maps match exactly in size and orientation, the Image boxes can be copied and pasted.  To change the background color of the image, go to the "Options" menu on the Image window and select "Set Background Color".  Type the new color name into the box and hit Enter.  To change the orientation of the image, select "View Control" under the options menu.  Select the name of the view from the "Set View" box.  In some cases, the "Front" view will actually be the top of the brain and vice versa.  To move the brain, select "Roam" from the "Mode" box.  A small dot will appear in the center of the image.  Click on this dot and move it to move the center of the brain.

    4.  To run the netfile, go the "Execute" menu and select "Execute Once".  If changes are made to the input files or colormaps, the program will need to be executed again.  If lines appear or the output does not change when the input has changed, go to the "Connections" menu and select "Reset Server".  Execute the program again.

    5.  To save the netfile, go to "File" menu and select "Save Program As".  Give it a path and name and click "OK".

    6.  To quit out of Data Explorer, select "Quit" under the "File" menu.  The netfile will disappear, but Data Explorer will keep running.  Go to the small "Data Explorer" window and click "Quit".



    Averaging 4 Dimensional UCFs

    Averages of value in the 4th position in a set of UCFs can be calculated.  The average ucf can then be read into a netfile in which the color on the maps represents the average value of the fourth dimension at each surface point.

    1)  Averages should be computed using ucfs 4 dimensional ucfs without an assigned covariate. It is most convenient if these files are copied to separate directories for each group.  The script move_files_to_groups.csh can be modified to copy over the desired files.  It creates a new directory named according to the groups that will be compared.  It makes a directory for each group and, under that, a directory for each type of files copied over.  It it set to copy gray matter distribution maps, dfz maps, surface asymmetry maps, and gray matter asymmetry ratio maps without covariates for all subjects, but this can be modified to fit a new data set's needs.  Changes will need to be made to the names of the groups being compared, the directories in which their information lives, and the subject numbers for each group.

    2)  The script avg.csh is an example script containing the command for averaging 4 dimensional ucfs.   The averages are computed and converted from ucf files to dx files.  The average of the fourth dimension (in this case gray matter density) is plotted on the average surface.  The group names must be changed to reflect the actual groups being compared.  The paths must also be changed to match the measure being analyzed.

    3)  Results can be viewed using Data Explorer. The netfile average_surf_asym.net is an example netfile that can be modified to fit the project.   The .dx files created by the script must be chosen using the "File Selector" buttons, with the right and left averages for one group going into the first 2 File Selectors and the right and left averages for the other group going into the second pair of File Selectors.  The Colormaps can be modified to reflect the correct range of data.



    Increase and Percent Change Maps

    Increase and percent change maps can be used to show the magnitude of differences between two groups.  In general, it is most meaningful to show differences in dfz as an increase in millimeters and differences in gray matter as a percent change.

    1)  The script increase_dfz_map.csh will compute the difference in millimeters between the average distance from zero in one group and the average distance from zero in the other group at each surface point.  The averages for each group are computed and then increases are calculated.

    2)  Results can be viewed using Data Explorer.  The netfile inc_dfz.net is an example netfile that can be modified to fit the project.  The files must be selected using the "File Selector" buttons and the colormap must be modified to reflect the range of the data.  In these maps, the color corresponds to the difference in millimeters between the average DFZ of one group and the average DFZ of the other group.

    3)  The script percent_change_gray.csh will compute the percent difference in gray matter between two groups.  The average gray matter maps for each group are made, the ratio of gray matter in one group to the other is taken, and that ratio is converted into a percentage of change.

    4)  Percent changes in gray matter can be viewed using Data Explorer.  The netfile per_gray.net is an example netfile that can be modified to fit the project.   The .dx files must be selected and colormap edited.  In these maps, the color corresponds to the percent difference in gray matter between one group and the other.



    Assigning Covariates

    The variable under investigation (age, gender, diagnosis, etc.) must be put into the header of each ucf file as a covariate if correlation or multiple regression analyses are to be run.

    1)  The script assign_covar.csh is an example script that assigns covariates.  The subject numbers with the same covariate (age, diagnosis, etc.) are put into the parentheses after the "foreach x".  The value (age, diagnosis 0 or 1) should be entered twice to the right of the "'s/200.000000 200.000000/".  The name of the input file should go next, with a "{$x}" replacing the subject number.  An output name, usually with an "a" if the covariate is age, a "g" for group or an "s" for sex, should follow the ">".

    2)  For multiple regression, values of both variables will need to be entered into the header as separate lines.  See Multiple Regression for details.



    Correlation Maps

    Code exists to compute the correlation coefficient (Pearson's r-value) and corresponding p-values.  In order for this code to work properly, the variable under study must be entered into the header as a covariate.  See Assigning Covariates above for details.

    1)  The script correlation.csh is an example script that uses the code that make r and p maps.  The end of the script converts the resulting ucfs to .dx format.  The directory path must be changed, as well as the filenames that follow the commands.  Directly following the command ("$RMAP" for example) there should be a list of the files with the covariates assigned for each hemisphere.  Multiple paths can be entered here if subjects are in different directories sorted by group, as long as the combined paths list the files to be studied.  The names of the output files should be changed as well.

    2)  As the commands are run, the script will output the number of subjects being analyzed.  If this number is different from the expected number of subjects, stop the script and fix the paths and filenames so that all, and only, the correct files are being fed into the command.

    3)  The output files can be entered into a netfile.  An example is correlation.net. The output of this netfile will be a map of r-values overlaid with p-maps thresholded at .05.  P-values below .05 that correspond to a positive R-value (the measure increases significantly with an increase in the variable under study) will be shown in white and p-values below .05 that correspond to a negative r-value (the measure decreases significantly with an increase in the variable under study) will be shown in red.  The location and name of the r-maps (left and right) should go into the first two File Selectors, the positive p-maps (left and right) should go into the middle two File Selectors, and the negative p-maps (left and right) should go into the last two file selectors.  To change the threshold of p-values shown, double click on each of the colormaps attached to the p-maps.  Change the upper limit from 0.05 to the new value and hit Enter.



    One Sample T-Tests

    When the null hypothesis for a test is that the mean of the measure is known, a one sample T-test can be used.  The one sample T-test compares the actual values to the hypothesized value.  This test is used to analyze statistical significance of asymmetry; if no gray matter asymmetry existed, for example, the ratio of gray matter on the left to gray matter on the right would be 1.  The test can also used to assess whether the rate of change in DFZ or gray matter density is different from 0 in longitudinal analyses.

    1)  The one-sample t-test code is set up to compare the actual mean to 0.  If the null hypothesis is different from 0, as it is with gray matter asymmetry, the values will have to be corrected so that the null hypothesis is 0;  since the null hypothesis for gray matter asymmetry is 1, 1 can be subtracted from each gray matter ratio to make a data set for which the null hypothesis is 0.  The script subtract_to_make_null_0.csh will do this.  Change paths and filenames, point to an average ucf in line 5, and insert the number that should be subtracted from each map in line 11.

    2)  Run the script one_sample_ttest.csh to get T-maps and positive and negative p-maps.

    3)  The p-maps can be read into one_sample_t_pvalue.net to display the p-value at each point.  Multiple color maps were used so that p-values could be entered more precisely, but the same positive and negative p-maps are fed into each set of File Selectors.  The colors corresponding to each p-value can be modified by opening the Colormap windows and moving the control points.



    Paired T-Tests

    When there are two observations for each subject, a paired t-test should be used.  This test is used to look for asymmetry by comparing a measure (gray matter density or y-coordinate) in one hemisphere to the other.

    1)  The script paired_t.csh compares the two observations for each subject and outputs a T-map and positive and negative p-maps.  It is important that the order of subjects for the first measure matches the order of subjects for the second measure since pairing is done according to the list order.  The code expects input in the form a1 b1 c1...a2 b2 c2, where a1 and a2 are the two observations for the same subject.  Use the ls command to check that the pairing will turn out correctly before running the script.

    2)  The resulting .dx files can be read into a file like correlation.net. The T-maps should be read into the left two File Selectors, the positive p-maps into the middle two, and the negative p-maps into the right two.  The left Colormap will have to be changed to reflect the range of T-values.  The other two Colormaps can be modified to change the p-value displayed.



    Non-Linear Statistics

    Sometimes effects are not linear.  For example, the brain is changing at different rates at different ages.  To assess the effect of the square of a variable (like age), non-linear statistics are used.

    1)  The script nonlin_stats.csh can be modified to fit the project.  The output will be maps of the slope and positive and negative p-values showing the significance of non-linear effects.

    2)  The .dx files created can shown using nonlin_stats.net.  The "slope2" files for the left and right hemispheres should be read into the left two File Selectors, the "pos2" files should be read into the middle two File Selectors, and the "neg2" should be read into the right two File Selectors.   The colorbar into which the slope feeds may have to be changed to fit the range of data, and the p-value of the probabilities overlaid in red and white can be adjusted using the other colorbars.



    Multiple Regression

    When the effect of one variable on a measure depends on the value of another variable, an interaction can be observed.  For example, the difference between control and patient populations may differ depending on the sex of subjects.  To assess the significance of the interaction, and to assess the effects of each variable independent of the other, multiple regression analysis can be done.

    1)  The two variables must be inserted into the header of each subject in separate lines.  It is easiest to switch the top lines of the file into which one variable has been assigned with a few lines from other files in which the possible values of the second variable have been entered.  The last line of the file example_header.txt can be changed to each value of the second variable (like 1 and 0) and saved as separate versions (like male and female).  The script assign_gender_and_age_covariates.csh can be modified to switch this header with the first lines of a file into which another variable has already been assigned.

    2)  The script mult_reg_stats.csh can be modified to match the project.  The output of the script will be a total of 10 files per hemisphere per measure assessed.  The R-squared map shows the overall amount of variance predicted using the two variables.  The slope1, ppos1, and pneg1 maps show the effects of the first variable independent of the second.  The slope2, ppos2,  and pneg2 maps show the effects of the second variable independent of the first.  The slopeint, pposint, and pnegint maps show the effects of the interaction.  Each of these sets of maps can be read into a netfile like correlations.net. The first two File Selectors hold the slope maps for each variable, the second two hold the positive p maps, and the last two hold the negative p maps.  The colorbar on the slope maps might have to be adjusted with each set of maps.



    Creating ROIs from Statistical Maps

    An ROI can be created from a statistical map.  This ROI can then be used in permutations or used as a label to define an area in which to sample gray matter.

    1)  The ucf of the statistical map must be turned into a minc and thresholded to so that it contains ones at voxels with values lower than a specific p-value and zeroes at all other voxels.  The script ucf_to_minc.csh will do this.  The p-map to be used must be specified between the parentheses after "foreach x".  The threshold can be specified at the top of the script.  If the label is to be used as a mask in which to sample gray matter, it is usually best to pick a lower threshold to reduce the amount of noise.

    2)  The minc created by step 1 includes voxels in all areas of the brain with values below the threshold.  If there is a particular blob of significance or region that the test is supposed to focus on, it can be selected by masking that region in Display.  Display the minc created in step 1 and a representative object in matching space.  Color code the object using "D" then "A".  Use the "Fill 3-D" command (F then 6) to fill in the areas that fall within the area the test is supposed to focus on.  The new label, containing only areas of significance in the desired region, should be saved using "T" then "W".

    3)  Since the ROI created in step 2 is just a shell, it will not necessarily fall onto each individual's surface.  To make sure that it does, it should be thickened in the direction parallel to the surface on which it falls; if it is on the lateral surface of the brain it should be blurred in the left-right direction (x), if is on the top surface of the brain it should be blurred in the top-bottom direction (z), and if it is on the front surface of the brain it should be blurred in the front-back direction (y).  The ROI will also be blurred by one standard deviation to combine any isolated areas of significance into unified blobs.  The script blur_statisical_roi.csh is set up to blur a mask in the the left-right direction.  To blur in the up-down direction,  change the dimension in the reorient command in line 22 to yz and the dimension in the reorient command in line 45 to zy.  To blur in the front-back direction, do not reorient  (remove those lines from the script).  The output of the script will be a minc with a filename starting with "final", which should be opened in Display to check that blurring was done properly.

    4)  If analysis was done in sulcal space or the label is to be used to sample gray matter, the ROI must be converted into each individual's sulcal space.  The script transform_statistical_roi.csh will output a label in each individual's sulcal space within which gray matter can be sampled.  It will also output an average which can be used for permutations.



    Permutations

    Creating ROIs

    Because statistics performed on the surface involve over 65,000 tests, permutations must be done to correct for multiple comparisons.  To localize effects, Regions of Interest (ROIs) may be used.  The output of these permuations should be directed to the /tmp directory to minimize network traffic.  The completed log files can be copied into the project's directory.

    1)  ROIs must be created.  Masks of the lobes created for an average brain exist in /data/edevel/ATLAS and are called:

    icbm_atlas_avg_53_frontal_nooverlap_label.mnc.gz
    icbm_atlas_avg_53_occip_nooverlap_label.mnc.gz
    icbm_atlas_avg_53_parietal_nooverlap_label.mnc.gz
    icbm_atlas_avg_53_temp_nooverlap_label.mnc.gz

    These masks can be used as ROIs if analysis is done in 305 space.

    If analysis has been done in sulcal space, ROIs can be created by transforming the label from 305 space into each individual's sulcal space using xfms, then averaging the transformed masks.  The script transform_lobe_rois.csh will do this, and the output will be a volume of ones and zeros with ones representing any region into which any individual's transformed mask fell for each ROI.

    2)  There is overlap between these masks which must be given to only one ROI for permutations.  The text file subtract_lobe_overlap.txt illustrates how to use the mincmath commands to remove the overlap from a lobe.

    3)  For each ROI, a directory must be made with the label volume for that roi named roi.mnc in it.  The script set_up_permutations.csh can be modified to do this.  It assumes that the permutation scripts have been edited so a version exists for each hemisphere and analysis.  In the directories for each ROI will be the label for that region, named roi.mnc and a copy of the appropriate permutation script for each hemisphere.  These scripts can be run in the batch queue so that multiple versions can be run at the same time without slowing down the system.

    batch_q -q long perm_script.csh

    Correlations

    The script correlation_perm_script.csh will randomly re-assign the covariates assigned according to group membership 10,000 times, run the statistical test, and record whether or not the random assignment generated more voxels below the threshold than the assignment based on groups.  The code works on 10 thresholds simultaneously and separates the results into positive and negative effects.   The output is a very large .log file with a record of each trial and a summary at the end.  For each trial and threshold, a record like the one below is added into the .log file.

    ...........................................................
    AT THRESHOLD p less than: 0.100000 threshold of test
    Supra-threshold count[i] is - OVERALL: 9 number of significant voxels in trial (real experiment: 1987) number of significant voxels in original comparison
     Supra-threshold count[i] is - for POSITIVE EFFECTS: 9 (real experiment: 0)

    Supra-threshold count[i] is - for NEGATIVE EFFECTS: 0 (real experiment: 1987)

    Estimate of CORRECTED P at permutation 2: Overall p is less than 0.500000 estimate of what p-value will be based on this and previous permutations
    Estimate of CORRECTED P at permutation 2: POSITIVE EFFECT p is less than 1.000000
    Estimate of CORRECTED P at permutation 2: NEGATIVE EFFECT p is less than 0.500000
    OVERALL SIGNIFICANT EFFECTS: 0 beat the real result, 1 didn't beat it...  tally of random trials compare to real result
    POSITIVE EFFECTS: 1 beat the real result, 0 didn't beat it...
    NEGATIVE EFFECTS: 0 beat the real result, 1 didn't beat it...
    ...........................................................

    4)  Because this file is so large that it is hard to open and work with, makeSHORT_log.csh should be used.  This script cuts out most of the information specific to each of the 10,000 trials but preserves the summary information.  At the end of this file, output like the following exists for each threshold and these are the p-values that should be reported:

    ----------------------------------------------------------------------------------------
    FINAL RESULTS AT THRESHOLD: p 0.050000

    FINAL CORRECTED P-VALUE, by permutation, is (OVERALL): 0.097100

    FINAL CORRECTED P-VALUE, by permutation, is (POSITIVE EFFECTS): 1.000000

    FINAL CORRECTED P-VALUE, by permutation, is (NEGATIVE EFFECTS): 0.050200
    --------------------------------------------------------------------------------------

    One Sample T-tests

    The script one_sample_perm_script.csh will randomly assign a sign (positive or negative) to the 4th dimension at each point for each subject,  re-compute the one sample t-test, and record whether or not the random assignment generated more voxels below the threshold than the actual data.  The script can be run in the batch queue so that the permutations for multiple ROIs can be run at once.

    Paired T-tests

    The script one_sample_perm_script.csh will assign the same random sign to the two observations, re-compute the paired t-test, and record whether or not the random assignment generated more voxels below the threshold than the actual data.  The code expects the pairs in a particular order - a1, b1, c1...a2, b2, c2  where a1 and a2 are the two observations for the same subject.   The script can be run in the batch queue so that the permutations for multiple ROIs can be run at once.


    Calculating Volumes from Segmented Images

    Volumes of the amount of gray matter, white matter, CSF, and background that were defined as brain tissue during masking can be obtained for each subject.  Volume data can be compared across groups or ages in Systat.

    1)  The script classify_final_volumes.csh will use the rf-corrected segmented volume and the final brain mask to calculate the volume of each tissue type within the brain of each subject.  The output of the script will be a .txt file like /loni/edevel/bin/STATS/final_classified_volume_L002.txt for each subject, showing the number of voxels within the mask that were classified as each tissue type.

    2)  The txt files for all subjects must be opened and turned into a single table in which each row represents a subject and each column represents a tissue type.  This file can then be converted and used in Systat.



    Viewing Data in Systat

    It can be helpful to pull a line of information from a ucf into Systat to make graphs or run simple statistics.  Since anatomy is matched based on levels, whatever line is pulled out of each individual's UCF should be an anatomically analogous point to that same line in all other subjects.  It is possible to search a UCF for coordinates or for values.

    1)  To find a line that falls within a significant blob on the brain, open the p-value map in nedit.  Use the search function or scroll down to find a value in the 4th dimension that is lower than the threshold.  Record the line number at which the value occurs.  In the script get_line_of_info.csh, replace the text "LINE NUMBER" with the number.  Change the script to reflect the type of measure being analyzed (gray matter, DFZ, etc.).  The end result will be a file with the information from each subject's line as a row , the first column as the x-coordinate, the second column the y-coordinate, the third the z-coordinate, and the fourth the value of the fouth dimension (gray matter, DFZ, etc.) at that point.

    2)  Pulling out coordinates near the center point of each sulcal line can give a general idea about trends all over the brain.  The coordinates at the center of each line can be determined by opening the SHORTvar files for each line (in EXAMPLE_PROJECT/OBJS/VAR) and finding the center line.  The average surface UCF can be searched to find these coordinates.  A script, get_gray_dfz_asym_at_all_lateral_lines.csh, is set up to find the center of lines based on the coordinates from the YALE 176 group and merge these lines into one file which will have a row for each subject and a column for each x, y, and z-coordinate and 4th dimension for each line.

    3)  The text file should be transferred from the UNIX side to a machine that runs both Excel and Systat.  Open Excel and choose "Open" from the File menu.  Select "Text Files" from the drop menu after "Files of Type" and the bottom of the window, click on the file, and hit open.  A "Text Import Wizard" box should pop up.  Click Next.  On the second window (with "Step 2 of 3" at the top) should be a list of options with boxes next to them under the heading "Delimiters".  Be sure the boxes next to "Tab" and "Space" are both checked and hit "Finish".  Add a row and label the columns.

    4)  Open the file in Systat.  Open Systat, go to File, then Open, then Data.  Next to "Files of Type", select "Microsoft Excel (*.xls)".  Find the file and click open.  Save the file as a Systat file.

    5)  To merge the file with other information, like demographics, sort both files by the variable they have in common, like blind number, and make sure the variable has the same name in both files.  To sort, go to the Data menu and select "Sort".  Select the variable from the box on the left, hit the Add button (which should make the variable name appear in the box on the right), and select "Okay".  Save the file.  To rename a variable, double click on the variable name and type the new name in the top box.  When both files have been sorted, merge by selecting "Merge" from the Data menu.  Hit the top browse button and select the demographics file.  Hit the lower browse button and select the new data file.  Press the "Key Variables" box in the lower right corner, select the variables the files have in common, hit add, hit okay in that window, and hit okay in the other window.  The output of the step should be a new file with a row for each subject which has both demographic information and the information from the UCFs.

    6)  To make graphs, select Scatterplot from the Graph menu.  Select the variable that should go on the x-axis and hit the top add to put it in the top box. Select the variable that should go on the y-axis and hit the second add to put it in the second box.  To add a trend line, hit the "Options" button at the bottom, select "Smoother" and select either "Linear" or "Quadratic".  The graph will appear in the output window.  Double clicking on it will enlarge it and allow changes to be made.

    7)  To calculate correlations, select Statistics, then Correlations, then Simple.  Select the variables to be correlated (multiple variables can be selected using the Control button) and hit add to put them in the top right box.  To get the p-values associated with the correlation, hit the "Options" button, check the box next to Probabilities, and select "Uncorrected".

    8)  To perform operations using the variables (like subtract one variable from another), select Data, then Transform, the Let.  Name a new variable in the bottom left box.  Use the lists and arrow keys to select the variables and operations to define it.