From f1b1952d1460f3707dbd248819c0cded46b04852 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 13 Aug 2024 12:28:35 -0700 Subject: [PATCH 1/3] Allow preparing a local chunk to produce a BED path from somewhere other than the current directory --- scripts/prepare_local_chunk.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/prepare_local_chunk.sh b/scripts/prepare_local_chunk.sh index 63d813c5..5f5a3c53 100755 --- a/scripts/prepare_local_chunk.sh +++ b/scripts/prepare_local_chunk.sh @@ -4,7 +4,7 @@ set -e function usage() { echo >&2 "${0}: Prepare a tube map chunk and BED line on standard output from a pre-made subgraph. Only supports paths, not haplotypes." echo >&2 - echo >&2 "Usage: ${0} -x subgraph.xg -r chr1:1-100 [-d 'Description of region'] [-n 123 [-n 456]] -o chunk-chr1-1-100 [-g mygam1.gam [-p '{\"mainPalette\": \"blues\", \"auxPalette\": \"reds\"}'] [-g mygam2.gam [-p ...] ...]] >> regions.bed" + echo >&2 "Usage: ${0} -x subgraph.xg -r chr1:1-100 [-d 'Description of region'] [-n 123 [-n 456]] -o chunk-chr1-1-100 [-g mygam1.gam [-p '{\"mainPalette\": \"blues\", \"auxPalette\": \"reds\"}'] [-g mygam2.gam [-p ...] ...]] [-b /output/directory/prefix/to/remove] >> regions.bed" exit 1 } @@ -20,6 +20,7 @@ do p) GAM_PALETTES+=("$OPTARG");; r) REGION="${OPTARG}";; o) OUTDIR="${OPTARG}";; + b) BASEDIR="${OPTARG}";; d) DESC="${OPTARG}";; n) NODE_COLORS+=("${OPTARG}");; *) @@ -53,6 +54,12 @@ if [[ -z "${OUTDIR}" ]] ; then usage fi +if [[ ! -z "${BASEDIR}" && "${OUTDIR}" != "${BASEDIR}"* ]] ; then + echo >&2 "Base directory from -b is not a prefix of out directory from -o" + echo >&2 + usage +fi + if [[ -z "${DESC}" ]] ; then DESC="Region ${REGION}" fi @@ -146,9 +153,16 @@ do printf "$file\n" >> "$OUTDIR/chunk_contents.txt" done +# Work out how the BED should refer to the OUTDIR +PATH_TO_OUTDIR="${OUTDIR}" +if [[ ! -z "${BASEDIR}" ]] ; then + # Remove BASEDIR from the front of OUTDIR + PATH_TO_OUTDIR="${OUTDIR#"$BASEDIR"}" +fi + # Print BED line cat "$OUTDIR/regions.tsv" | cut -f1-3 | tr -d "\n" -printf "\t${DESC}\t${OUTDIR}\n" +printf "\t${DESC}\t${PATH_TO_OUTDIR}\n" rm -fr "$TEMP" From 432c7d2069144f5dd54e6d839e6d3e96600c132a Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 13 Aug 2024 12:31:02 -0700 Subject: [PATCH 2/3] Require trailing slash --- scripts/prepare_local_chunk.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/prepare_local_chunk.sh b/scripts/prepare_local_chunk.sh index 5f5a3c53..d7b09e56 100755 --- a/scripts/prepare_local_chunk.sh +++ b/scripts/prepare_local_chunk.sh @@ -60,6 +60,12 @@ if [[ ! -z "${BASEDIR}" && "${OUTDIR}" != "${BASEDIR}"* ]] ; then usage fi +if [[ ! -z "${BASEDIR}" && "${BASEDIR}" != *"/" ]] ; then + echo >&2 "Base directory from -b does not end with a slash" + echo >&2 + usage +fi + if [[ -z "${DESC}" ]] ; then DESC="Region ${REGION}" fi From e1045379c854aecb8f5b0c9f19af2413f7108bee Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 13 Aug 2024 12:36:56 -0700 Subject: [PATCH 3/3] Note b option existence for option parsing --- scripts/prepare_local_chunk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/prepare_local_chunk.sh b/scripts/prepare_local_chunk.sh index d7b09e56..c1f27a44 100755 --- a/scripts/prepare_local_chunk.sh +++ b/scripts/prepare_local_chunk.sh @@ -12,7 +12,7 @@ GAM_FILES=() GAM_PALETTES=() NODE_COLORS=() -while getopts x:g:p:r:o:d:n: flag +while getopts x:g:p:r:o:b:d:n: flag do case "${flag}" in x) GRAPH_FILE="${OPTARG}";;