TCP-Lab / x.FASTQ

Bash wrapper modules for the remote analysis of RNA-Seq data, with persistency features.
MIT License
2 stars 0 forks source link

Make background execution of the main statements optional to enable pipelining. #26

Open Feat-FeAR opened 6 months ago

Feat-FeAR commented 6 months ago

Given the hard-coded background execution of most x.FASTQ modules, it is currently not possible to use command sequences for creating automated pipelines. On the contrary, before launching each module, it is necessary to ensure that the previous one has successfully terminated.

See, for instance, here

Feat-FeAR commented 6 months ago

This is my proposal (already tested... it seems to work well !)

#!/bin/bash

# true-false boolean flag
pipeline=$1

# Implementation of a conditional nohup in background that also applies to functions.
function _NUhup {
    log_file="$1"
    if $pipeline; then
        ("${@:2:$#}" | tee -a "${log_file}")
    else
        (trap '' HUP; "${@:2:$#}" >> "${log_file}" 2>&1 &)
    fi
}

# --- Minimal usage example ----------------------------------------------------

# Get local x.FASTQ installation path 
xpath="$(dirname "$(realpath "$(which getfastq)")")"

gene_names=true
level="genes"
design="NA"
metric="TPM"
raw=false
target_dir="$(realpath "${PWD}")"

# MAIN STATEMENT
_NUhup "log_file.txt" Rscript "${xpath}"/workers/assembler.R \
    "$gene_names" "$level" "$design" "$metric" "$raw" "$target_dir"