help > Error: 'Checking for zipped files failed '
Showing 1-7 of 7 posts
Display:
Results per page:
Apr 25, 2014  11:04 AM | Christian Utzerath
Error: 'Checking for zipped files failed '
Dear Dr. McLaren,

First I would like to thank you for the speedy release of version 13.1, which fixed a bug that I encountered earlier.

I am encountering a problem with gPPI that I do not entirely understand. Thus I thought I might share it here. Specifically, when I call PPPI, the program aborts with the message 'checking for zipped files failed'. The running_gPPI test files run smoothly.

My first suspicion was that maybe PPPI would miss files. My GLM in SPM.mat contains 9 sessions, but initially I only specified one VOI in the P.VOI parameter field. To rule this out, I copied my gPPI parameters in a short wrapper that would loop over all regions - but it still fails at the same point, telling me that 'checking for zipped files failed' in PPPI.

Here is the code of the wrapper:

addpath('D:\spm8')
addpath('D:\spm8\toolbox\PPPI')
fmri_dir = 'M:\impexp\fMRI\';
analysis_dir = 'analysis\Firstlevel_Blocks_normalised_RPsAdapt180_19-Apr-2014'

for isubj = 1:1

subjects = {'S04'};
glm_dir = fullfile(fmri_dir,subjects{isubj},analysis_dir);

% Files with the actual time courses of your voxels of interest
% For now, these were manually extracting using SPM -> results -> eigenvariate
regionfile = {'VOI_A1_1.mat' 'VOI_A1_2.mat' 'VOI_A1_3.mat' 'VOI_A1_4.mat' 'VOI_A1_5.mat' 'VOI_A1_6.mat' 'VOI_A1_7.mat' 'VOI_A1_8.mat' 'VOI_A1_9.mat'};

% Names of these regions
region = {'A1_1' 'A1_2' 'A1_3' 'A1_4' 'A1_5' 'A1_6' 'A1_7' 'A1_8' 'A1_9'};

for ireg=1:numel(regionfile)
try
% PPPI parameters
P.subject = subjects{isubj};
P.VOI  = [pwd filesep regionfile{ireg}];
P.Region  = region{ireg};
P.SPMver = 8;
P.directory = glm_dir;
P.Estimate = 1;                             % 1: Will estimate PPI model
P.Contrast = 'Omnibus F-test for PPI Analyses'; % Adjusted for this effect of interest
P.extract = 'mean';
P.Tasks = {'1' 'Predictive' 'Non-predictive'};
% P.Weights = []; % For traditional PPI, contrast weights are specified here
P.analysis = 'psy';
P.method = 'cond'                           % 'trad' or 'cond'
P.CompContrasts = 1;
P.Contrasts(1).left = {'Predictive'};       % LHS of left > right
P.Contrasts(1).right = {'Non-predictive'};  % RHS of left > right
P.Contrasts(1).STAT = 'T';                  % 'T' or 'F'
P.Contrasts(1).Weighted = 0;                % tasks are not weighted by amount of trials
P.Contrasts(1).MinEvents = 5;               % Minimum n events to include
P.Contrasts(1).name = 'Predictive_vs_Non-predictive';

save([subjects{isubj} '_PPI_config.mat'],'P');
PPPI([subjects{isubj} '_PPI_config.mat'])

catch
disp(['Failed: ' subjects{isubj}]);

end
end
end


My working directory contains the following files:
VOI_A1_1.mat to VOI_A1_9.mat
Estimated first level GLM and SPM.mat
Parameter files (after it is saved)

The first level GLM was created from images that were preprocessed using SPM. Raw and preprocessed files are still in the same directories as the SPM.mat lists them, so they cannot really be missing.


I am feeling that this sort of error must be due to something really trivial on my end, but I cannot really identify the problem. Would you happen to have an idea about this?
Apr 25, 2014  01:04 PM | Donald McLaren
RE: Error: 'Checking for zipped files failed '
What OS and MATLAB version are you using?

What happens when you use the following code:
load SPM.mat
for ii=1:numel(SPM.xY.VY)
    a{ii}=SPM.xY.VY(ii).fname;
end
a=unique(a);
filesgz={}; filesbz={};
for ii=1:numel(a)
    if ~exist(a{ii},'file')
       disp([a{ii} ' DOES NOT EXIST.'])
    else
       disp([a{ii} ' EXISTS']) 
    end
end

What happens when you type:
usejava('jvm')

Depending on the answers, you'll need to try some other things, but the above is a good starting point.
Apr 25, 2014  03:04 PM | Christian Utzerath
RE: Error: 'Checking for zipped files failed '
Dear Dr. McLaren,

Thank you for the fast reply! I am using Windows, Matlab 2012a and SPM8. However, I have the same problem when I try to run the analysis on Mac OS X.

I think the code you posted gives the answer away; it returns these error messages for every file
'/home/predatt/chrutz/impexp/fMRI/S04/func/task3_run3/swrf131111075050STD131221107523235034-0011-00184-000184-01.nii DOES NOT EXIST.' 

