Converting functional .nii files to .nii.gz

Hi,
I have 90 functional volumes in .nii format. Can I convert them to AFNI format. I have tried following commands:

  1. 3dcopy fRSN_P2-0015-00090-000090-01.nii p2+orig: converting only one file (which seems obvious).
  2. 3dcopy fRSN_P2-0015*.nii p2+orig: shows fatal error (3dcopy can only take one input and one output)
  3. 3dcopy fRSN_P2-0015* p2+orig: shows fatal error (3dcopy can only take one input and one output)

Attaching google drive link to access some files. fMRI Data - Google Drive

Thanks

code text  # or delete if not needed

If fRSN_P2-0015*.nii resolves in 90 files, that will not work. 3dcopy works like the shell 'cp' command (without directories), copying one dataset at a time. For this it would be good to write a little loop, going from ...-01.nii to ...-90.nii.

  • rick

But, writing the conversion in loop will create BRIK and HEAD files for each .nii file. I want to create a single BRIK and HEAD file for the whole session per subject. Is there any way in AFNI to do that?

Thanks

You could use 3dTcat if your objective is to stick all of them together into a single file.

Howdy-

Just adding a bit to @pmolfese's likely solution to what is desired here, if you are wanting to concatenate or glue together your set of files (which is different than copying each individually).

  • you can type ls -1 fRSN_P2-0015*.nii and verify visually that the order of the displayed column of files is the order in which you would like these datasets to be glued together; the top of the column will be the first (or [0]th in zerobased counting terms) volume.

  • the following command can then be used to concatenate them to a new BRIK/HEAD file:

    3dTcat -prefix DSET_NEW fRSN_P2-0015*.nii
    

    If you wanted the output to be a (compressed) NIFTI formatted file, you could use:

    3dTcat -prefix DSET_NEW.nii.gz fRSN_P2-0015*.nii
    

--pt

Thanks very much. It is very helpful.

Thanks

Just to add another technique, you can also use catenation in memory without writing the file to disk. This kind of remastering happens on the fly with either quotes or parentheses around the input datasets. From the help of 3dcalc :

CATENATED AND WILDCARD DATASET NAMES
------------------------------------
 Datasets may also be catenated or combined in memory, as if one first
 ran 3dTcat or 3dbucket.
 
 An input with space-separated elements will be read as a concatenated
 dataset, as with 'dset1+tlrc dset2+tlrc dset3+tlrc', or with paths,
 'dir/dset1+tlrc dir/dset2+tlrc dir/dset3+tlrc'.
 The datasets will be combined (as if by 3dTcat) and then treated as a
 single input dataset.  Note that the quotes are required to specify
 them as a single argument.

Getting back to the party here, note that if this is a time series, you will probably want slice timing and a TR set. Those could both be included in the 3dTcat command. After the fact, 3drefit could be used to add or modify them.

  • rick