Home > utility > feSegmentFascicleFromConnectome.m

feSegmentFascicleFromConnectome

PURPOSE ^

Segment a fascicle from a connectome by applying a series of 'AND' and

SYNOPSIS ^

function [fg, keepFG] = feSegmentFascicleFromConnectome(fg, rois, operation, fascicleFileName)

DESCRIPTION ^

 Segment a fascicle from a connectome by applying a series of 'AND' and
 'NOT' operations between the connectome and a set of ROIs.

 The important aspect of this function is that it returns both the new
 fiber group AND the indices in the origianl fiber group of the fibers
 that passed all the 'and' and 'not' operations requested.

 These idices can be used to address the columns of a LiFE model (M
 matrix). This allows for subtracting entire fiber group dfined
 anatomically from a pre-existing connectome. In turns this allows for
 testing hypotheses on the improtance of an (anatomically selected)
 fascicle within the volume of white-mater comprised by the connectome.

 [fg fibersIndices] = feSegmentFascicleFromConnectome(fg, rois, operation, fascicleFileName)

 INPUTS:
   fg           - A connectome (e.g., fg = feGet(fe,'fibers acpc'))
   rois         - A cell array of rois to be used for selecting the fibers in the
                  final fascicle
   operation    - A set of logical operations to be applied to the fibers in
                 the connectome in relation to the rois. There should be one
                 operation per roi. 
   fascicleName - The name of the final fascicle. 


 OUTPUTS:
  fg            - The segmented fiber group, containing only the fibers
                  that passed all the logical operations.
  keepFG        - A vector of indices (0's and 1's) of the length of the
                  number of fibers in the input fiber group. A one
                  indicates that the fiber survived all the logical
                  operations requested. A 0 indicates that the fibers did
                  not survive some of the logical operations and it was
                  deleted from the output fiber group.

 Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fg, keepFG] = feSegmentFascicleFromConnectome(fg, rois, operation, fascicleFileName)
0002 % Segment a fascicle from a connectome by applying a series of 'AND' and
0003 % 'NOT' operations between the connectome and a set of ROIs.
0004 %
0005 % The important aspect of this function is that it returns both the new
0006 % fiber group AND the indices in the origianl fiber group of the fibers
0007 % that passed all the 'and' and 'not' operations requested.
0008 %
0009 % These idices can be used to address the columns of a LiFE model (M
0010 % matrix). This allows for subtracting entire fiber group dfined
0011 % anatomically from a pre-existing connectome. In turns this allows for
0012 % testing hypotheses on the improtance of an (anatomically selected)
0013 % fascicle within the volume of white-mater comprised by the connectome.
0014 %
0015 % [fg fibersIndices] = feSegmentFascicleFromConnectome(fg, rois, operation, fascicleFileName)
0016 %
0017 % INPUTS:
0018 %   fg           - A connectome (e.g., fg = feGet(fe,'fibers acpc'))
0019 %   rois         - A cell array of rois to be used for selecting the fibers in the
0020 %                  final fascicle
0021 %   operation    - A set of logical operations to be applied to the fibers in
0022 %                 the connectome in relation to the rois. There should be one
0023 %                 operation per roi.
0024 %   fascicleName - The name of the final fascicle.
0025 %
0026 %
0027 % OUTPUTS:
0028 %  fg            - The segmented fiber group, containing only the fibers
0029 %                  that passed all the logical operations.
0030 %  keepFG        - A vector of indices (0's and 1's) of the length of the
0031 %                  number of fibers in the input fiber group. A one
0032 %                  indicates that the fiber survived all the logical
0033 %                  operations requested. A 0 indicates that the fibers did
0034 %                  not survive some of the logical operations and it was
0035 %                  deleted from the output fiber group.
0036 %
0037 % Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.
0038 
0039 % Make sure that the inputs have one logical operation per ROI
0040 if ~(length(rois) == length(operation))
0041   error('[%s] Please provide one logical operand (e.g., ''and'', ''not'') for each ROI...',mfilename)
0042 end
0043 
0044 % Read fibers, if a path was passed
0045 if ~isstruct(fg)
0046   fg = fgRead(fg);
0047 end
0048 
0049 % The following is the vector containing the indices
0050 % to the fibers we KEEP from the origianl fiber group
0051 % after all the logical operations are applied.
0052 keepFG = false(length(fg.fibers),1); 
0053 
0054 % The following is a cell array which will old the relative indices of the
0055 % fibers into each sized-down version of the fibers.
0056 % Each entry of the cell arry holds the indices to the fibergroup in the
0057 % before the current operation was applied.
0058 currentFibIndices = cell(length(rois)+1,1);    
0059 currentFibIndices{1} = 1:length(keepFG);
0060 
0061 for ir = 1:length(rois)
0062   % Read the rois from disk if paths were passed in
0063   if ~isstruct(rois{ir})
0064     rois{ir} = dtiReadRoi(rois{ir});
0065   end
0066   
0067   % Intersect the wholebrain fiber group with "AND" / "NOT" ROIs
0068   [fg, ~, keep]  = dtiIntersectFibersWithRoi([],operation{ir},[],rois{ir},fg);
0069   
0070   % Select the indices fo the fibers that were deleted in the previous
0071   % loop. The way we address these indices depends on the type of operation.
0072   % For 'and' we simply use the idices in keep{ir-1}
0073   % For 'not' we need to flip the sign and use the indices in kee{ir-1}
0074   % that were se to 0.
0075   %
0076   % See help dtiIntersectFibersWithRoi.m
0077   % "The output variables keep and keepID vectors for "not" option are
0078   % counterintuitive: they mark fibers that DO intersect the ROI and that are
0079   % exluded from the output FG."
0080   switch operation{ir}
0081     case {'and','AND','and both endpoints','endpoints'}
0082       currentFibIndices{ir+1} = currentFibIndices{ir}(keep);
0083     case {'not','NOT'}
0084       currentFibIndices{ir+1} = currentFibIndices{ir}(~keep);
0085     otherwise
0086       keyboard
0087   end
0088   clear keep
0089 end
0090 
0091 % Save the indices of the fibers that survived all the operations.
0092 keepFG( currentFibIndices{end} ) = true;
0093 
0094 % Clean up the rest of the fields in the fiber group.
0095 % dtiIntersectFibersWithRoi.m does not handle other fields but the .fiber
0096 % one.
0097 fg.pathwayInfo = [];
0098 fg.seeds       = [];
0099 fg.Q           = [];
0100 fg.params      = [];
0101 
0102 % Change the fibergroup name
0103 if isstruct(fascicleFileName)
0104     fg.name = fascicleFileName.name;
0105 else
0106     fg.name = fascicleFileName;
0107 end
0108 return

Generated on Wed 02-Jul-2014 17:17:39 by m2html © 2005