reg2std4feat 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. set -e
  12. set -u
  13. tntdir="$1"
  14. shift
  15. inspace="$1"
  16. shift
  17. stdspace="$1"
  18. shift
  19. for featdir in $@; do
  20. subj="$(echo $featdir| sed -e 's,.*\(sub-.*\)/.*,\1,g')"
  21. tntsubdir="${tntdir}/${subj}"
  22. # sane defaults
  23. tmpl2std_mat="$FSLDIR/etc/flirtsch/ident.mat"
  24. tmpl2std_warp=""
  25. # cleanup existing standard space registration
  26. [ -d "$featdir/reg_standard" ] && rm -rf "$featdir/reg_standard" || true
  27. # place reg info in existing featdir in a way that featregapply would
  28. # swallow it
  29. regdir="$featdir/reg"
  30. mkdir -p "$regdir"
  31. # remove any possibly existing standard space setup
  32. rm -rf "$regdir"/*standard*
  33. if [ "$inspace" != "$stdspace" ]; then
  34. xfmdir="$tntsubdir/$inspace/in_$stdspace"
  35. # check that we have the xfm info
  36. [ $(imtest "$xfmdir/head") -eq 1 ] && : || echo "cannot find transformation"
  37. if [ -e "$xfmdir/xfm_12dof.mat" ]; then
  38. tmpl2std_mat="$xfmdir/xfm_12dof.mat"
  39. fi
  40. if [ $(imtest "$xfmdir/subj2tmpl_warp") -eq 1 ]; then
  41. tmpl2std_warp="$xfmdir/subj2tmpl_warp"
  42. fi
  43. imcp "$xfmdir/head" "$regdir/standard"
  44. else
  45. # we stay in the
  46. imcp "$tntsubdir/$inspace/brain" "$regdir/standard"
  47. fi
  48. if [ -e "$regdir/example_func2highres.mat" ]; then
  49. convert_xfm -omat "$regdir/example_func2standard.mat" \
  50. -concat "$tmpl2std_mat" \
  51. "$regdir/example_func2highres.mat"
  52. else
  53. cp "$tmpl2std_mat" "$regdir/example_func2highres.mat"
  54. cp "$tmpl2std_mat" "$regdir/example_func2standard.mat"
  55. fi
  56. if [ -n "$tmpl2std_warp" ]; then
  57. imcp "$tmpl2std_warp" "$regdir/highres2standard_warp"
  58. fi
  59. done