Case AX
Kathryn Barker 7/24/2006
1 run MT localizer
1 run LO localizer
1 run auditory cortex localizer

6 runs RER target (LH/RH/LF/RF + target)

comments: least favorite was MT because it made her dizzy; maybe dot speed is too fast!

# Network IO was slow, try initial steps locally then copy to network

set ec = AX
set session = /Volumes/data1/UT/{$ec}
cd $session
mkdir afni
set session = /Volumes/data1/UT/{$ec}/afni
cd $session

cd /Volumes/data1/UT/AX/AX/TACTILE

# these are series number of fMRI runs from DICOM
set t = (4 6 7 9 10 11 12 14 15 )
foreach s ( $t )
set dir =  "FMRI-SS - "{$s}"01"
cd "$dir"
to3d -session {$session} -epan -prefix {$ec}r{$s} -time:tz 150 33 2000 alt+z  *   
cd ..
end

# did one T1 first, then two T1s at end
set anat = (3 16 17 )
foreach s ( $anat )
set dir =  "T1W-3D- - "{$s}"01"
cd "$dir"
to3d -session $session -prefix {$ec}anatr{$s} *
cd ..
end

3) Concatenate and motion correct all runs for ease of processing, also create mask

cd $session

reorder so that it is MT,LO,Aud,RER Tactile for simplicity (posterior to anterior!)
 (4 6 7 9 10 11 12 14 15 )
4: MT
9: LOloc
12: Audloc
6,7,10,11,14,15: Tactile

3dTcat -prefix {$ec}rall {$ec}r4+orig {$ec}r9+orig.HEAD  \
{$ec}r12+orig  {$ec}r6+orig {$ec}r7+orig {$ec}r10+orig {$ec}r11+orig {$ec}r14+orig {$ec}r15+orig 

3dvolreg -base 0 -1Dfile {$ec}vrout -prefix {$ec}rallvr {$ec}rall+orig
1dplot -volreg -dx 2 {$ec}vrout &
3dmerge -doall -1blur_rms 3 -prefix {$ec}rallvrbl {$ec}rallvr+orig 
3dTstat -mean -prefix {$ec}EPIanat {$ec}rallvr+orig
3dAutomask -prefix {$ec}mask {$ec}rallvrbl+orig

3dSkullStrip -input  {$ec}anatr{$anat[1]}+orig -prefix {$ec}anatr{$anat[1]}SS
@auto_tlrc -base TT_icbm452+tlrc -no_ss -input {$ec}anatr{$anat[1]}SS+orig
adwarp -apar {$ec}anatr{$anat[1]}SS_at+tlrc -dpar {$ec}anatr{$anat[1]}+orig

# Go through and resample everything for common viewing: (AFNI MIGHT do it automatically, but worried that
might choose wrong +tlrc transform!)

foreach ds (AVt1EPIanat+orig  AVt1v1decirf+orig  AVt1v2decirf+orig AVt1v1mr+orig AVt1v2mr+orig)
adwarp -apar {$ec}anat1SS_at+tlrc -dpar {$ds} -resam Cu -dxyz 3
end

# stimulus order for MT was L/R regular alternation, for LO was pseudo-random, see
# Tstimseqv7: ['a' 'b' 'b' 'a' 'a' 'b' 'a' 'a' 'b' 'b']

printf  "0 60 120 180 240\n*\n*\n*\n*\n*\n*\n*\n*\n"    > LMTloc.txt
printf  "30 90 150 210 270\n*\n*\n*\n*\n*\n*\n*\n*\n"    > RMTloc.txt

printf "*\n0 90 120 180 210\n*\n*\n*\n*\n*\n*\n*\n" > LOReal.txt
printf "*\n30 60 150 240 270\n*\n*\n*\n*\n*\n*\n*\n" > LOScr.txt

printf "*\n*\n0 30 60 90 120 150 180 210 240 270\n*\n*\n*\n*\n*\n*\n" > Audloc.txt
printf "0\n150\n300\n450\n600\n750\n900\n1050\n1200\n" > runs.txt

# Use 1..2 for tactile only, 1..3 for resp (because of extra stuff)

ran script @3dAX because command line was getting so ridiculously long!
contains 3dDeconvolve command lines for dec (assume BLOCK irf for localizers)
and irf-block (assume TENT irf for localizer)

