3dTcat - Creating/cutting distinct time-series within one code

Dear all,

I am currently working with 3dTcat and my aim is to cut out distinct time windows from a run and then, in a second step, to save those time windows not into one single new file, but into distinct files.
In other words: there is one input file (a preprocessed and regressed run “fitts.Subject_1+tlrc”). I would like to cut out several sub-brick distances (time windows) in this run and then save those different sub-bricks (time windows) into distinct new files.

However, no matter how I try to adjust my code for this job, 3dTcat always provides me with one single output file; and this file then contains all time windows merged together.

First, I tried it with the following code:

directory=/users/philipp/desktop/fmri/dataset/subjects
for subject in subj1_exp1
do
for fMRIruns (fitts.Subject_1+tlrc)
do
cd $directory/$subject/Preprocessing
echo “Processing $subject …”
3dTcat
-prefix $fMRIruns
-session $directory/$subject/Cut_TimeWindows
-verb
-tr 1.0
$fMRIruns’[21…75]’
$fMRIruns’[199…253]’
$fMRIruns’[427…481]’
$fMRIruns’[489…543]’
$fMRIruns’[549…603]’
$fMRIruns’[659…713]’
$fMRIruns’[837…891]’
$fMRIruns’[893…947]’
$fMRIruns’[955…1009]’
$fMRIruns’[1013…1067]’
done
done

Then, a friend of mine suggested to use another (third) for-loop that adds the distinct time windows. See the following code:

directory=/users/philipp/desktop/fmri/dataset/subjects
for subject in subj1_exp1
do
for fMRIruns (fitts.Subject_1+tlrc)
do
for TimeWindows (‘[21…75]’ ‘[199…253]’ ‘[427…481]’ ‘[489…543]’ ‘[549…603]’ ‘[659…713]’ ‘[837…891]’ ‘[893…947]’ [955…1009]’ ‘[1013…1067]’)
do
cd $directory/$subject/Preprocessing
echo “Processing $subject …”
3dTcat
-prefix $fMRIruns.$TimeWindows
-session $directory/$subject/Cut_TimeWindows
-verb
-tr 1.0
$fMRIruns$TimeWindows
done
done
done

The second code in not working at all. The output of this code is “for for for quote>” and then AFNI stops. I think that the problem is that AFNI is searching for a command what it should do with “TimeWindows”, and then I do not provide any command beside adding it as “$TimeWindows” behind the input file name of “$fMRIruns” near the end of the code. But I don’t know how to solve this problem and I already tried a lot.

Is this problem solveable? Thanks, Philipp

An update:

I just realized that I could simply add 3dTcat as program over and over again, like in the following example (which paradigmatically only shows two time windows):

directory=/users/philipp/desktop/fmri/dataset/subjects
for subject in subj1_exp1
do
for fMRIruns (fitts.Subject_1+tlrc)
do
cd $directory/$subject/Preprocessing
echo “Processing $subject …”

3dTcat
-prefix 21-75.$fMRIruns
-session $directory/$subject/TimeWindows
-verb
-tr 1.0
$fMRIruns’[21…75]’

3dTcat
-prefix 199-253.$fMRIruns
-session $directory/$subject/TimeWindows
-verb
-tr 1.0
$fMRIruns’[199…253]’

done
done

This actually works and one could now add all required time windows this way. 3dTcat then creates distinct outputs for each time window (instead of merging them all into one file). It is not a nice way to do this though, as the code would become really long depending on the number of time windows. So, if there is a nicer way to code this, please let me know.

Thanks, Philipp

Update:

The problem is solved. Here is a efficient code which functions.

directory=/users/philipp/desktop/fmri/dataset/subjects
for subject in subj1_exp1
do
for fMRIruns (fitts.Subject_1+tlrc)
do
for TimeWindows (‘[21…75]’ ‘[199…253]’ ‘[427…481]’ ‘[489…543]’ ‘[549…603]’ ‘[659…713]’ ‘[837…891]’ ‘[893…947]’ ‘[955…1009]’ ‘[1013…1067]’)
do
cd $directory/$subject/Preprocessing
echo “Processing $subject … $TimeWindows …”
3dTcat
-prefix $TimeWindows.$fMRIruns
-session $directory/$subject/TimeWindows
-verb
-tr 1.0
$fMRIruns.BRIK'$TimeWindows'
done
done
done

Explanation of the code (written in Zsh): This code takes the file “fitts.Subject_1+tlrc” as input. It then creates distinct time windows for all assigned windows in the “for TimeWindows” loop. That is, the here assigned sub-bricks are extracted from the run and copied into distinct time windows as output files. Hope this helps people in the same situation.

Feel free to comment and have a good day. Special thanks to Yasir (the problem solver) if you read this.

Philipp

That is great, Philipp, thanks for the updates!

An alternative (but not necessarily easier) method might be to run 3dTsplit4D to initially break the 4D dataset into many 3D ones, and then use array subscripting to put them together. That would end up being a very similar script, but it can be nice to know of other options.

Thanks,

  • rick