-
Notifications
You must be signed in to change notification settings - Fork 1
/
drive_afni_xyz
executable file
·123 lines (106 loc) · 3.27 KB
/
drive_afni_xyz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
set -e
#MH April 2015
#This is a script to send coordinates to AFNI for navigating through a file in which rows contains ROIs/coordinates of interest.
#For example the output of a 3dclust command can be used to navigate to each of the clusters on the command line.
#This depends on AFNI plugouts being turned on/available.
if [ $# -eq 0 ]; then
echo "Usage: drive_afni_xyz -coord_file <file with xyz coords> -lr <left/right column> -pa <posterior/anterior column> -is <inferior/superior column>"
exit 0
fi
#cleanup tmpfile on quit/exist
trap "rm -f .tmpfile" EXIT SIGHUP SIGINT SIGTERM
coord_file=
lrcol=1 #defaults
pacol=2
iscol=3
lpi=1 #only support LPI coords at the moment...
comment_char="#" #default to # as comment
image_file=
delim="\t" #default
while [ _$1 != _ ] ; do
if [ $1 = -coord_file ]; then
coord_file="$2"
shift 2
elif [ $1 = -image_file ]; then
image_file="$2"
shift 2
elif [ $1 = -lr ]; then
lrcol=$2
shift 2
elif [ $1 = -pa ]; then
pacol=$2
shift 2
elif [ $1 = -is ]; then
iscol=$2
shift 2
elif [[ $1 = -lpi || $1 = -spm ]]; then
lpi=1
shift 1
elif [ $1 = -delim ]; then
delim="$2"
shift 2
elif [ $1 = -comment_char ]; then
comment_char="$2"
shift 2
else
echo "Don't know what this means: $1"
exit 1
fi
done
if [ -n "$image_file" ]; then
if [ -r "$image_file" ]; then
plugout_drive -com "SET_FUNCTION $image_file" -quit 2>&1 >/dev/null
else
echo "Cannot locate -image_file $image_file"
exit 1
fi
fi
echo "Assuming coordinates are in LPI order."
#remove any comment lines
sed "/^${comment_char}/ d" < "${coord_file}" > .tmpfile
#tail -n +2 "$extremaFile" > .tmpfile
#3dclust does not write a trailing newline at the end of the file.
#Consequently, read chokes on the file (error = 1), but this is a trivial error.
#thus, trap and ignore
OLDIFS=$IFS
IFS=$'\n' read -d '' -r -a lines < .tmpfile || eof=true
IFS=$OLDIFS
echo "length of lines is ${#lines[@]}"
echo "first line is ${lines[0]}"
nlines=${#lines[@]}
curline=0
while [ $curline -lt $nlines ]
do
repline=$( echo "${lines[$curline]}" | perl -pe "s/${delim}/ /g")
echo "$((curline+1)): ${repline}"
echo ""
xyz=$( echo "${lines[$curline]}" | awk -F"${delim}" "{print \$${lrcol},\$${pacol},\$${iscol}}" )
plugout_drive -com "SET_SPM_XYZ ${xyz}" -quit 2>&1 >/dev/null
read -sn1 -p "Press # to enter rownum, n for next, p for previous, r for reload, q for quit" key
echo ""
if [ $key = p ]; then
[ "$curline" -gt 0 ] && curline=$((curline - 1))
elif [ $key = q ]; then
echo "Quitting"
exit 0
elif [ $key = r ]; then
plugout_drive -com "SET_SPM_XYZ ${xyz}" -quit 2>&1 >/dev/null
elif [ $key = "#" ]; then
read -p "Enter goto row: " row
curline=$((row - 1)) #account for 0-based index
elif [ $key = n ]; then
[ $curline -lt $(( nlines - 1 )) ] && curline=$((curline + 1))
else
curline=$((curline + 1)) #default to next
fi
done
#need to read in file through different i/o stream 9
#otherwise, read command for prompts will collide with file lines
# while read -u 9 line
# do
# echo -e "\n\n$line"
# xyz=$( echo "$line" | awk '{print $5,$6,$7}' )
# plugout_drive -com "SET_SPM_XYZ ${xyz}" -quit 2>&1 >/dev/null
# read -sn1 -p "Press enter to go to the next activation"
# done 9< .tmpfile