No BSD License  

Highlights from
CoCoMac

image thumbnail
from CoCoMac by James Allen
Download CoCoMac.org cortical connectivity data, model it as a network, and simulate epileptic sprea

gui.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Spreading Activation GUI %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Author: James Allen      %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Date: July 2006          %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all;

% Timestamp start of session in log file
fc_saveLog('########################################');
fc_saveLog(['Session started: ' datestr(now)]);

%----------------------------------------
% Initialisations

net = [];
netLabels = {};
activ = [];
data = [];
pajekDir = 'F:\pajek';
pajekGraphType = 'Fruchterman Reingold 3D';
movieMatrix = [];
fitLine = [];
fitLineLabel = [];
time_colour = [];
nodeCoords = [];
%----------------------------------------


%========================================
% Construct the gui window and elements
%========================================

fig_id = figure('MenuBar', 'none');
set(fig_id, 'Units', 'Normalized');
set(fig_id, 'Position', [0.01 0.2 0.98 0.8], 'DefaultUicontrolUnits', 'Normalized');


%======================
% MENUS
%=====================

menu_file = uimenu(fig_id, 'Label', 'File');

% Menu item 'Load data...' will load a specified mat file containing var
% 'data' (full data structure), run makeNet to construct connectivity
% matrix from data, plot the matrix as a circular graph on axes 'circular_
% plot_axes', return 'net' and 'netLabels' for further use by gui.
menu_file_loadNetwork = uimenu(menu_file, 'Label', 'Load network data...', 'Callback',...
    '[data, net, netLabels] = fc_loadData(list_startNodes); circularPositions = fc_afterLoad(fig_id, net, netLabels, activ_plot_axes, circular_plot_axes);');

% Menu item 'Download data...' - same as above but rather than load a .mat
% file, initiates download.m to download data from CoCoMac. 
menu_file_download = uimenu(menu_file, 'Label', 'Download network data...', 'Callback',...
    '[data, net, netLabels] = fc_download_data(list_startNodes); circularPositions = fc_afterLoad(fig_id, net, netLabels, activ_plot_axes, circular_plot_axes);');

% Load .net data
menu_pajek_load = uimenu(menu_file, 'Label', 'Load pajek .net file...',...
    'Callback', '[net, netLabels, nodeCoords] = fc_readPajek(); circularPositions = fc_afterLoad(fig_id, net, netLabels, activ_plot_axes, circular_plot_axes);');

% Save .net data
menu_save_pajek_dotNet = uimenu(menu_file, 'Label', 'Save as pajek .net...', 'Callback',...
    'fc_saveas_pajek(net,netLabels,nodeCoords);');


