Skip to content

Commit

Permalink
do not remap if already matches anonymized -- workaround around oddit…
Browse files Browse the repository at this point in the history
…y of heudiconv
  • Loading branch information
yarikoptic committed Jan 25, 2023
1 parent c76737f commit df3811f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions utils/anon-cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ if [ ! -e "$anon_file" ]; then
touch "$anon_file" # initiate it
fi

# apparently heudiconv passes even those we provided in `-s` CLI option
# to anonymization script. So, we will have to match those by our format
# and then give back if matches. That would forbid plain remapping though if
# original ids are in the same format, so some folks might want to disable that!
sid_input_fmted=$(echo "$sid" | sed -e 's,^0*,,g' | xargs printf "$anon_fmt" 2>&1 || :)
if [ "$sid" = "$sid_input_fmted" ]; then
debug already in the anonymized format
echo "$sid"
exit 0
fi

res=$(grep "^$sid," "$anon_file" | head -n 1)
if [ -n "$res" ]; then
ann="${res##*,}"
debug "Found $ann in '$res'"
else
echo "We have all sids mapped already! Will not create a new one for $sid" >&2; exit 1
# need to take the latest one
largest=$(sed -e 's/.*,//g' "$anon_file" | sort -n | tail -n1 | sed -e 's,^0*,,g')
next=$((largest+1))
Expand Down

0 comments on commit df3811f

Please sign in to comment.