Entering edit mode
2.9 years ago
ManuelDB
▴
110
How can I introduce arguments in an script containing third parties
I want to be able to run the script ./ sam2bam.sh argument1 argument 2 `
# Load pipeline settings
. *.config
FASTAQ1=$1
FASTAQ2=$2
bwa mem \
-R '@RG\tID:'"$RunID"'_'"$Sample_ID"'\tSM:'"$Sample_ID"'\tPL:'"$Platform"'\tLB:'"$ExperimentName" \
"$refgenome4bwa" \
"${FASTAQ1}" "${FASTAQ2}" \
> output.sam
The argument taken from .config work but the argument parsing from the command line do not work. I have tried "${FASTAQ1}" and "$FASTAQ1"
This is a pure bash question and you will find plenty of answers of StackOverflow. As it's
20212022 I strongly recommend to learn a workflow manager such as Nextflow or Snakemake to write your workflows rather than bash scripts. It is just super laborious to have a bash script parsing arguments, see e.g. https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bashI think first and foremost everyone should know bash, if someone cannot make a thing work in bash, the other tools only add another layer of complexity,
this is a valid bioinformatics question, how come snakemake is bioinformatics but a bioinformatics script in bash is not?
I agree that bash is basic knowledge one should have. In contrast, I disagree with the statement that these tools are necessarily an extra layer of complexity. Sure, there is an initial learning curve and you can type a simple bash script in 5' but the fact alone on how much lines you have to write to get optparse working in bash (while this comes out of the box for both SM and NF) shows that this is a good investment of time.
the
$1
and$2
in your script already does that,it makes your script take parameters from command line exactly in the way you want it. Take this script:
it contains:
use it:
prints:
what else do you need?