Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion workflow/envs/qc.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
channels:
- defaults
- bioconda
- conda-forge
dependencies:
Expand Down
3 changes: 1 addition & 2 deletions workflow/envs/wepp.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
channels:
- conda-forge
- defaults
- bioconda
dependencies:
- usher=0.6.3
Expand All @@ -14,4 +13,4 @@ dependencies:
- nginx
- yarn>=1.22
- lsof
- gettext
- gettext
53 changes: 30 additions & 23 deletions workflow/rules/dashboard.smk
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rule process_dashboard:
params:
dashboard=config.get("DASHBOARD_ENABLED", "false"),
bam_file="results/{DIR}/{FILE_PREFIX}_haplotype_reads.bam",
haplotype_bam_file="{FILE_PREFIX}_haplotypes.bam",
haplotype_sam_file="{FILE_PREFIX}_haplotypes.sam",
ref=config["REF"]
conda:
"../envs/wepp.yml"
Expand All @@ -57,11 +57,16 @@ rule process_dashboard:
if [ -f "{params.bam_file}" ]; then
# Split BAM files by read groups
echo "Splitting BAM file by read groups..."
workflow/scripts/split_bams.sh {params.bam_file} ./results/{wildcards.DIR}/bams {workflow.cores}
workflow/scripts/split_bams.sh {params.bam_file} ./results/{wildcards.DIR}/bams {workflow.cores} --force

samtools view -bS -o ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes_.bam ./results/{wildcards.DIR}/{params.haplotype_sam_file}
samtools sort -o ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes.bam ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes_.bam
samtools index ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes.bam

mv ./results/{wildcards.DIR}/{params.haplotype_bam_file} ./results/{wildcards.DIR}/bams/{params.haplotype_bam_file}
mv ./results/{wildcards.DIR}/{params.haplotype_bam_file}.bai ./results/{wildcards.DIR}/bams/{params.haplotype_bam_file}.bai
mv ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes.bam ./results/{wildcards.DIR}/bams/{FILE_PREFIX}_haplotypes.bam
mv ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes.bam.bai ./results/{wildcards.DIR}/bams/{FILE_PREFIX}_haplotypes.bam.bai

rm ./results/{wildcards.DIR}/{FILE_PREFIX}_haplotypes_.bam
rm {params.bam_file}
rm {params.bam_file}.bai
else
Expand Down Expand Up @@ -98,11 +103,9 @@ rule dashboard_serve:

if [ "{params.dashboard}" = "True" ]; then


export WEPP_DASHBOARD_PATH="$(pwd)/runtime"
mkdir -p "$WEPP_DASHBOARD_PATH"


# Check if running inside Docker
if [ -f /.dockerenv ]; then
IN_DOCKER=True
Expand All @@ -120,15 +123,14 @@ rule dashboard_serve:
if [ -f "$WEPP_DASHBOARD_PATH/dashboard.pid" ]; then
DASH_PID=$(cat "$WEPP_DASHBOARD_PATH/dashboard.pid")
if kill -0 "$DASH_PID" 2>/dev/null; then
echo "Existing dashboard running with PID $DASH_PID. Killing it safely."
echo -e "Existing dashboard running with PID $DASH_PID. Killing it safely."
kill -9 "$DASH_PID" || true
else
echo "dashboard.pid found, but process $DASH_PID not running. Cleaning up file."
echo -e "dashboard.pid found, but process $DASH_PID not running. Cleaning up file."
fi
rm -f "$WEPP_DASHBOARD_PATH/dashboard.pid"
fi


read FILENAME MAX_MEM < <( python ./src/Dashboard/taxonium_backend/projects.py \
{wildcards.DIR} {input.taxonium_jsonl} ./results/{wildcards.DIR}/{params.ref})

Expand All @@ -140,14 +142,14 @@ rule dashboard_serve:
echo "Installing backend dependencies..." | tee -a {params.log}
cd src/Dashboard/taxonium_backend/ && yarn install && cd ../../../.

echo "Starting the Node.js server..." | tee -a {params.log}
echo -e "Starting the Node.js server..." | tee -a {params.log}


