0

I am trying to align my samples to a reference genome using bwa mem.

I have over 300 samples which I created an index from a metadata file

but something isn't really working!

The loop i'm using is this (in SLURM)

#SBATCH --export=ALL # export all environment variables to the batch job
#SBATCH -D . # set working directory to .
(...)

# Commands

module load BWA/0.7.17-foss-2018a
module load SAMtools/1.3.1-foss-2018a
module load BCFtools/1.6-intel-2017b

reference=/gpfs/ts0/home/jn378/mussels/snp/genomes/gallo_v6.snail.svg
input_reads=/gpfs/ts0/home/jn378/mussels/snp/3.fastp
align=/gpfs/ts0/home/jn378/mussels/snp/5.bam-files
metadata=/gpfs/ts0/home/jn378/mussels/snp/SNP-array-metadata.txt
metadata=/gpfs/ts0/home/jn378/mussels/snp/SNP-array-metadata.txt


read1=( `cat $metadata | cut -f 4` )
read1_array=$input_reads/${read1[(($SLURM_ARRAY_TASKID))]}

read2=( `cat $metadata | cut -f 5` )
read2_array=$input_reads/${read2[(($SLURM_ARRAY_TASKID))]}

outbam=( `cat $metadata | cut -f 1` )
out=${outbam[(($SLURM_ARRAY_TASKID))]}

echo "reference" $reference
echo "read1" $read1_array
echo "read2" $read2_array
echo "alignment" $align/${out}_unsorted.raw.sam

#### Align with bwa mem ###

####bwa mem -t 4 $reference $read1_array $read2_array > ${align}/${out}_unsorted.raw.sam

but I keep getting this error:

bwa.sh: line 34: (()): syntax error: operand expected (error token is "))")

Could someone help me with this issue?

Many thanks!

Mat
  • 202,337
  • 40
  • 393
  • 406

1 Answers1

0

The error message you get

bwa.sh: line 34: (()): syntax error: operand expected (error token is "))")

is because the variable you want to use is named SLURM_ARRAY_TASK_ID and not SLURM_ARRAY_TASKID. The latter is not set and the expression expands to

read1_array=$input_reads/${read1[(())]}

which Bash cannot parse.

So replace SLURM_ARRAY_TASKID with SLURM_ARRAY_TASK_ID and it should be ok.

Also note that the double parentheses are not needed, and it is always a good idea to double quote variables of paths in case some contain special chars, so you can write

read1_array="$input_reads/${read1[$SLURM_ARRAY_TASK_ID]}"
damienfrancois
  • 52,978
  • 9
  • 96
  • 110