AnyWave:MATLAB Batch GUI

From WikiMEG
Revision as of 16:30, 21 April 2020 by Bruno (Talk | contribs)

Jump to: navigation, search

Introduction

AnyWave can run plugin code using the command line as mentioned here:

That implies the user has to write his own shell scripts to accomplish that.
One alternative is to use the built-in Batch GUI in AnyWave that will allows to program your batch operations using a user friendly interface.
This features allows to run your batching operations within AnyWave, in the background with a monitoring of what it is done.
If we want our plugin to be processed using this feature we must make it compatible with AnyWave Batch GUI system.

Make my plugin GUI compatible

First, the plugin must be callable using the command line.
Reminder on how to do that:

args.json

Remember, we have defined an arg.json file to describe the command line arguments we would like AnyWave to parse for us:
Make your plugin batchable

ui.json

There are some important things to setup in ui.json file:
There is a key describing the input parameters of the plugin. Suppose that you want to compute something on several files, you must then set several input_keys in the json file.
This is done by creating the input_keys key.
This key will hold the names of all the other keys that must be considered as files that AnyWave will provide to our plugin when running it.
In our example below, there is only ONE file key, that we called input_file which is the default key name for the file argument.
Hence, AnyWave will bring a GUI to pick up all the files we want, and run our plugin on all those files.
Once you setup the FILES entries keys, you must also describe them in the file by setting two values to the corresponding key.
The first value is always the decorated readable name of the key that will be used to create the GUI.
The second value is a string. If you set "check" as the value, that will tell AnyWave to check that the file setup is a data file and not a side car file.
If you don't want a data file to be set, just set an empty string as the value.

Let's setup an example using one input file and two parameters:

{
"input_keys" : [ "input_file"],
"input_file" : ["Input File", "check"],
"hp" : ["High Pass Filter", "double"],
"lp" : ["Low Pass Filter", "double"],
"fields_ordering" : ["hp", "lp"]
}

input_keys : mandatory key. Here, we setup only one input file, and the key is called "input_file".
Then we must describe that key:

  • "Input File" is the name used in the GUI to describe the parameter.
  • "check" indicates that the file MUST be a data file that AnyWave can read.

fields_ordering: mandatory key. Describe the GUI fields order. Here we set up HP before LP in the GUI.

Between the mandatory keys, you have the other parameters:

  • hp described as High Pass Filter, and "double" indicates this parameter is a double value.
  • lp described as Low Pass Filter, and "double" indicates this parameter is a double value.

Others possible parameter values:

value description
"double" double precision value
"int" integer value
"list" indicates we want a combo list selection among predefined item.
"string" string value
"stringList" an array of strings.
"boolean" a boolean value.

default.json

This file comes to se the default values for parameters described in ui.json.
So you need to define the same keys and set a default value for them.
In our skeleton that will be:

{
"input_file" : "", 
"hp" : 0.,
"lp" : 0.
}

GUI representation of ui.json

See below the GUI representation of keys inserted in the ui.json:

key GUI
"hp" : ["High Pass", "double"] Json ui key double.png
"n_iter" : ["#Iterations", "int"] Json ui key int.png
"modality" : ["Modality", "list"] Json ui key list.png
"output_prefix" : ["Output Prefix", "string"] Json ui key string.png

Note: The list type will make a combobox list selection of items. Define the possible items in default.json file:
"modality" : ["MEG", "EEG", "SEEG"]

Example

A small test plugin that takes TWO files as input:

  • a MEG file
  • an EEG file

desc.txt

name = MAT_BATCH
description = TEST_BATCH
category = Process:TEST:MAT_BATCHING
flags = CanRunFromCommandLine:NoDataRequired

ui.json

{
"input_keys" : [ "meg_file", "eeg_file"],
"meg_file" : ["MEG File", "check"],
"eeg_file" : ["EEG File", "check"],
"output_file_prefix" : ["Output File Prefix", "string"],
 "fields_ordering": [ "output_file_prefix" ]
}

We set up two files as input (eeg_file, meg_file).
output_file_prefix is a string variable we will use to prefix our output filename.
There is only one field because meg_file and eeg_file are input files keys, so they won't appear in the left part of the GUI but in the input file part.

default.json

{
"meg_file" : "",
"eeg_file" : "",
"output_file_prefix" : "resampled"
}

main.m

function main(varargin)
global args;
if isdeployed
% STANDALONE AnyWave Plugin code
   global host;
   global port;
   global pid;
 
   if (nargin < 3)
       error('missing arguments.');
  end
  host = varargin{1};
  port = str2num(varargin{2});
  pid = str2num(varargin{3});
  if (nargin > 3)
    args = varargin{4};
  end
 
  assignin('base', 'host',  host);
  assignin('base', 'port', port);
  assignin('base', 'pid', pid);
  assignin('base', 'args', args);
% end of STANDALONE AnyWave Plugin code
end
 
% we assume here that the code will always run in batch mode.
% To check if the plugin was called in batch mode, just check if args variable is empty or not.
if isempty(args)
   error('this plugin will only run in batch mode');
end
 
 
pathMEG = args.meg_file;
pathEEG = args.eeg_file;
infosMEG = aw_getfileinfo(pathMEG);
if isempty(infosMEG)
    error('Could not open MEG file');
end
infosEEG = aw_getfileinfo(pathEEG);
if isempty(infosEEG)
   error('Could not open EEG file');
end
 
cfg=[];
cfg.file = pathEEG;
markersEEG = aw_getmarkers(cfg);
cfg.file = pathMEG;
cfg.channels = { 'Trigger' };
markersMEG = aw_gettriggers(cfg);
 
cfg = [];
cfg.file = pathEEG;
cfg.filtering = 'yes';
cfg.start = 0;
cfg.duration = -1;
cfg.eeg_lp = infosEEG.max_sr / 3;
 
eegdata = aw_getdata(cfg);
assert(~isempty(eegdata));
disp(eegdata);
end