Creating a single .nii.gz from .nii files

I have downloaded ADNI rs-fMRI dataset. Each subject consist of 141 .nii files. I don’t know how can I use this files in I watched a video on how to process resting state data and in that video the instructor used a single .nii.gz file. I was wondering if there is a way in AFNI to create such .nii.gz file.


Please go ahead and try it. AFNI programs read .nii and .nii.gz
files as they are specified. You should not have to do anything
with the files.

Though note, to compress (.nii → .nii.gz), one could use gzip.
In the other direction, one could use gzip -d or gunzip. Also,
AFNI programs will write .nii or .nii.gz as specified in the output

But again, you should not need to alter the compression.

  • rick

This is exactly what I do:

  1. I run
  2. In Analysis Initialization, I choose resting state and apply the changes
  3. Since I don’t have any anatomical dataset (I just have 141 .nii files for each subject), I uncheck Anatomical Dataset
  4. In EPI Datasets section, I load all .nii files
  5. Then I generate the cods and run them.

Then I get several warnings and this error in the end:

e[7m** FATAL ERROR:e[0m Can’t use dataset with < 15 time points per voxel!
** Program compile date = Dec 31 2016

Because of this error I guessed that there I should gather all my .nii files in a single .nii.gz file.

This is the problem: “(I just have 141 .nii files for each subject)”.
It has nothing to do with .gz.

You do not have a dataset that is a single run, but have 141
separate volumes. Put them into a single dataset before
running or Specify the TR when
doing this:

3dTcat -TR XXXX -prefix run1 volume*.nii.gz

  • rick

Thank you very much, I guess I should read the manual more carefully.

I know it may sound silly, But I don’t know where to use 3dTcat -TR XXXX -prefix run1 volume*.nii.gz, I tried to copy and paste it in my command line, But it did not work.
And my second problem is that when I open mu subject description the TR looks like this : “TR”>3000.0, But for an other patient it is: “TR”>3000.9983, Should I use only 3 in my code or I should specify the TR exactly?
And my second problem is that my slices are interleaved, should I worry about it when I use 3dTcat -TR XXXX -prefix run1 volume*.nii.gz . ?

For the first question, you should replace the appropriate parts of the command you pasted, so the TR gets 3.000, prefix is followed by the name you want for the output, and the input volumes are the names of your EPI dataset volume files (maybe *.nii where the asterisk is a wildcard character).

The approximate TR will probably work unless you have a thousand TRs, and then the later TRs could be off by a second. Still it doesn’t really hurt to set the TR exactly. The slice timing can be set with the 3dTcat command by adding “-tpattern alt+z” to get interleaved slice timing.

Thank you very much.
There is one more question, I am using ADNI dataset and in ADNI the slices are interleaved. Is it something that I should worry about when I’m using 3dTcat?

That is what Daniel mentioned, that you probably
want “-tpattern alt+z”. It is important to use the
correct timing pattern, or at least not an incorrect

  • rick