-
Notifications
You must be signed in to change notification settings - Fork 9
/
bids_funcs.sh
87 lines (63 loc) · 1.65 KB
/
bids_funcs.sh
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
# helper functions
#set -e
#set -x
function bids_phaseencode_check {
# check that any x,y,z direction is replaced with i,j,k
inJSON=$1
pedVal=$( jq -r ".PhaseEncodingDirection" ${inJSON} )
if [[ ${pedVal} =~ [xyz] ]] ; then
# brute replace
# echo "changing the x,y,z to i,j,k"
pedVal=$(echo ${pedVal} | sed s,x,i, )
pedVal=$(echo ${pedVal} | sed s,y,j, )
pedVal=$(echo ${pedVal} | sed s,z,k, )
echo $(jq -r '.PhaseEncodingDirection="'${pedVal}'"' ${inJSON}) > ${inJSON}
fi
}
function bids_namekeyvals {
local baseName=$1
local inJSON=$2
local inPARAMS="${3}"
# let's just take in session
local session=$4
# ses added manually
if [[ -n ${session} ]] ; then
baseName="${baseName}_ses-${session}"
fi
for addparam in ${inPARAMS} ; do
# be flexible for fullname
fullname=$(bids_short_to_fullname ${addparam})
tmpval=$( jq -r ".meta.${addparam}" ${inJSON} )
if [[ ${tmpval} = "null" ]] ; then
# if fullname alternatives exists, try once more
for ff in $(echo ${fullname}) ; do
tmpval=$( jq -r ".meta.${ff}" ${inJSON} )
if [[ ${tmpval} != "null" ]] ; then
break
fi
done
fi
# add to basename
if [[ ${tmpval} != "null" ]] ; then
baseName="${baseName}_${addparam}-${tmpval}"
fi
done
# output the basename
echo "${baseName}"
}
function bids_short_to_fullname {
# populate with fullnames.
inShort=$1
outFull=''
case ${inShort} in
acq )
outFull="Acquisition acquisition" ;;
rec )
outFull="Reconstruction reconstruction" ;;
dir )
outFull="Direction direction" ;;
task )
outFull="TaskName Taskname taskname" ;;
esac
echo "$outFull"
}