Concatenate irfs separately and together:
set ec = AX
set v = 1
3dTcat -prefix {$ec}v{$v}BDirf  {$ec}irf1+orig {$ec}irf2+orig {$ec}irf3+orig {$ec}irf4+orig {$ec}irf5+orig  
3dTcat -prefix {$ec}v{$v}decirf  {$ec}irf6+orig {$ec}irf7+orig {$ec}irf8+orig {$ec}irf9+orig {$ec}irf10+orig  

STIMULUS SEQUENCE NOTES

for AG:
optseq2:
set tr = 2.015
set numev = 20
set out = Tstimv1

optseq2 --tsearch 1 \
--nkeep 8 --o {$out} \
--ntp 150 --tr {$tr} \
--polyfit 2 --focb 1 --repvar 10 \
--psdwin 0 16.120  \
--ev S1 {$tr} $numev  \
--ev S2 {$tr} $numev  \
--ev S3 {$tr} $numev  \
--ev S4 {$tr} $numev  \
--ev S5 {$tr} $numev  \
--ev S6 {$tr} $numev  

6*20 of each type=120  + 30 NULL

AU:
STIMULUS SEQUENCE GENERATION
150 events / 4 event types =  37.5

set tr = 2
set numev = 37
set out = AudTac

/Applications/freesurfer/bin/optseq2 --tsearch 1 \
--nkeep 4 --o {$out} \
--ntp 150 --tr {$tr} \
--polyfit 2 --focb 1 --repvar 10 \
--psdwin 0 16  \
--ev TLH {$tr} $numev  \
--ev TRH {$tr} $numev  \
--ev AUD {$tr} $numev  

37*3=111 of each type + 39 NULL

# Next, convert to a text file we can easily cut and paste into a Presentation scenario using Matlab:
see TstimSeqv5.m
created regressors TRH,TLH,AUD.txt

AX: 
next design:
Use 4 main (left/right hand and foot with target (hip)
less for target e.g. 10
4*30,10,20?
4*25,10,40?
4*28,10,28

set tr = 2
set numev = 28
set numtar = 10
set out = TacTarget

/Applications/freesurfer/bin/optseq2 --tsearch 1 \
--nkeep 8 --o {$out} \
--ntp 150 --tr {$tr} \
--polyfit 2 --focb 1 --repvar 10 \
--psdwin 0 16  \
--ev LH {$tr} $numev  \
--ev RH {$tr} $numev  \
--ev LF {$tr} $numev  \
--ev RF {$tr} $numev  \
--ev TG {$tr} $numtar  

~5 minutes per T1 * 3 = 15 minutes
150 TRs * 2 seconds = 5 minutes/run * 6 runs of tactile RER = 30 minutes
(* 28 trials of each type = 170 trials total, quite adequate)
LO Localizer: 2 runs BD * 4 minutes each = 8 minutes
MT Localizer: 1 run BD

Auditory Localizer: 2 runs BD * 4 minutes each = 8 minutes
but might be nice to compare response to tactile stimuli

should be more than adequate

2/27/2007
Try to improve registration by using 3dAllineate

6/19/2007
examined AudvsVis sub-BRIK, discovered a problem with contrast
fixed with /data1/UT/AZ/afni/@3dv7

To look for patchiness, could use a weaker threshold (or just look at all positive voxels)
rm junk*
3dcalc  -prefix junk -a AXSTPv3+orig -expr "step(a)*a"
3drefit -sublabel 0 stepminAVT junk+orig
3dbucket -glueto AXSTPv3+orig -fbuc junk+orig AXv7dec+orig'[121,124,127]'

rm junk*
3dcalc  -prefix junk -a AXtriv2+orig -expr "step(a)*a"
3dcalc  -prefix junk2 -a AXtriv2+orig -expr "step(a)*a"
3drefit -sublabel 0 stepminAVTwholebrain junk+orig
3dbucket -glueto AXSTPv3+orig -fbuc junk+orig 

rm junk*
3dcalc  -prefix junk -a AXtriv2+orig -expr "step(a)*a"
3dcalc  -prefix junk2 -a0 AX_lh_all_Surf2Vol_ROI+orig -b0 AX_rh_all_Surf2Vol_ROI+orig \
 -expr "2*amongst(80,a,b)+1*(1-amongst(80,a,b))"

3drefit -sublabel 0 stepminAVTwholebrain junk+orig
3drefit -sublabel 0 STS2wb1 junk2+orig

3dbucket -glueto AXSTPv3+orig -fbuc junk+orig junk2+orig

AXv7dec+orig'[121,124,127]'

Yes, this works well for Tac vs Aud use colorscale of 8 range = 4

7/12/2007
Make some data to give to Steve LaConte
Just tactile runs; break up AlBl file into individual tactile runs, that's what he wants
]cat runs.txt
0
150
300
450
600
750
900
1050
1200