% For saving simulation data (activ, net, data, starNodes, removeNodes
menu_file_saveSimulation = uimenu(menu_file, 'Label', 'Save activation data...', 'Callback',...
    'fc_saveActiv(activ, activLabels, net, netLabels, data, get(list_sel_startNodes, ''string''), get(list_sel_removal, ''string''));');

% Loading simulation data
menu_file_loadSimulation = uimenu(menu_file, 'Label', 'Load activation data...', 'Callback',...
    '[activ activLabels net netLabels data circularPositions] = fc_loadActiv(fig_id, activ_plot_axes, circular_plot_axes, time_plot_axes);');

menu_file_exit = uimenu(menu_file, 'Label', 'Exit', 'Callback', 'delete(fig_id); close all; clear;');

menu_pajek = uimenu(fig_id, 'Label', 'Pajek');

% for setting directory that pajek.exe resides in
menu_pajek_setDir = uimenu(menu_pajek, 'Label', 'Set pajek dir...',...
    'Callback', 'pajekDir = uigetdir(''C:\'',''Select pajek directory'');');

% Call pajek to generate 3D plot
menu_pajek_plot = uimenu(menu_pajek, 'Label', 'Plot pajek...',...
    'Callback', 'pajekDir = fc_plotPajek(net, netLabels, pajekDir, pajekGraphType);');

% For setting the pajek graph type
menu_pajek_graphType = uimenu(menu_pajek, 'Label', 'Pajek graph type...',...
    'Callback', 'pajekGraphType = questdlg(''Select the graph type to plot using Pajek: '', ''Select Pajek plot type'', ''Kamada-Kawai'', ''Fruchterman Reingold 3D'', ''Fruchterman Reingold 3D'');');

menu_animation = uimenu(fig_id, 'Label', 'Animation');

% For saving animation
menu_animationSave = uimenu(menu_animation, 'Label', 'Save animation...',...
    'Callback', 'fc_saveAnimation(movieMatrix);');

menu_help = uimenu(fig_id, 'Label', 'Help');
%------------------------------------------

%======================
% CIRCULAR_PLOT_AXES
%======================
% create axes for the circular network plot
circular_plot_axes = axes('position', [0.02 0.54 0.3 0.4], 'visible', 'off');
%------------------------------------------


%======================
% TIME_PLOT_AXES
%======================

panel_time_plot = uipanel('position', [0.59 0.43 0.4 0.55], 'visible', 'off',...
    'backgroundColor', [0.8 0.8 0.8], 'tag', 'panel_time_plot');

time_plot_axes = axes('parent', panel_time_plot, 'position', [0.12 0.2 0.8 0.75]);

% Polyfit limits editbox and label:
fit_limit_label = uicontrol(fig_id, 'parent', panel_time_plot, 'style', 'text', 'string', 'Fitline x-axis range:',...
    'position', [0.5 0.02 0.4 0.06], 'backgroundColor', [0.8 0.8 0.8]);

fit_limit_editbox = uicontrol(fig_id, 'parent', panel_time_plot, 'style', 'edit', 'string', '3',...
    'position', [0.85 0.03 0.07 0.06], 'backgroundColor', [0.8 0.8 0.8],...
    'tag', 'fit_limit_editbox',...
    'callback', '[linearFit, fitLine, fitLineLabel] = fc_recalculate_fitLine(fitLine, fitLineLabel, time_plot, time_plot_axes, time_colour);');

% Hold Graph push button
button_hold_graph = uicontrol(fig_id, 'parent', panel_time_plot, 'style', 'toggle', 'position', [0.05 0.03 0.2 0.06],...
    'string', 'Hold graph', 'backgroundColor', [0.8 0.8 0.8],...
    'tag', 'button_hold_graph');

% Show Fit line push button
button_show_fitline = uicontrol(fig_id, 'parent', panel_time_plot, 'style', 'toggle', 'position', [0.27 0.03 0.2 0.06],...
    'string', 'Show fit line', 'backgroundColor', [0.8 0.8 0.8],...
    'tag', 'button_show_fitline', 'callback', 'fc_hide_fitline(fitLine, fitLineLabel)');
%------------------------------------------


%======================
% ACTIV_PLOT_AXES
%======================
% create axes for the activity spreading simulation
activ_plot_axes = axes('parent', fig_id, 'position', [0.63 0.07 0.3 0.3], 'visible', 'off', 'tag', 'activ_plot_axes');


%======================
% LIST BOXES
%======================

%------------------------------------------
% List boxes for selecting starting nodes (where activation spreading will start from)

% LIST BOX of possible start nodes
list_startNodes = uicontrol(fig_id, 'Style', 'Listbox', 'String', '',...
    'Max', 10, 'Min', 0, 'Position', [0.13 0.03 0.1 0.4], 'HandleVisibility', 'callback',...
    'tag', 'list_startNodes');

% LIST BOX of user-selected start nodes
list_sel_startNodes = uicontrol(fig_id, 'Style', 'Listbox', 'String', '',...
    'Max', 10, 'Min', 0, 'Position', [0.265 0.03 0.08 0.4], 'tag', 'list_sel_startNodes');
label_sel_startNodes = uicontrol(fig_id, 'Style', 'Text', 'String', 'Start node(s)',...
    'Position', [0.265 0.435 0.08 0.05], 'BackgroundColor', [0.8 0.8 0.8]);


% LIST BOX of nodes selected for removal
list_sel_removal = uicontrol(fig_id, 'Style', 'Listbox', 'String', '',...
    'Max', 10, 'Min', 0, 'Position', [0.01 0.03 0.08 0.4], 'tag', 'list_sel_removal');
label_sel_removal = uicontrol(fig_id, 'Style', 'Text', 'String', 'Node(s) for removal',...
    'Position', [0.01 0.435 0.08 0.05], 'BackgroundColor', [0.8 0.8 0.8]);

% BUTTONS for adding / removing start nodes / nodes for removal from main list to start /
% remove list boxes
button_add_startNode = uicontrol(fig_id, 'Style', 'pushbutton', 'String', 'Add',...
    'Callback', 'fc_add_to_listbox(list_sel_startNodes);',...
    'Position', [0.233 0.3 0.03 0.05]);
button_remove_startNode = uicontrol(fig_id, 'Style', 'pushbutton', 'String', 'Del.',...
    'Callback', 'fc_remove_from_listbox(list_sel_startNodes);',...
    'Position', [0.233 0.2 0.03 0.05]);
button_add_nodeRemoval = uicontrol(fig_id, 'Style', 'pushbutton', 'String', 'Add',...
    'Callback', 'fc_add_to_listbox(list_sel_removal);',...
    'Position', [0.095 0.3 0.03 0.05]);
button_remove_nodeRemoval = uicontrol(fig_id, 'Style', 'pushbutton', 'String', 'Del.',...
    'Callback', 'fc_remove_from_listbox(list_sel_removal);',...
    'Position', [0.095 0.2 0.03 0.05]);
%------------------------------------------


%======================
% SIMULATION PANEL
%======================

% Edit box and slider to allow user to select number of time steps
panel_simulation = uipanel('position', [0.38 0.03 0.2 0.2],...
    'backgroundColor', [0.8 0.8 0.8]);

% Start Simulation - push button
button_start_simulation = uicontrol(fig_id, 'parent', panel_simulation, 'style',...
    'pushbutton', 'position', [0.19 0.23 0.6 0.19], 'string', 'Start simulation', 'callback',...
    '[activ, activLabels, time_plot, linearFit, fitLine, fitLineLabel, time_colour] = fc_run_simulation(net, netLabels, time_plot_axes, activ_plot_axes, fitLine, fitLineLabel, time_colour);');

% Editbox for number of time steps
time_step_label = uicontrol(fig_id, 'parent', panel_simulation, 'style', 'text', 'string', 'No. of time steps',...
    'position', [0.01 0.74 0.66 0.15], 'backgroundColor', [0.8 0.8 0.8]);
time_step_editbox = uicontrol(fig_id, 'parent', panel_simulation, 'style', 'edit', 'string', '5',...
    'position', [0.7 0.74 0.17 0.18], 'backgroundColor', [0.8 0.8 0.8],...
    'tag', 'time_step_editbox',...
    'callback', 'fc_change_timesteps(get(time_step_editbox, ''string''));');

% Editbox for alpha value
alpha_label = uicontrol(fig_id, 'parent', panel_simulation, 'style', 'text', 'string', 'Alpha',...
    'position', [0.01 0.49 0.66 0.15], 'backgroundColor', [0.8 0.8 0.8]);
alpha_editbox = uicontrol(fig_id, 'parent', panel_simulation, 'style', 'edit', 'string', '',...
    'position', [0.62 0.49 0.32 0.18], 'backgroundColor', [0.8 0.8 0.8], 'tag', 'alpha_editbox');

% 'Please wait' label which can be turned on and off using 'visible' property, to be
% turned on while the simulation is running
label_simulation_working = uicontrol(fig_id, 'parent', panel_simulation, 'style', 'text', 'string', 'Working.....',...
    'position', [0.15 0.03 0.66 0.15], 'backgroundColor', [0.8 0.8 0.8], 'visible', 'off',...
    'tag', 'label_simulation_working');
%-------------------------------------------


%======================
% ANIMATION PANEL
%======================

panel_animation = uipanel('position', [0.38 0.25 0.2 0.23], 'visible', 'off',...
    'backgroundColor', [0.8 0.8 0.8], 'tag', 'panel_animation');

% Editbox for animation delay time period
animation_delay_editbox = uicontrol(fig_id, 'parent', panel_animation, 'style', 'edit',...
    'string', '500', 'position', [0.7 0.7 0.2 0.2], 'backgroundColor', [0.8 0.8 0.8],...
    'tag', 'animation_delay_editbox');
animation_delay_label = uicontrol(fig_id, 'parent', panel_animation, 'style', 'text', 'string', 'Animation delay (ms):',...
    'position', [0.01 0.7 0.66 0.15], 'backgroundColor', [0.8 0.8 0.8]);

% Animate simulation - push button
% NOTE: pressing animation button causes plot_coords to be re-calculated
% This is stored in GUI for later use by animation_frame_slider or
% animation_frame_editbox

button_animate = uicontrol(fig_id, 'parent', panel_animation, 'style', 'pushbutton', 'position', [0.19 0.5 0.6 0.15],...
    'string', 'Animate', 'callback', '[plot_coords movieMatrix] = fc_animate(activ, activLabels, netLabels, circularPositions, circular_plot_axes, str2num(get(findobj(''tag'', ''animation_delay_editbox''), ''string'')));');

% Editbox and slider for controlling current animation frame is displayed
animation_frame_label = uicontrol(fig_id, 'parent', panel_animation, 'style', 'text', 'string', 'Current frame:',...
    'position', [0.01 0.2 0.66 0.15], 'backgroundColor', [0.8 0.8 0.8], 'tag', 'animation_frame_label',...
    'visible', 'off');
animation_frame_editbox = uicontrol(fig_id, 'parent', panel_animation, 'style', 'edit',...
    'string', get(time_step_editbox, 'string'), 'position', [0.7 0.2 0.17 0.2], 'backgroundColor', [0.8 0.8 0.8],...
    'callback', 'fc_update_slider(activ, plot_coords, circular_plot_axes, activ_plot_axes);',...
    'tag', 'animation_frame_editbox', 'visible', 'off');
animation_slider = uicontrol(fig_id, 'parent', panel_animation, 'style', 'slider',...
    'min', 1, 'max', str2num(get(time_step_editbox, 'string')), 'sliderStep', [0.01 0.1],...
    'value', str2num(get(time_step_editbox, 'string')), 'position', [0.05 0.07 0.9 0.1], 'backgroundColor', [0.8 0.8 0.8], 'callback',...
    'fc_update_editbox(activ, plot_coords, circular_plot_axes, activ_plot_axes);',...
    'tag', 'animation_slider', 'visible', 'off');

Contact us at files@mathworks.com