Soy consciente de la ambivalencia de cogsci.stacexchange con respecto a hacer preguntas sobre el código, pero esta pregunta realmente es sobre SPM, específicamente, así que creo que la naturaleza específica del dominio de mi consulta la hace adecuada para este foro. Me disculpo si esto está en mala forma.
Estoy tratando de ejecutar un script por lotes personalizado en algunos datos de fMRI. El código correspondiente se presenta a continuación:
cfg = config(); % a struct that holds a few parameters, namely paths and regexps
for isub = 1:length(cfg.subdir)
subdir = cfg.subdir(isub);
rundirs = fullfile(subdir, regexpdir(subdir, cfg.regex.rundir));
matlabbatch{isub}.spm.spatial.realign.estwrite.data = regexpdir(fullfile(subdir), cfg.regex.funcscan);
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.quality = 1.0;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.sep = 4;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.rtm = 2;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.interp = 2;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.weight = '';
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.which = [0 1]; % [0 1] = create mean images only; [1 1] crt all imgs + mean
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.interp = 4; % 4th degree bspline interp
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.mask = 1;
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
end
Este bucle, que realiza la realineación de cortes para todos los sujetos, se llama a través de la secuencia de comandos spm_jobman('serial', 'myscript.m')
que myscript.m
se muestra arriba.
regexpdir
está disponible en el intercambio de archivos matlab para aquellos que deseen examinarlo, pero devuelve una matriz de cadenas de celdas Nx1, que corresponden a las rutas que coinciden con el parámetro regex.
Ejecutar este código no parece producir ningún error per se, sino que imprime lo siguiente varios miles de veces:
Item 'Session', field 'val': Value must be either empty, a cellstr or a cfg_dep object.
El nombre de la variable cfg_dep
me hace pensar en la construcción de "dependencia" de SPM, que a menudo se usa en la herramienta de lote visual. El código anterior está tomado de la función de exportación de código de dicha herramienta visual por lotes, por lo que es posible que esté haciendo referencia a una dependencia que de alguna manera se omitió cuando refactoricé el código exportado... pero maldita sea si puedo encontrar dónde...
¡Cualquier pensamiento o consejo sería muy apreciado!
A continuación se muestra una versión corregida del script. SPM parece ser bastante quisquilloso con la estructura de los datos que se pasan a matlabbatch{...}.spm.spatial.realign.estwrite.daat{...}
.
%%job_realign.m SPM batch module.
% SPM's spm_jobman function will eval this file, and automatically launch a
% batch job if the parameters are valid. Cryptic errors out of spm_jobman
% are usually an indication of a runtime error in batch modules.
%% Get configuration
cfg = config();
%% Get data
include = cfg.subdir(find(cfg.submask));
for isub = 1:length(include)
subdir = include{isub};
fprintf('In directory %s:\n', fileparts(subdir));
runs = regexpdir(subdir, cfg.regex.rundir, false)';
runs = [runs regexpdir(subdir, cfg.regex.locdir, false)'];
runs = [runs regexpdir(subdir, cfg.regex.retdir, false)'];
for irun=1:length(runs)
rundir = runs{irun};
scans = regexpdir(rundir, cfg.regex.funcscan, false);
fprintf('Scans: %d\n', size(scans, 1));
matlabbatch{isub}.spm.spatial.realign.estwrite.data{irun} = scans;
end
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.sep = 4;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.interp = 2;
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
matlabbatch{isub}.spm.spatial.realign.estwrite.eoptions.weight = {''};
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.which = [0 1]; % [0 1] creates mean image only; [1 1] creates all images + mean
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.interp = 4; % 4th degree B-Spline interpolation
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.mask = 1;
matlabbatch{isub}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
end
JAQuent