Parsing arguments in BWA tool
0
0
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"

bwa • 959 views
ADD COMMENT
1
Entering edit mode

This is a pure bash question and you will find plenty of answers of StackOverflow. As it's 2021 2022 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-bash

ADD REPLY
0
Entering edit mode

I 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?

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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:

cat test.sh 

it contains:

echo Hello $1

use it:

bash test.sh Jane

prints:

Hello Jane

what else do you need?

ADD REPLY

Login before adding your answer.

Traffic: 1649 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6