help > Contrast image filenames are inconsistent
Showing 1-7 of 7 posts
Display:
Results per page:
Jul 15, 2015  10:07 AM | Fleur Bouwer
Contrast image filenames are inconsistent
Dear Dr. McLaren,

I am using your toolbox to look at connectivity in a factorial design with many conditions (2x3x3) and everything seems to be working fine. However, the contrast images seem to get different names quite randomly. This is not necessarily disastrous, I could manually change names of the images that go into my 2nd level analysis, but having 18 participants and 18 conditions, it would be great if I don't have to go through that.

The problem is as follows:
I wrote a wrapper to loop over subjects and different seed regions. Something happens while looping over regions. For some subjects, all contrast images for all regions get a name that is specified as: ['con_PPI_' mycontrastname '_' subjectno]. For others, all images get the output I normally get from SPM, which is ['con_' contrastno]. And for most, the contrast images for the 1st seed region get the first version (with the contrast name in it), and the contrast images for the 2nd seed region get the second version (with only a number).

As I don't change anything inside the loop, the only thing I could think of that may be causing this is that some file gets overwritten. Indeed, there is 1 file that seems to have a generic name and gets overwritten with every next seed region ([subjectno '_PPIstructure.mat']). This file contains the P structure and is saved in whatever directory I start the analysis in. There is another file containing the P structure, which gets appended with the name of the seed region and the date and is saved in the SPM directory. The P structures in these files are identical, except for the last one gets an extra field "correct" added to it (value 1).

Somehow it is hard to understand how to fix this problem. I do not understand how overwriting the P file with the generic name could cause this, as the contrasts in all files are identical. Also, this does not really explain why it randomly changes for different participants. Maybe there's some other file that interferes?

Any ideas what could be the problem?

Thanks for your time!

Fleur
Jul 15, 2015  03:07 PM | Donald McLaren
RE: Contrast image filenames are inconsistent
Fleur,

It's hard to figure out what is going on without the structure files and the wrapper. However, I suspect the problem is that you are not getting separate PPI directories for each seed region. The structure file for each seed region should differ in the P.VOI and P.Region field. The structure file should also have different names to identify the subject and region.

If you want, you can attach the wrapper and structure files.

-Donald
Jul 16, 2015  03:07 PM | Fleur Bouwer
RE: Contrast image filenames are inconsistent
Sorry, I wasn't clear about that. I do get different folders for the different seed regions and the ROI and Region fields are correct. I just meant that the contrast field is identical for all files, so the differences don't make sense to me.

Just to check, I got two Matlabs going and started different subjects in each. For subject 1, the contrast images get the full contrast name, while for subject 3 (running the exact same script at exactly the same time), they get the short, numbered names. I'm really at a loss what's going on here.