if [[ "${{FILENAME}}" == *.gz ]]; then
MAX_MEM=$(( MAX_MEM * 10 ))
fi
MAX_MEM=$(( MAX_MEM + 2048 ))
echo "Allocating $MAX_MEM MB for Node.js server ..." | tee -a {params.log}
echo -e "Allocating $MAX_MEM MB for Node.js server ..." | tee -a {params.log}

node --expose-gc --max-old-space-size=$MAX_MEM \
src/Dashboard/taxonium_backend/server.js \
Expand All @@ -156,7 +158,7 @@ rule dashboard_serve:
--config_json src/Dashboard/taxonium_backend/config_public.json &
BACKEND_PID=$!

echo "$BACKEND_PID" > "$WEPP_DASHBOARD_PATH/dashboard.pid"
echo -e "$BACKEND_PID" > "$WEPP_DASHBOARD_PATH/dashboard.pid"

# ──────────────────────────────────────────────
# Wait until Node.js server opens port $BACKEND_PORT
Expand All @@ -170,9 +172,17 @@ rule dashboard_serve:
# Start Nginx if not already in use
# ──────────────────────────────────────────────

if [ -f "$WEPP_DASHBOARD_PATH/nginx.pid" ] && kill -0 "$(cat "$WEPP_DASHBOARD_PATH/nginx.pid")" 2>/dev/null; then
echo "The nginx is already in use. Exiting." | tee -a {params.log}
else
if [ -f "$WEPP_DASHBOARD_PATH/nginx.pid" ]; then
NGINX_PID=$(cat "$WEPP_DASHBOARD_PATH/nginx.pid")
if kill -0 "$NGINX_PID" 2>/dev/null; then
echo "Existing nginx running with PID $NGINX_PID. Killing it safely." | tee -a {params.log}
kill -9 "$NGINX_PID" || true
kill -9 $((NGINX_PID + 1)) || true
else
echo "nginx.pid found, but process $NGINX_PID not running. Cleaning up file."
rm -f "$WEPP_DASHBOARD_PATH/nginx.pid"
fi
fi
echo "Starting dashboard..." | tee -a {params.log}

mkdir -p "$WEPP_DASHBOARD_PATH/Dashboard" "$WEPP_DASHBOARD_PATH/results"
Expand All @@ -183,13 +193,10 @@ rule dashboard_serve:

# Check if running inside Docker
if [ "$IN_DOCKER" = "True" ]; then
echo "Running inside Docker container." | tee -a {params.log}
export USER_DIRECTIVE="user root";
export FRONTEND_PORT=80

else
echo "Not running inside Docker container." | tee -a {params.log}

source workflow/scripts/find_free_port.sh
export USER_DIRECTIVE="# not user root";
export FRONTEND_PORT=$(find_free_port)
Expand All @@ -203,18 +210,18 @@ rule dashboard_serve:
nginx -c $WEPP_DASHBOARD_PATH/wepp-nginx.conf &

until lsof -i :$FRONTEND_PORT >/dev/null 2>&1; do
echo "Waiting for nginx to start on port $FRONTEND_PORT..."
echo -e "Waiting for nginx to start on port $FRONTEND_PORT..."
sleep 1
done
if lsof -i :$FRONTEND_PORT >/dev/null 2>&1; then
echo "🎉 Workflow completed! Dashboard is running at http://localhost:$FRONTEND_PORT (or your forwarded host port).\\n"
echo -e "\n\n\nWORKFLOW COMPLETED! DASHBOARD IS RUNNING AT http://localhost:$FRONTEND_PORT (OR YOUR FORWARDED HOST PORT).\n\n\n"
else
echo "Workflow completed, but dashboard not detected on port $FRONTEND_PORT. \\n"
echo -e "\n\n\nWORKFLOW COMPLETED, BUT DASHBOARD NOT DETECTED ON PORT $FRONTEND_PORT. \n\n\n"
fi
fi

else
rm -f {input.taxonium_jsonl}
echo "Workflow completed! To run the dashboard, set DASHBOARD_ENABLED=True and rerun the workflow with --forcerun dashboard_serve.\\n"
echo -e "\n\n\nWorkflow completed! To run the dashboard, set DASHBOARD_ENABLED=True and rerun the workflow with --forcerun dashboard_serve.\n\n\n"

fi

Expand Down