sortByModule

PURPOSE ^

SORTBYMODULE sort all types of nodes in order of modules.

SYNOPSIS ^

function [ network ] = sortByModule( network )

DESCRIPTION ^

 SORTBYMODULE sort all types of nodes in order of modules.

   [ network ] = sortByModule( network )
   This function will find community structures of all nodes, and arrange
   each type of nodes in order of its module. Finally nodes will be arraged
   by its type (input, output, inter) and its module id.

   Input:
       network: a network structure contain input & output nodes information.

   Output:
       network: a network structure sorted in order of modules.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ network ] = sortByModule( network )
0002 % SORTBYMODULE sort all types of nodes in order of modules.
0003 %
0004 %   [ network ] = sortByModule( network )
0005 %   This function will find community structures of all nodes, and arrange
0006 %   each type of nodes in order of its module. Finally nodes will be arraged
0007 %   by its type (input, output, inter) and its module id.
0008 %
0009 %   Input:
0010 %       network: a network structure contain input & output nodes information.
0011 %
0012 %   Output:
0013 %       network: a network structure sorted in order of modules.
0014 
0015 %   ---------
0016 %   Yen-Nan Lin, NTHU, 2010-2014, Matlab 2012a
0017 
0018 FIELD_NAME_MODULE_ID = 'moduleId';
0019 
0020 % find community structure by brain connectivity toolbox
0021 moduleIdEachNode = modularity_dir(full(network.matrix));
0022 
0023 inputIx = findList(network.label, network.inputList);
0024 outputIx = findList(network.label, network.outputList);
0025 interList = setdiff(network.label, [network.inputList, network.outputList]);
0026 interIx = findList(network.label, interList);
0027 % rearrage index by modules
0028 [sortInputModuleId, sortInputIx] = sort(moduleIdEachNode(inputIx), 'ascend');
0029 [sortOutputModuleId, sortOutputIx] = sort(moduleIdEachNode(outputIx), 'ascend');
0030 [sortInterModuleId, sortInterIx] = sort(moduleIdEachNode(interIx), 'ascend');
0031 sortAllIx = [inputIx(sortInputIx), outputIx(sortOutputIx), ...
0032     interIx(sortInterIx)];
0033 sortAllModuleId = ([sortInputModuleId; sortOutputModuleId; sortInterModuleId]');
0034 
0035 network.label = network.label(sortAllIx);
0036 network.matrix = network.matrix(sortAllIx, sortAllIx);
0037 network = setfield(network, FIELD_NAME_MODULE_ID, sortAllModuleId);
0038 end
0039 
0040 function [ indexList ] = findList( array, wantedList )
0041 indexList = [];
0042 nEntry = numel(array);
0043 for iEntry = 1:nEntry
0044     if ~isempty(find(wantedList == array(iEntry), 1))
0045         indexList = [indexList, iEntry];
0046     end
0047 end
0048 end

Generated on Thu 30-Jan-2014 00:00:07 by m2html © 2005