reg2std4feat 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. #
  3. # Usage: reg2std4feat <tntdir> <inspace> <stdspace> <feat_dir> [<feat_dir> ...]
  4. #
  5. # Example: reg2std4feat src/tnt/ bold3Tp2 grpbold3Tp2 sub-/run*_testme.feat
  6. #
  7. # This script makes the assumption that there is no highres space, but
  8. # alignment was performed from BOLD directly to a group template (most
  9. # likely computed from BOLD as well)
  10. #
  11. # code/reg2std4feat src/templatesntransforms/ bold3Tp2 grpbold3Tp2 sub-*/run-*.feat
  12. set -e
  13. set -u
  14. tntdir="$1"
  15. shift
  16. inspace="$1"
  17. shift
  18. stdspace="$1"
  19. shift
  20. for featdir in $@; do
  21. subj="$(echo $featdir| sed -e 's,.*\(sub-.*\)/.*,\1,g')"
  22. echo $subj
  23. tntsubdir="${tntdir}/${subj}"
  24. # sane defaults
  25. tmpl2std_mat="$FSLDIR/etc/flirtsch/ident.mat"
  26. tmpl2std_warp=""
  27. # cleanup existing standard space registration
  28. [ -d "$featdir/reg_standard" ] && rm -rf "$featdir/reg_standard" || true
  29. # place reg info in existing featdir in a way that featregapply would
  30. # swallow it
  31. regdir="$featdir/reg"
  32. mkdir -p "$regdir"
  33. # remove any possibly existing standard space setup
  34. rm -rf "$regdir"/*standard*
  35. if [ "$inspace" != "$stdspace" ]; then
  36. xfmdir="$tntsubdir/$inspace/in_$stdspace"
  37. # check that we have the xfm info
  38. [ $(imtest "$xfmdir/head") -eq 1 ] && : || echo "cannot find transformation"
  39. if [ -e "$xfmdir/xfm_12dof.mat" ]; then
  40. tmpl2std_mat="$xfmdir/xfm_12dof.mat"
  41. fi
  42. if [ $(imtest "$xfmdir/subj2tmpl_warp") -eq 1 ]; then
  43. tmpl2std_warp="$xfmdir/subj2tmpl_warp"
  44. fi
  45. imcp "$xfmdir/head" "$regdir/standard"
  46. else
  47. # we stay in the
  48. imcp "$tntsubdir/$inspace/brain" "$regdir/standard"
  49. fi
  50. if [ -e "$regdir/example_func2highres.mat" ]; then
  51. convert_xfm -omat "$regdir/example_func2standard.mat" \
  52. -concat "$tmpl2std_mat" \
  53. "$regdir/example_func2highres.mat"
  54. else
  55. cp "$tmpl2std_mat" "$regdir/example_func2highres.mat"
  56. cp "$tmpl2std_mat" "$regdir/example_func2standard.mat"
  57. fi
  58. if [ -n "$tmpl2std_warp" ]; then
  59. imcp "$tmpl2std_warp" "$regdir/highres2standard_warp"
  60. fi
  61. done