Skip to content

Commit

Permalink
Merge pull request #452 from vgteam/lancet-integration
Browse files Browse the repository at this point in the history
Add relative path support to local chunk script for Lancet integration
  • Loading branch information
adamnovak authored Aug 13, 2024
2 parents c20f5a9 + e104537 commit c43f161
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions scripts/prepare_local_chunk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ 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
}

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}";;
g) GAM_FILES+=("$OPTARG");;
p) GAM_PALETTES+=("$OPTARG");;
r) REGION="${OPTARG}";;
o) OUTDIR="${OPTARG}";;
b) BASEDIR="${OPTARG}";;
d) DESC="${OPTARG}";;
n) NODE_COLORS+=("${OPTARG}");;
*)
Expand Down Expand Up @@ -53,6 +54,18 @@ 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 "${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
Expand Down Expand Up @@ -146,9 +159,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"

0 comments on commit c43f161

Please sign in to comment.