I attached 4 files (see the next posts, couldn't do that in 1 go). It makes 2 structure files for each seed region, 1 with the name identifying region, subject and date and 1 that gets overwritten for each region (as you will see, it already overwrote it for subject 3, so it has a different region in it, it did also make the earlier one). Apart from the regions and subject identifiers, everything is the same. The file that gets overwritten ends up in whatever directory I cd to before starting the analysis and the file with the full name ends up in the SPM directory. As the files are the same, I do not really see how for subject 1 it gives the contrast images different names than for subject 3. Should I cd to a different directory before running the analysis? Or may it have something to do with SPM windows still being open? Just guessing here...

This is part of my script:

% Defining contrasts, with left, right and name in it

contrasts2use={
{'temp_strictmetric_0'} {'none' } {'temp_strictmetric_0'};
{'temp_weakmetric_0'} {'none'} { 'temp_weakmetric_0'};
{'temp_nonmetric_0'} { 'none'} { 'temp_nonmetric_0'};
{'int_strictmetric_0'} { 'none' } {'int_strictmetric_0'};
{'int_weakmetric_0'} { 'none'} { 'int_weakmetric_0'};
{'int_nonmetric_0'} { 'none'} { 'int_nonmetric_0'};
{'temp_strictmetric_1'} { 'none'} { 'temp_strictmetric_1'};
{'temp_weakmetric_1'} { 'none'} { 'temp_weakmetric_1'};
{'temp_nonmetric_1' } {'none' } {'temp_nonmetric_1'};
{'int_strictmetric_1'} { 'none'} { 'int_strictmetric_1'};
{'int_weakmetric_1'} { 'none'} { 'int_weakmetric_1'};
{'int_nonmetric_1'} { 'none' } {'int_nonmetric_1'};
{'temp_strictmetric_2'} { 'none'} { 'temp_strictmetric_2'};
{'temp_weakmetric_2'} { 'none'} { 'temp_weakmetric_2'};
{'temp_nonmetric_2'} { 'none'} { 'temp_nonmetric_2'};
{'int_strictmetric_2'} { 'none' } {'int_strictmetric_2'};
{'int_weakmetric_2'} { 'none'} { 'int_weakmetric_2'};
{'int_nonmetric_2' } {'none'} { 'int_nonmetric_2'};
…etc...
};

% (here I define stuff like the subject identifier, all directories etc., then loop over subjects and before starting the analysis cd to the PPIdir I'm making)

This is the function I use to make the parameter file:

function P=makePPPI(pp_id,ROI2use,roiname,SPMdir,PPIdir,PPIdir2nd,contrasts2use)
% Parameter struct
P.subject=pp_id; 
P.directory=SPMdir; 
P.VOI=ROI2use; 
P.Region=[roiname]; 
P.Estimate=1; 
P.contrast=0; 
P.extract='eig'; 
P.Tasks={'1' 'temp_strictmetric_0' 'temp_weakmetric_0' 'temp_nonmetric_0' 'int_strictmetric_0' 'int_weakmetric_0' 'int_nonmetric_0' 'temp_strictmetric_1' 'temp_weakmetric_1' 'temp_nonmetric_1' 'int_strictmetric_1' 'int_weakmetric_1' 'int_nonmetric_1' 'temp_strictmetric_2' 'temp_weakmetric_2' 'temp_nonmetric_2' 'int_strictmetric_2' 'int_weakmetric_2' 'int_nonmetric_2' 'instruction' 'pic_hit' 'rit_hit' 'button'};
P.Weights=[]; 
P.analysis='psy'; 
P.method='cond'; 
P.CompContrasts=1; 
P.Weighted=0; 
P.ConcatR=0; 
P.preservevarcorr=0; 
P.outdir=PPIdir; 
P.GroupDir=PPIdir2nd; 
P.equalroi=0;
P.FLmask=1;

if ~exist(P.GroupDir,'dir')
mkdir(P.GroupDir)
end

for contrasti=1:length(contrasts2use)
P.Contrasts(contrasti).left=contrasts2use{contrasti,1};
P.Contrasts(contrasti).right=contrasts2use{contrasti,2};
P.Contrasts(contrasti).STAT='T';
P.Contrasts(contrasti).Weighted=0;
P.Contrasts(contrasti).MinEvents=5;
P.Contrasts(contrasti).name=contrasts2use{contrasti,3};
end
end
Jul 16, 2015  03:07 PM | Fleur Bouwer
RE: Contrast image filenames are inconsistent
Second P file
Jul 16, 2015  03:07 PM | Fleur Bouwer
RE: Contrast image filenames are inconsistent
3rd P-file
Jul 16, 2015  03:07 PM | Fleur Bouwer
RE: Contrast image filenames are inconsistent
And the last one
Jul 16, 2015  08:07 PM | Donald McLaren
RE: Contrast image filenames are inconsistent
Can you remove the field outdir from the parameter files? I'm not sure if this is the source of the problem, but according to the parameter files, these are the same for every VOI. I suspect the field isn't being used because there looks like there is a potential bug in the code. If outdir doesn't exist, then you should get PPI folders that are labeled with the region names.

I would cd into the 1st level SPM directory before running the PPPI command. As you are overwriting files that you may be trying to read at the same time, this could be the cause.

If you run one subject at a time and one seed at a time, do you encounter the issue OR is it only when they are run at the same time? 

The only thing that I can think of is that some paths are being crossed in the configuration and PPPI line, but not in the PPPI code. If you run it outside of a try loop, do you get any error messages when moving the files from the 0001 format to the contrast name?

Can you also try this new spm_contrasts_ppi file?

If you still are having issues, can you send me your script file and I can try and replicate the issue with another dataset.
Attachment: spm_contrasts_PPI.m