run.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # This is a short script that runs the desired script through the correct conda environment, assuming `conda` is in path.
  3. # The environments are specified in `env/`.
  4. # check for arguments
  5. if [ $# -eq 0 ]
  6. then
  7. echo "File not specified! The first argument should be a .py or .R script"
  8. exit 1
  9. fi
  10. # check first argument is a file that exists
  11. if [ ! -f $1 ]; then
  12. echo "File not found! Expected first argument to be a .py or .R script"
  13. exit 1
  14. fi
  15. # extract file name and extension
  16. filename=$(basename -- "$1")
  17. extension="${filename##*.}"
  18. extension_lwr="${extension,,}"
  19. filename="${filename%.*}"
  20. # identify language from file extension
  21. if [ $extension_lwr = "py" ]
  22. then
  23. # identify which environment to use based on filename
  24. if [ "$filename" = "00_get_orth_model_rdms" ]
  25. then
  26. env="rdms"
  27. elif [ "$filename" = "01_get_corpus_model_rdms" ]
  28. then
  29. env="rdms"
  30. elif [ "$filename" = "02_preprocessing" ]
  31. then
  32. env="mne"
  33. elif [ "$filename" = "03_get_neural_rdms" ]
  34. then
  35. env="mne"
  36. # these are the two visualisation scripts that use the mne environment
  37. elif [ "$filename" = "99_plot_ica_N_change_examples" ]
  38. then
  39. env="mne"
  40. elif [ "$filename" = "99_plot_ica_filter_change_examples" ]
  41. then
  42. env="mne"
  43. else
  44. # every other python script (probably) uses rdms environment
  45. echo "Assuming rdms as Python env"
  46. env="rdms"
  47. fi
  48. # run script
  49. conda run -n $env --no-capture-output python $1
  50. elif [ $extension_lwr = "r" ]
  51. then
  52. # only one environment for R scripts
  53. conda run -n r --no-capture-output Rscript $1
  54. else
  55. echo "Expected file with .py or .R extension"
  56. exit 1
  57. fi