From 63265008b106fe3309595fdf85e2b75898919387 Mon Sep 17 00:00:00 2001 From: Pedro Madrigal <8195212+pmb59@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:02:53 +0100 Subject: [PATCH] dirname: missing operand error in SCXA loading due to undefined $BASH_SOURCE (#68) * Update load_db_scxa_dimred.sh * using ${BASH_SOURCE:-$0} to avoid cases where BASH_SOURCE is not defined * edit SCRATCH_DIR in bin/load_db_scxa_dimred.sh * Related to PR #66 --- bin/add_exps_to_collection.sh | 2 +- bin/create_collection.sh | 2 +- bin/delete_collection.sh | 2 +- bin/delete_exp_from_collection.sh | 2 +- bin/get_experiment_info.sh | 2 +- bin/load_db_scxa_analytics.sh | 2 +- bin/load_db_scxa_analytics_pg9.sh | 2 +- bin/load_db_scxa_cell_clusters.sh | 2 +- bin/load_db_scxa_dimred.sh | 5 +++-- bin/load_db_scxa_marker_genes.sh | 2 +- bin/load_exp_design.sh | 2 +- bin/load_experiment_web_cli.sh | 2 +- bin/modify_collection.sh | 2 +- bin/update_experiment_web_cli.sh | 2 +- fixtures/generate-fixtures.sh | 2 +- fixtures/generate-tsv-fixture.sh | 2 +- tests/run_tests.sh | 4 ++-- tests/test_dimred_load.sh | 4 ++-- 18 files changed, 22 insertions(+), 21 deletions(-) diff --git a/bin/add_exps_to_collection.sh b/bin/add_exps_to_collection.sh index 3a7bd0e..e2c7429 100755 --- a/bin/add_exps_to_collection.sh +++ b/bin/add_exps_to_collection.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/create_collection.sh b/bin/create_collection.sh index bc88cf1..db11521 100755 --- a/bin/create_collection.sh +++ b/bin/create_collection.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/delete_collection.sh b/bin/delete_collection.sh index 546b927..2a8fab2 100755 --- a/bin/delete_collection.sh +++ b/bin/delete_collection.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/delete_exp_from_collection.sh b/bin/delete_exp_from_collection.sh index c6d43a8..dcf0624 100755 --- a/bin/delete_exp_from_collection.sh +++ b/bin/delete_exp_from_collection.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/get_experiment_info.sh b/bin/get_experiment_info.sh index 4096cf1..d2bb3a1 100755 --- a/bin/get_experiment_info.sh +++ b/bin/get_experiment_info.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh postgres_scripts_dir=$scriptDir/../postgres_routines diff --git a/bin/load_db_scxa_analytics.sh b/bin/load_db_scxa_analytics.sh index 05779a7..18c6348 100755 --- a/bin/load_db_scxa_analytics.sh +++ b/bin/load_db_scxa_analytics.sh @@ -12,7 +12,7 @@ # - Postprocess table and attach it to the main scxa-analytics table. set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh postgres_scripts_dir=$scriptDir/../postgres_routines diff --git a/bin/load_db_scxa_analytics_pg9.sh b/bin/load_db_scxa_analytics_pg9.sh index ca89825..95ec151 100755 --- a/bin/load_db_scxa_analytics_pg9.sh +++ b/bin/load_db_scxa_analytics_pg9.sh @@ -10,7 +10,7 @@ # PG10, which loads each experiment into a different partition. set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/load_db_scxa_cell_clusters.sh b/bin/load_db_scxa_cell_clusters.sh index 7c1c4d7..dff3bf2 100755 --- a/bin/load_db_scxa_cell_clusters.sh +++ b/bin/load_db_scxa_cell_clusters.sh @@ -5,7 +5,7 @@ # scxa_cell_group_membership table of AtlasProd. set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/load_db_scxa_dimred.sh b/bin/load_db_scxa_dimred.sh index 31f17b6..e0ed5ba 100755 --- a/bin/load_db_scxa_dimred.sh +++ b/bin/load_db_scxa_dimred.sh @@ -5,7 +5,7 @@ # parameterisations, and loads it into the scxa_coords table of AtlasProd. set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} @@ -13,7 +13,8 @@ EXP_ID=${EXP_ID:-$2} DIMRED_TYPE=${DIMRED_TYPE:-$3} DIMRED_FILE_PATH=${DIMRED_FILE_PATH:-$4} DIMRED_PARAM_JSON=${DIMRED_PARAM_JSON:-$5} -SCRATCH_DIR=${SCRATCH_DIR:-"$(dirname ${DIMRED_FILE_PATH})"} +#SCRATCH_DIR=${SCRATCH_DIR:-"$(dirname ${DIMRED_FILE_PATH})"} +SCRATCH_DIR=${SCRATCH_DIR:-"$DIMRED_FILE_PATH"} # Check that necessary environment variables are defined. [ -n ${dbConnection+x} ] || (echo "Env var dbConnection for the database connection needs to be defined. This includes the database name." && exit 1) diff --git a/bin/load_db_scxa_marker_genes.sh b/bin/load_db_scxa_marker_genes.sh index 89067fb..dc70d05 100755 --- a/bin/load_db_scxa_marker_genes.sh +++ b/bin/load_db_scxa_marker_genes.sh @@ -6,7 +6,7 @@ # scxa_cell_groups_marker_genes table of AtlasProd. set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/load_exp_design.sh b/bin/load_exp_design.sh index 6ed6458..bd86df3 100755 --- a/bin/load_exp_design.sh +++ b/bin/load_exp_design.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +scriptDir=$(cd "$( dirname "${BASH_SOURCE[0]:-$0}" )" && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/load_experiment_web_cli.sh b/bin/load_experiment_web_cli.sh index d0cebc6..f550dbb 100755 --- a/bin/load_experiment_web_cli.sh +++ b/bin/load_experiment_web_cli.sh @@ -11,7 +11,7 @@ jar_dir=$CONDA_PREFIX/share/atlas-cli -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/common_routines.sh echo "CONDA_PREFIX: $CONDA_PREFIX" diff --git a/bin/modify_collection.sh b/bin/modify_collection.sh index e7f08e4..2ca68be 100755 --- a/bin/modify_collection.sh +++ b/bin/modify_collection.sh @@ -2,7 +2,7 @@ set -e -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/db_scxa_common.sh dbConnection=${dbConnection:-$1} diff --git a/bin/update_experiment_web_cli.sh b/bin/update_experiment_web_cli.sh index 2c6d8fa..bd2c7bf 100755 --- a/bin/update_experiment_web_cli.sh +++ b/bin/update_experiment_web_cli.sh @@ -11,7 +11,7 @@ jar_dir=$CONDA_PREFIX/share/atlas-cli -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) source $scriptDir/common_routines.sh echo "CONDA_PREFIX: $CONDA_PREFIX" diff --git a/fixtures/generate-fixtures.sh b/fixtures/generate-fixtures.sh index 840a621..dbd91f8 100755 --- a/fixtures/generate-fixtures.sh +++ b/fixtures/generate-fixtures.sh @@ -22,7 +22,7 @@ # https://stackoverflow.com/questions/59895/how-can-i-get-the-source-directory-of-a-bash-script-from-within-the-script-itsel # https://stackoverflow.com/a/246128 -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd )" export POSTGRES_HOST=${POSTGRES_HOST:-localhost} export POSTGRES_PORT=${POSTGRES_PORT:-5432} diff --git a/fixtures/generate-tsv-fixture.sh b/fixtures/generate-tsv-fixture.sh index e55bf4b..8bf89eb 100755 --- a/fixtures/generate-tsv-fixture.sh +++ b/fixtures/generate-tsv-fixture.sh @@ -10,7 +10,7 @@ # We choose 100 genes that are expressed in those cells via analytics table set -e -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd )" source ${SCRIPT_DIR}/utils.sh diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 02a8f18..9b7dc55 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +scriptDir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd ) export testsDir=$scriptDir export PATH=$scriptDir/../bin:$scriptDir/../tests:$PATH @@ -29,7 +29,7 @@ chmod -R a+w /tmp/fixtures/experiment_files/expdesign if [ "$#" -eq 0 ]; then - bats --tap "$(dirname "${BASH_SOURCE[0]}")" + bats --tap "$(dirname "${BASH_SOURCE[0]:-$0}")" else bats random-data-set.bats fi diff --git a/tests/test_dimred_load.sh b/tests/test_dimred_load.sh index e9f2c1b..46e1dc3 100755 --- a/tests/test_dimred_load.sh +++ b/tests/test_dimred_load.sh @@ -6,7 +6,7 @@ delete_db_scxa_dimred.sh # do it just for testing ls ${EXPERIMENT_DIMRED_PATH}/${EXP_ID}.tsne*.tsv | while read -r l; do - export DIMRED_TYPE=tsne + export DIMRED_TYPE=t-SNE export DIMRED_FILE_PATH=$l paramval=$(echo "$l" | sed 's/.*[^0-9]\([0-9]*\).tsv/\1/g') export DIMRED_PARAM_JSON='[{"perplexity": '$paramval'}]' @@ -14,7 +14,7 @@ ls ${EXPERIMENT_DIMRED_PATH}/${EXP_ID}.tsne*.tsv | while read -r l; do done ls ${EXPERIMENT_DIMRED_PATH}/${EXP_ID}.umap*.tsv | while read -r l; do - export DIMRED_TYPE=umap + export DIMRED_TYPE=UMAP export DIMRED_FILE_PATH=$l paramval=$(echo "$l" | sed 's/.*[^0-9]\([0-9]*\).tsv/\1/g') export DIMRED_PARAM_JSON='[{"n_neighbors": '$paramval'}]'