my aim is to create a single .1D or .txt file containing all voxels’ values in one column, but from many subjects. Using 3dmaskdump, I am only able to do one of the following two options:
- I provide all subjects as input and write the results into one .1D or .txt file. In this case, each subject’s values are added as a new column. The result is a file that contains as many columns as subjects.
- I use 3dmaskdump per subject, resulting into as many output files as there are subjects.
But I would like to create only one giant file that contains all the voxels from all subjects in one column, i.e., one value per row. The file would start with subject1 and contains all the voxels from subject1. Then all voxels from subject2 are added, and so on.
Is this possible to realise via AFNI?
I provide all subjects as input and write the results into one .1D or .txt file. In this case, each subject’s values
are added as a new column. The result is a file that contains as many columns as subjects.
Suppose that your 1D file is called Philipp.1D. I offer two approaches –
- If the number of columns in Philipp.1D is N and N is not large, try
1dcat Philipp.1D’‘' Philipp.1D’‘' … Philipp.1D’[N-1]'' > out.1D
1dcat out.1D' > out.1D (this line is necessary if you want the output to be one column instead of one row)
If N is large, create a loop to replace the first line above.
- Do it in R:
x ← read.table(‘Philipp.1D’) (use option ‘skip’ if you have some number of lines in the header)
write.table(c(x), file = “out.1D”, quote = F, row.names = F, col.names = F)
What is the current output per subject, is it just one value per row (meaning the input has only 1 volume)?
If so, then you could write one file per subject (does the alphabetical ordering matter?), so that each file has one value per row, and then just ‘cat’ the files.
foreach subj ( `cat my_subjects.txt` )
3dmaskave -mask MASK+tlrc data_$subj+tlrc > ave_$subj.1D
cat ave_*.1D > all_subjects.1D
Hi Gang and Rick,
Gang, thank you. Your solution for AFNI worked fine. I totally forgot that it is possible to select columns with 1dcat. So what your approach with AFNI does is the following:
- 3dmaskdump: Extraction of all voxels from all subjects into one .1D file. This file contains as many columns as subjects. Each column contains the voxels from one specific subject.
- Transpose all columns into one single row. The result is one row that contains the voxels from all subjects.
- Transpose the row into a column.
Rick, when using 3dmaskdump per subject, the output was one file per subject that contains one column with thousands of voxels (one voxel per row). In this case, I already used 1dcat in order to “cat” the single columns together into a new file. Of course, the result was a new file that contains as many columns as subjects, while I wanted to add “one column after another” so that the number of columns (=1) remains stable (instead of having as many columns as there are subjects). I then thought that it is probably impossible to achieve my aim in AFNI and created this topic.
However, as stated above, I totally forgot about the single column selection option via 1dcat and the idea to transpose (File1’'', …).
Happy new year.