It appears then that the file references in SPM.mat are OS-dependent. Having processed my files on a Linux server, these references are then of course invalid in Windows. That would explain why PPPI cannot find these files, and what my trivial mistake was!

With this result I think I can continue for the time being; meanwhile, I would however like to ask you one more question:

Does any part of gPPI or the create_sphere package use compressed files (such as *.nii.gz)? I have been trying a couple of different approaches to extract VOI information, and some custom functions that I encountered rely on this format. Since gPPI explicitly checks for zipped data, I thought such a commonality might be a bridge between gPPI and other custom functions (supposing that would be advantageous at some point).


All the best,
Christian
Apr 25, 2014  04:04 PM | Donald McLaren
RE: Error: 'Checking for zipped files failed '
I'll fix the code to be explicit that the files do not exist. I think because I used the error command, you get an error message that is not informative.

Yes. The filenames in the SPM.mat file are OS-Dependent/system-dependent. If the locations of the files change or the SPM.mat points to files on another system, then you will run into issues.

The easiest thing to do is change the SPM.mat file to point to the appropriate locations. This can be done using the command
spm_changepath. This is what is used with the sample dataset to make it work on all computers. See runOnSample.m.Windows.Template or runOnSample.m.Template for examples.

There are no parts of my code that use '.nii.gz' files. The checking for zipped files is done to check if you have zipped files and then unzips them to process the data. Then the code will rezip the files at the end. This makes the files useable to matlab and spm functions.

As far as I have been able to discern, any program that uses '.gz' files must uncompress the files first, then do the processing, then zip the files back up before the program ends. Thus, the user doesn't know the files are being uncompressed and compressed. In the future, it may be possible to only uncompress part of the data, which would speed everything up.
Apr 25, 2014  07:04 PM | Donald McLaren
RE: Error: 'Checking for zipped files failed '
Here is an updated version of PPPI.m that provides better error messages that will reduce troubleshooting time in the future.
Attachment: PPPI.m
Apr 29, 2014  04:04 PM | Christian Utzerath
RE: Error: 'Checking for zipped files failed '
Dear Dr. McLaren,

Thank you for the quick fix! I have tested my wrapper on a couple of models now, and it runs very smooth - the toolbox is most definitely a great simplification of the whole process!


One thing that I wanted to share - because other users will face this as well - is the suggested fix for the 'VOI larger than dataset error'. Because my seed VOI is located at the edge of the brain, I encountered this error in every subject. The gPPI manual suggests to fix this by multiplying the VOI mask with the brain mask that SPM creates. Any voxel that is included in the VOI mask (has value 1) but is excluded in the brain mask (has value 0) will then be excluded because of the multiplication with zero.

This suggested approach is very simple. However if, like me, someone has not done it before, you might not realize that SPM8 can do this to *.nii-files. The solution is the imcalc function:

brain_mask_path = fullfile(work_dir,'mask.img');
voi_mask_fname = strcat([VOI_name, '_mask.nii']);
voi_mask_path = fullfile(work_dir,voi_mask_fname);
matlabbatch{1}.spm.util.imcalc.input = {brain_mask_path, voi_mask_path};
trimmed_mask_path = strcat(['trimmed_' voi_mask_fname]);
matlabbatch{1}.spm.util.imcalc.output = trimmed_mask_path;
matlabbatch{1}.spm.util.imcalc.outdir = {''};
matlabbatch{1}.spm.util.imcalc.expression = 'i1.*i2';
matlabbatch{1}.spm.util.imcalc.options.dmtx = 0;
matlabbatch{1}.spm.util.imcalc.options.mask = 0;
matlabbatch{1}.spm.util.imcalc.options.interp = 1;
matlabbatch{1}.spm.util.imcalc.options.dtype = 4;
spm_jobman('run',matlabbatch);


In a wrapper, I would add a safeguard that checks if any VOI extends beyond the borders of the brain mask, and if so, trims the VOI in this way. I thought I would just leave this here in case another user also has a very lateral VOI and is searching for a solution (since this was not described online when I was looking for it).




All the best,
Christian
Apr 29, 2014  06:04 PM | Donald McLaren
RE: Error: 'Checking for zipped files failed '
Christian,

Thanks for the useful code. There are a few things that should be pointed out to the user:

(1) This approach should utilize the mask.img file from the group analysis, this way all subjects have the same VOI.

(2) The program can trim the VOI on a case by case basis by setting P.FLmask=1 and P.equalroi=0.

(3) The automatic trimming (e.g. P.FLmask=1 and P.equalroi=0) is not enabled by default because I felt that it is better to always use the same VOI for all subjects. If you meant automatic trimming based on the group mask, this would require more options and code, it would also require changing the P.VOI field as the program loops through subjects, it would require the program to redo subjects previously done, and it would require knowing the group mask location.

Perhaps, the best advice is to run this script before your gPPI analysis to avoid errors.

-Donald