------------------------------------------------
 The SessionsTools -> Calc 3D Rand Block Stats
 sets up and runs deconvolution on 3D volume
 data set using AFNI 3dDeconvolve (by Doug Ward)
------------------------------------------------
This panel configures files and runs Doug Ward's
3dDeconvolve on functional time-series BRIKs.
Normally, you then use SessionTools -> Import 3D
Stats to extract the output files and PAINT them.
It requires that single-column 1D paradigm files
have been previously generated and placed within
each paradigm dir (see below).

The Image Name Format

This will typically be a concatenated,
motion-corrected time-series BRIK.  This is
automatically entered from the Setup Functional
panel.

Paradigm Dir

Directory containing the single-condition 1D
files specifying the paradigm.  This can be
anywhere (e.g., a central paradigm depository).
However, since these files are small, and since
a central paradigm store may get out of sync
with an already-performed expt, it is a better
idea to save a copy of the paradigm files that
were actually used inside each scan directory.
The directory specified here can either be
absolute (starts with "/") or relative (doesn't
start with "/" and is assumed to be inside the
current scandir).  A relative path is preferred
since using an absolute path to the paradigm
dir may break if the functional session is moved
into a different FUNCTIONALS_DIR.  The standard
name is "stim1Ds".

Paradigm Files

These are single column (n x 1) files, one
for each condition.  The filename should be a
short (8 chars or less) word followed by a .1D
suffix (e.g., face.1D, house.1D, scramble.1D).
(see below on naming rules for files that are
going to be auto-concatentated).

The files should end in unix-style newline
characters, \n.  If they don't -- e.g., output
from export to "space-separated" from Excel has
DOS carriage returns (\r), not unix newlines
(\n) -- fix them by using, for example, tr:

  tr '\r' '\n' < condfiles.prn > condfiles.txt

That would convert DOS carriage returns to unix
newlines (you will need a different tr command
is you have more than one invisible end-of-line
character).  To see explicitly what is in a text
file, use

  od -cv textfile

This will print out the actual bytes in the
file 16 to a line, with spaces between each byte
(N.B.: space characters also show up as spaces
[separated by spaces]).  There should only be
numbers (0 and 1) and newlines (\n) (and possibly
spaces or tabs (\t) in the paradigm file.  Spaces
and tabs will be ignored.  Any other characters
will cause csurf or 3dDeconvolve errors.

The filename stem (e.g., face, house, scramble)
will be used in the interface and the resulting
saved bitmaps as the condition name.  Inside
the file, there should be a 1 when its named
condition is present and a 0 when it is not
(an error panel will come up if something other
than 0 or 1 is found).

The baseline condition is defined by the presence
of a 0 in all of the condition files.  Thus,
there is no 1D file for the off-condition.
Except for the off-condition case, for a given
TR, there should be a 1 in exactly one paradigm
file.  Here is an example of a portion of a
paradigm file:

====== cut here ==========================
0
0
1
1
1
...
====== cut here ==========================

If the scandir was generated by concatenating
raw data files from separate runs (COMBINE
on the SessionTools -> Combine 3D Raw Images
panel) prior to opening this panel, the COMBINE
concatentation process should already have
automatically generated the following files:

 concat'd BRIK/HEAD raw data file
 concat'd motion.1D file (if runs volreg'd)
 boundsfile: run1.1D (so HDRs don't cross runs)
 a stim1Ds subdirectory
 concat'd paradigm files put in stim1Ds/

N.B.: for the automatic concatenation of paradigm
1D files to work correctly, the paradigm files
in the stim1Ds subdir in each of the scan dirs
to be concantentated *must* be named as follows:

  scan1
    face1.1D
    house1.1D
  scan2
    face2.1D
    house2.1D
  ...

That is, the condition name stem (up to the
number before the .1D suffix) much be exactly
the same across all scans to be concatentated.
The stem must be immediately followed by a single
numeral before the .1D suffix.

The list of conditions (1D files) to concatenate 
is taken from the first directory in the list.
That is, each successive scan should have 
the same set of conditions in it.  It's OK if
numerals are the same across scans (e.g., same
randomization in those scans).  The concatenated
paradigm file will be given a name that has the
numeral position replaced by a 'C'.

TR (sec)

Repetition time between successive images of
the same slice in seconds.

Maximum Lag (-maxlag)

The maximum lag (in TRs) to allow when solving
for the hemodynamic response function for a
each trial type.

Polynomial Fit Order (-polort)

This specifies the order of the polynomial used
to fit the low frequency drift in the signal.
The default is 2.

Motion Params File (-dfile)

This should contain a 6-parameters-per-timestep
estimate of motion artifact.  This is typically
generated by 3dvolreg after motion correction is
run in the Setup Functional panel.

Scans, Total TRs

The number of scans that were concatenated to
generate the input file named at the top, and the
total number of TRs that it contains.

Paradigm Panel

When "READ 1Ds" is clicked, the individual
condition paradigm files are each read and
assembled into a paradigm matrix, where each
column comes from one 1D file.  The stems of the
paradigm filenames are substituted for 1's and
"----" is substituted the 0's in the 1D file.
This step verifies that the 1D files all have
the same length.

Condition Differences

To add a subtraction, select a block type from
the "Condition A:" and  "Condition B:" dropdown
menus and then click "ADD SUBTRACTION" which
should add it to the Subtractions list below.  To
omit a subtraction, use Backspace.

Action Button--DECONVOLVE

When DECONVOLVE is clicked, 3dDeconvolve will be
run according to the mode radio buttons just
above the paradigm window (test/F/t-stats).  The
output stats file will be written into the
current scan directory.  If Test is selected, the
parameters are checked for completeness and the
design matrix is tested for singularity.

Stats Output File

The output stats BRIK name appears here after
DECONVOLVE has been run.  This takes a while
for a concatenated scan.  Correct settings for
rendering will depend on the paradigm.  For the
blue/red scale, try starting with:

  smooth:   10
  thresh:   0.0
  contrast: 0.15
  midpoint: 7
