If two or more aa modules perform similar operations, we want to minimize redundant code by sharing the matlab and XML code between them. For example, aamod_norm_write and aamod_norm_write_cons both perform the same operation (applying normalisation parameters to warp images), but on different data (the epi stream in the first case, and the firstlevel_cons stream in the latter case). Rather than creating a unique .m file for each module and duplicating matlab code, we can create a general purpose .m function that is shared by both modules. Each module still requires it’s own unique .xml file, but we can specify which .m file goes with each module by using the ‘mfile_alias’ feature. We can also inherit settings (and their default values) from other modules using the ‘inheritfrom’ feature. We will illustrate the use of these features using the aamod_norm_write module.
First, we created the files aamod_norm_write.m and aamod_norm_write.xml. Together, these two files comprise the aa module that applies normalisation parameters to the epi stream. The .xml for this module looks like this:
<?xml version="1.0" encoding="utf-8"?> <aap> <tasklist> <currenttask domain='session' desc='apply normalisation to EPIs' modality='MRI'> <vox desc='voxel size of normalised images'>2 2 2</vox> <inputstreams> <stream>normalisation_seg_sn</stream> <stream>structural</stream> <stream>epi</stream> </inputstreams> <outputstreams> <stream>epi</stream> </outputstreams> </currenttask> </tasklist> </aap>
Creating the ‘aamod_norm_write_cons’ module is simplified by re-using aamod_norm_write.m (rather than creating aamod_norm_write_cons.m). We can tell aa to use the aamod_norm_write.m for our new module by adding the mfile_alias=’aamod_norm_write’ option to the aamod_norm_write_cons.xml specification (see below).
We also want aamod_norm_write_cons to share settings with aamod_norm_write, so that both modules re-sample the data (i.e., EPI volumes and contrast images) to the same voxel size. We can use the ‘inheritfrom’ option to tell aa that aamod_norm_write_cons.xml should automatically include all the same settings (and their default values) as aamod_norm_write, and then we only have to specify any new or different settings.
Here is aamod_norm_write_cons.xml:
<?xml version="1.0" encoding="utf-8"?> <aap> <tasklist> <currenttask domain='subject' mfile_alias='aamod_norm_write' inheritfrom='aamod_norm_write' desc='normalise contrast images' modality='MRI'> <inputstreams> <stream>normalisation_seg_sn</stream> <stream>firstlevel_cons</stream> </inputstreams> <outputstreams> <stream>firstlevel_cons</stream> </outputstreams> </currenttask> </tasklist> </aap>
As you can see, aamod_norm_write_cons.xml does not include a voxel size setting (<vox>). However, it inherits this setting (and any other settings and their default values) from aamod_norm_write.xml. The only difference between these two modules are the input and output streams (epi vs firstlevel_cons). It is also worth noting that modules can inherit settings from modules that inherit from other modules (and so on).
For other examples of module inheritance, see aamod_GLMdenoise.xml and aamod_GLMdenoise_noEPI.xml, which inherit from aamod_firstlevel_model.