1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/bash
- # This is a short script that runs the desired script through the correct conda environment, assuming `conda` is in path.
- # The environments are specified in `env/`.
- # check for arguments
- if [ $# -eq 0 ]
- then
- echo "File not specified! The first argument should be a .py or .R script"
- exit 1
- fi
- # check first argument is a file that exists
- if [ ! -f $1 ]; then
- echo "File not found! Expected first argument to be a .py or .R script"
- exit 1
- fi
- # extract file name and extension
- filename=$(basename -- "$1")
- extension="${filename##*.}"
- extension_lwr="${extension,,}"
- filename="${filename%.*}"
- # identify language from file extension
- if [ $extension_lwr = "py" ]
- then
- # identify which environment to use based on filename
- if [ "$filename" = "00_get_orth_model_rdms" ]
- then
- env="rdms"
- elif [ "$filename" = "01_get_corpus_model_rdms" ]
- then
- env="rdms"
- elif [ "$filename" = "02_preprocessing" ]
- then
- env="mne"
- elif [ "$filename" = "03_get_neural_rdms" ]
- then
- env="mne"
- # these are the two visualisation scripts that use the mne environment
- elif [ "$filename" = "99_plot_ica_N_change_examples" ]
- then
- env="mne"
- elif [ "$filename" = "99_plot_ica_filter_change_examples" ]
- then
- env="mne"
- else
- # every other python script (probably) uses rdms environment
- echo "Assuming rdms as Python env"
- env="rdms"
- fi
- # run script
- conda run -n $env --no-capture-output python $1
- elif [ $extension_lwr = "r" ]
- then
- # only one environment for R scripts
- conda run -n r --no-capture-output Rscript $1
- else
- echo "Expected file with .py or .R extension"
- exit 1
- fi
|