3dbucket -prefix AXrun1 AXrallAlbl+orig'[450..599]'
3drefit -TR 2 AXrun1+orig

3dbucket -prefix AXrun2 -abuc AXrallAlbl+orig'[600..749]'
3dbucket -prefix AXrun3 -abuc AXrallAlbl+orig'[750..899]'
3dbucket -prefix AXrun4 -abuc AXrallAlbl+orig'[900..1049]'
3dbucket -prefix AXrun5 -abuc AXrallAlbl+orig'[1050..1199]'
3dbucket -prefix AXrun6 -abuc AXrallAlbl+orig'[1200..1349]'
3drefit -TR 2 AXrun?+orig.HEAD

cp LH.txt LeftHand.txt
cp RH.txt RightHand.txt
cp LF.txt LeftFoot.txt
cp RF.txt RightFoot.txt
cp TG.txt Target.txt

7/17/2007
redo deconvolution to make visual vs tactile patches
/Volumes/data1/UT/AZ/afni/@3dv8 AX
3dbucket -glueto {$ec}STPv3+orig {$ec}v8dec+orig'[127,130,133]'
problem: MT is weak in this subject, tactile is strong.
So, do strongest visual stimulus (LOScr) against weakest tactile (ipsi foot)
Could also just do multiples.

cp /Volumes/data1/UT/AZ/afni/@3dv8 ./@3dv9
3dbucket -glueto {$ec}STPv3+orig {$ec}v9dec+orig'[2]'

2/1/2008
Manually draw an S1 ROI, place in
S1ROI.niml.roi

# Must do separately for both hemispheres

3dSurf2Vol  -spec /Volumes/data9/surfaces/barker_kathryn/AX/SUMA/both.spec -surf_A rh.smoothwm.asc -grid_parent AXv6dec+orig -sv AX_SurfVol_Alnd_Exp+orig -map_func max -prefix S1lhROIv5 -sdata_1D S1ROIRH.1D.roi

3dSurf2Vol  -spec /Volumes/data9/surfaces/barker_kathryn/AX/SUMA/both.spec -surf_A lh.smoothwm.asc -grid_parent AXv6dec+orig -sv AX_SurfVol_Alnd_Exp+orig -map_func max -prefix S1lhROIv6 -sdata_1D S1LH.1D.roi

# Now, we combine to make an ROI file where 1=S1HAND, 2=S1FOOT

3dcalc -prefix AXS1 -a S1lhROIv5+orig -b S1lhROIv6+orig -c82 AXv6dec+orig -d109 AXv6dec+orig \
-expr "step(a+b)*step(c-8.4)*(1*step(d-2) + 2*step(-2-d))"

# How many voxels?
3dclust 4 100 AXS1+orig

6/6/2008
Bob Cox suggests using -stim_times_IM but it doesn't work
Give him a simplified version of the data (with just last 6 runs)
3dTcat -prefix AX_TEST AXrallvrbl+orig'[450..$]'

11/3/2008
Make some srfs
 3dcalc -fscale -a AXEPIanatAlbl+orig -b AXv12decirf+orig -prefix AXv12decirfpcnt -expr '100 * b/a * step(1-abs(b/a))'
3dcalc -fscale -a AXEPIanatAlbl+orig -b AXv12decsrf+orig -prefix AXv12decsrfpcnt -expr '100 * b/a * step(1-abs(b/a))'

Next, we want to pick a good voxel in S2 and a good ROI for all voxels in S2.
Voxel ijk 23 48 15 looks good
52.4 -15-2 34.3
x y z
tlrc 50 -39 18

open -a "Microsoft Excel"  023_048_015.1D

Make an S2 ROI
3dcalc -datum byte -prefix AX_R_S2 -a Clust_mask+orig -expr "equals(a,3)"
3dROIstats -quiet -sigma  -mask AX_R_S2+orig AXv12decirfpcnt+orig > AX_S2.1D
open -a "Microsoft Excel"  AX_S2.1D