Thanks for specifying that.
Some comments on “For 1.”:
I would recommend using 3dClusterize rather than 3dmerge—the latter is very old, and I find the syntax quite opaque. You can also input both a “data” volume (e.g., a beta weight or coefficient) as well as an accompanying stat (e.g., t-stat), for making maps of both simultaneously. Here is an example of the former from the help file:
-inset stats.FT+tlrc. \
-ithr 2 \
-idat 1 \
-mask mask_group+tlrc. \
-NN 1 \
-bisided -3.313 3.313 \
-clust_nvox 157 \
-pref_map ClusterMap \
NB: If the stats volume was created by AFNI, then it would have header information to convert from a specified p-value to an equivalent t-stat (see 3dClusterize help examples for more info on that). Note when converting between p- and statistics-values, one needs to have an appropriate sided hypothesis specified—in AFNI, our default is 2sided testing (because most researchers are looking for differences between things), while in other software the default tends to be 1sided (because of the kind of statistic output). So, this is something to be aware of in mixing software outputs and commands. Not correcting for having two, 1sided tests will artificially double FPR values; see more info here: A tail of two sides: Artificially doubled false positive rates in neuroimaging due to the sidedness choice with t‐tests.
If you want your positive and negative supra-threshold regions to not count as a single cluster (which I guess you wouldn’t), then using the “-bisided” option, as above, is good. I am not sure what the equivalent would be in other software.
Also note, when you run 3dClusterize, you will get a table per cluster that tells you how many voxels there are per cluster (3dROIstats can also do the same).
Another difference between software is what it means to be a neighbor of a voxel. Do they have to share a face, or a face or an edge, or a face or an edge or a node? AFNI, FSL and SPM have typically used different definitions as a default—in AFNI you can specify what you want, though, using “NN” (nearest neighbor value). See here:
I am not sure what method you used to calculate your clustersize threshold, but this might have been calculated using one “neighborhood” definition, and different software might have a different one.
Note that there has also been a lot of discussion in the field about what appropriate p-values should be used for voxelwise thresholding. Several papers (and journals, too) have pushed for using p=0.001 and not p=0.01—this is of course entirely up to you, but note that that might be a point of discussion with a reviewer.
On a scripting note: you are using “>” to redirect output in your for-loop. I think this will overwrite whatever was there previously, and it doesn’t look like $outfile changes value within that loop. So you might want to adjust that by having the $outfile change each time, or by using “>>” to redirect with appending.
Some comments on “For 2.”:
Converting BRIK/HEAD to NIFTI is fine, sure. One can use 3dAFNItoNIFTI or 3dcopy, etc. AFNI programs do read/write NIFTI files directly, in most cases, if specified (afni_proc.py uses all BRIK/HEAD, but copying output is pretty straightforward, as you have done).
The for-loop here is missing a “-prefix …” for the command, I think.
In the bilateral mask, if the hemispheric masks are each binary, then the L and R hemispheres have lost their identity in this sum; if you wanted to be able to tell them apart in the output, you could use:
-a 'lh_MTL_rs.nii' \
-b rh_MTL_rs.nii \
-expr 'a+2*b' \
for example. Of course, if they aren’t binary masks, this may already be accounted for. (NB: this assumes that the ‘a’ and ‘b’ datasets don’t overlap—you can check for that visually, if it might be a concern, or by seeing what the max value in the dset is after.)
You had initially asked about potential left-right flipping in each case. I don’t see how that could happen with the above commands. You can also verify by looking at the clusters and hemispheric maps in the GUI. You can even use the “Clusterize” button in the GUI, to see the clusterizing at work.
Sorry for the long and possibly extraneous reply!