User Tools

Site Tools


neuroelf_gui_-_scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

neuroelf_gui_-_scripting [2011/02/28 23:59] (current)
jochen created
Line 1: Line 1:
 +====== NeuroElf - GUI Scripting ======
  
 +===== Motivation =====
 +While using the GUI manually (browsing maps, setting thresholds, etc.) is usually the first step in getting a feel for the data, sometimes it is yet convenient to create a set of images (screenshots,​ etc.) that all have the same properties, which then becomes a matter for scripting.
 +
 +NeuroElf thus offers the capability to control much of the behavior available via mouse clicks as function calls to the neuroelf_gui function.
 +
 +===== Requirements =====
 +In the presented case, a GLM file was manually opened, and a VMP file was pre-created containing the result of regression maps.
 +
 +===== Script =====
 +<code matlab negui_script_example.m>​% get global access to NeuroElf GUI config (ne_gcfg)
 +global ne_gcfg;
 +
 +% list of maps to cluster and show effects of
 +maps = [1, 2, 11, 12, 21, 22, 31, 32];
 +
 +% get handle to xff class
 +x = xff;
 +
 +% which file to use as underlay for display
 +try
 +    vmr = x('​colin_brain_ICBMnorm.vmr'​);​
 +catch
 +    vmr = neuroelf_file('​c',​ '​colin_brain_ICBMnorm.vmr'​);​
 +end
 +vmr.Browse;
 +
 +% load VMP
 +try
 +    vmp = x('​reappdevel_38subs_agesquared_correl.vmp'​);​
 +catch
 +    vmp = xff('/​Volumes/​reappdevel/​Imaging/​bv_analyses/​reappdevel_38subs_agesquared_correl.vmp'​);​
 +end
 +vmp.Browse;
 +
 +% open montage window
 +neuroelf_gui('​vismontage'​);​
 +drawnow;
 +
 +% options for montage images
 +miopt = struct( ...
 +    '​atrans', ​   false, ...
 +    '​atranscol',​ [0, 0, 0], ...
 +    '​blx', ​      [1, 1], ...
 +    '​brds', ​     0, ...
 +    '​drc', ​      1, ...
 +    '​drs', ​      256, ...
 +    '​filename', ​ '​./​X.png',​ ...
 +    '​flp', ​      ​false,​ ...
 +    '​flx', ​      ​false,​ ...
 +    '​frame', ​    [128, 128, 128; -127.99, -127.99, -127.9999], ...
 +    '​hFig', ​     xfigure('​Wnd_NeuroElf_vismontage'​),​ ...
 +    '​imeth', ​    '​linear',​ ...
 +    '​imetha', ​   '​linear',​ ...
 +    '​join', ​     true, ...
 +    '​ppv', ​      4, ...
 +    '​showinfig',​ false, ...
 +    '​slvar', ​    vmr, ...
 +    '​stalp', ​    1, ...
 +    '​stthr', ​    [0.1, 1.0], ...
 +    '​stvar', ​    vmp, ...
 +    '​stvix', ​    1, ...
 +    '​sws', ​      ​false,​ ...
 +    '​tpvol', ​    1);
 +
 +% get (Matlab UI) handle of all beta plot windows
 +cfigs = fieldnames(ne_gcfg.cc);​
 +bpfig = cfigs(~isemptycell(regexpi(cfigs,​ '​^BP'​)));​
 +bpglm = bpfig;
 +bpglmf = bpglm;
 +bpglmvb = bpglm;
 +for fc = 1:​numel(bpfig)
 +    bpglm{fc} = ne_gcfg.cc.(bpfig{fc}).Config.glm;​
 +    bpfig{fc} = ne_gcfg.cc.(bpfig{fc}).SatelliteMLH;​
 +    [glmpath, bpglmf{fc}] = fileparts(bpglm{fc}.FilenameOnDisk);​
 +end
 +bpfig = cat(1, bpfig{:});
 +
 +% set figure size(s)
 +set(bpfig, '​Position',​ [100, 100, 1024, 768]);
 +
 +% iterate over maps
 +for mc = 1:​numel(maps)
 +    ​
 +    % get map number and name
 +    mn = maps(mc);
 +    mnm = makelabel(vmp.Map(mn).Name);​
 +    ​
 +    % enable clustering thresholds and two-tailed test
 +    vmp.Map(mn).ClusterSize = 57;
 +    vmp.Map(mn).EnableClusterCheck = 1;
 +    vmp.Map(mn).ShowPositiveNegativeFlag = 3;
 +    ​
 +    % set as current map
 +    neuroelf_gui('​setcstatmap',​ mn);
 +    ​
 +    % enforce correct threshold
 +    neuroelf_gui('​setstatthrpval',​ 0.01);
 +    ​
 +    % create cluster table
 +    neuroelf_gui('​clustertable'​);​
 +    ​
 +    % continue if no clusters
 +    if isempty(ne_gcfg.voi.VOI)
 +        continue;
 +    end
 +    ​
 +    % set map in options for montage image
 +    drawnow;
 +    miopt.stvix = mn;
 +    miopt.stthr = [vmp.Map(mn).LowerThreshold,​ vmp.Map(mn).UpperThreshold];​
 +    ​
 +    % restrict clusters to 8mm spheres
 +    neuroelf_gui('​setcluster',​ '​set',​ 1:​numel(ne_gcfg.voi.VOI));​
 +    neuroelf_gui('​limitclusters',​ {8, '​s'​});​
 +    ​
 +    % get VOI object handle
 +    voi = ne_gcfg.voi;​
 +    ​
 +    % extract betas
 +    for fc = 1:​numel(bpglm)
 +        bpglmvb{fc} = bpglm{fc}.VOIBetas(voi);​
 +    end
 +    ​
 +    % iterate over clusters
 +    for cc = 2:​2:​numel(voi.VOI);​
 +        ​
 +        % get coordinate and text
 +        svoi = voi.VOI(cc);​
 +        svoic = svoi.Voxels(1,​ :);
 +        svoin = regexprep(svoi.Name,​ '​^.*_(.H_.*)$',​ '​$1'​);​
 +        svoin = regexprep(svoin,​ '​_sph.*$',​ ''​);​
 +        svoin = regexprep(svoin,​ '​_+$',​ ''​);​
 +        ​
 +        % build cluster name
 +        clname = sprintf('​%s%s_%d_%d_%d',​ mnm, svoin, svoic(1), svoic(2), svoic(3));
 +        ​
 +        % set cluster
 +        neuroelf_gui('​setcluster',​ '​set',​ cc);
 +        ​
 +        % draw and update
 +        pause(0.01);​
 +        drawnow;
 +        pause(0.01);​
 +        ​
 +        % handle barplots
 +        for fc = 1:​numel(bpfig)
 +            ​
 +            % get frame(s) from figure(s)
 +            bplot = getframe(bpfig(fc));​
 +            ​
 +            % save as PNGs
 +            imwrite(bplot.cdata,​ sprintf('​%s_%s_plot.png',​ bpglmf{fc}, clname));
 +            ​
 +            % save extract data as well
 +            vb = bpglmvb{fc}(:,​ [2, 4, 6], cc);
 +            save(sprintf('​%s_%s_extract.txt',​ bpglmf{fc}, clname), '​vb',​ '​-ascii'​);​
 +        end
 +        ​
 +        % create three panel views
 +        miopt.drc = 1; % SAG
 +        miopt.filename = sprintf('​%s_%s_SAG.png',​ bpglmf{fc}, clname);
 +        miopt.frame = [128, 128, 128; svoic(1), -127.99, -127.9999];
 +        neuroelf_gui('​vismontage_create_ex',​ miopt);
 +        miopt.drc = 2; % COR
 +        miopt.filename = sprintf('​%s_%s_COR.png',​ bpglmf{fc}, clname);
 +        miopt.frame = [128, 128, 128; -127.99, svoic(2), -127.9999];
 +        neuroelf_gui('​vismontage_create_ex',​ miopt);
 +        miopt.drc = 3; % TRA
 +        miopt.filename = sprintf('​%s_%s_TRA.png',​ bpglmf{fc}, clname);
 +        miopt.frame = [128, 128, 128; -127.99, -127.99, svoic(3)];
 +        neuroelf_gui('​vismontage_create_ex',​ miopt);
 +    end
 +end</​code>​
 +
 +===== Remarks =====
 +Many aspects of this script can still be adapted, such as the settings for the single-slice montage images, or the thresholding options. The usefulness of such a script is, of course, questionable,​ and without a doubt a more sophisticated script (e.g. one that re-loads images and combines them to a panel, etc.) could be devised. However, it is important to understand that this is meant as a starting point!
neuroelf_gui_-_scripting.txt ยท Last modified: 2011/02/28 23:59 by jochen