-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsoncrawler.sh
66 lines (58 loc) · 1.63 KB
/
jsoncrawler.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
#!/bin/bash
#
#single-sub single-session script for adding intended for statements to fmap jsons before running BIDS apps
# requires JQ
#usage: jsoncrawler.sh {bids directory} {session} {subject}
#
#pbc
#example: jsoncrawler.sh {projectFolder}/{projectBIDSoutputFromHeuDiConv} ses-01
sesname=$2
seslen=${#sesname}
sub=$3
seshs=($1/${sub}/${sesname})
for sesh in ${seshs[@]}; do
cd $sesh
restfuncmaps=(./fmap/*rest*json)
restfuncs=(./func/*rest*bold*nii.gz)
for restfuncmap in ${restfuncmaps[@]}; do
img=${restfuncs:1}
jq '.IntendedFor' $restfuncmap > tmpj
if [[ $(cat tmpj) == "${sesname}${img}" ]];
then
echo "IntendedFor found as "${sesname}$img""
exit 0
else
# replace the following with jq or jo
cat $restfuncmap | jq '.IntendedFor |= "${sesname}$img"' > tmp
mv tmp $restfuncmap
fi
done
taskfuncmaps=`find ./fmap -maxdepth 2 -type f \( -iname "*nback*json" -a -not -iname "*rest*" \)`
taskfuncs=`find ./func -maxdepth 2 -type f \( -iname "*nback*bold*nii.gz" -a -not -iname "*rest*" \)`
for taskfuncmap in ${taskfuncmaps[@]}; do
img=${taskfuncs:1}
# taskprefix=${taskfuncmap#*task-*}
# taskname="${taskprefix%%_*}"
task="*nback*"
if [[ "$img" == "$task" ]];
then
cat $taskfuncmap | jq '.IntendedFor |= "${sesname}$img"' > tmp
mv tmp $taskfuncmap
fi
done
dwimaps=(./fmap/*dwi*json)
dwis=(./dwi/*dwi*nii.gz)
for dwimap in ${dwimaps[@]}; do
img=${dwis:1}
jq '.IntendedFor' $dwimap > tmpj
if [[ $(cat tmpj) == "${sesname}$img" ]];
then
echo "IntendedFor found as "${sesname}$img""
exit 0
else
cat $dwimap | jq '.IntendedFor |= "${sesname}$img"' > tmp
mv tmp $dwimap
fi
done
done
rm -f tmpj