I have 90 functional volumes in .nii format. Can I convert them to AFNI format. I have tried following commands:
- 3dcopy fRSN_P2-0015-00090-000090-01.nii p2+orig: converting only one file (which seems obvious).
- 3dcopy fRSN_P2-0015*.nii p2+orig: shows fatal error (3dcopy can only take one input and one output)
- 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
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.
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?
You could use 3dTcat if your objective is to stick all of them together into a single file.
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
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
Thanks very much. It is very helpful.
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.