This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to run simultaneous jobs in parallel using Job arrays in SLURM?

Dear all,

I need help in running simultaneous jobs parallel on SLURM. I'm very new in running array jobs and working on SLURM. I have around 100 tar.gz files. I would like to unit them and use the fastq's for alignment with hisat2 exporting bam, sorting the bam files and finally exporting the output as sorted.bam files.

tar.gz -> fastq (after extraction) -> bam -> sorted.bam

I made a script for this like below to run on SLURM cluster.

#!/bin/bash

#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=4G
#SBATCH --time=05:59:59
#SBATCH --tmp=500G
#SBATCH --array=1-100%20

mkdir /home/destination
cd /home/destination

for i in /home/eg/*.tar.gz
do
tar xvzf $i -C $TMPDIR
for sample in $TMPDIR/*1.fastq
do
dir2="/home/destination"
base=$(basename $sample "_1.fastq")
base2=$(basename $i ".tar.gz")
module load HISAT2/2.0.4-goolf-1.7.20; module load SAMtools/1.3.1-goolf-1.7.20; hisat2 -p 8 --dta --rna-strandness RF -x /home/grch38_snp_tran/genome_snp_tran -1 $TMPDIR/${base}_1.fastq -2 $TMPDIR/${base}_2.fastq | samtools view -Sb - > $TMPDIR/${base2}.bam; samtools sort -T $TMPDIR/${base2}.sorted -o ${dir2}/${base2}.sorted.bam $TMPDIR/${base2}.bam
done
done

With this the jobs started running, but even after finishing one job the same job is repeating again. Do I need to specify "$SLURM_ARRAY_TASK_ID"? How to do that for the above code?

And also how to get .out files for each array ID index?

Any help is appreciated.

slurm parallel alignment fastq bam

I am not sure if a job array can be used with a program that requires multiple inputs like HISAT2. Perhaps someone else will have an input on that.

You could basically run the for look outside and then submit the jobs in parallel using single line sbatch commands.

I’m confused. Could you please explain with some script.

Following is untested. I added an echo. I am assuming that the rest of the logic is sound. See if you are able to generate right command lines. If all looks well then remove echo. You should need to module load once at the beginning before submitting the jobs.

module load HISAT2/2.0.4-goolf-1.7.20; module load SAMtools/1.3.1-goolf-1.7.20; 

for i in /home/eg/*.tar.gz
do
tar xvzf $i -C $TMPDIR
for sample in $TMPDIR/*1.fastq
do
dir2="/home/destination"
base=$(basename $sample "_1.fastq")
base2=$(basename $i ".tar.gz")
echo sbatch -n 8 -N 1 --mem 32g -t 5:59:00 --wrap="hisat2 -p 8 --dta --rna-strandness RF -x /home/grch38_snp_tran/genome_snp_tran -1 $TMPDIR/${base}_1.fastq -2 $TMPDIR/${base}_2.fastq | samtools view -Sb - > $TMPDIR/${base2}.bam; samtools sort -T $TMPDIR/${base2}.sorted -o ${dir2}/${base2}.sorted.bam  $TMPDIR/${base2}.bam"
done
done

I tried this before but it didn't work. And btw even untarring is taking more than 30 mins.

HISAT2 should understand compressed files. You should not need to uncompress.

 <m1>       Files with #1 mates, paired with files in <m2>.
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).

Take @h.mon's note into account below.

Why are your fastq files tarred? Could you show the contents of one such file?

yes, they were tarred. I want to untar them and use the fastq's for alignment all need to be done in a single script. Tar.gz files look like below:

TCGA-A7-A0CH-11A.tar.gz
TCGA-A7-A0DB-11A.tar.gz
TCGA-A7-A0DC-11A_dd.tar.gz
TCGA-A7-A0D9-11A.tar.gz

Your files are tarred.

TCGA-A7-A0CH-11A.tar.gz has been tarred and gzipped: first several files are joined on one single tar file, then this tar file is compressed with gzip. Same for all other files with a .tar.gz extension.

What does

tar -tvf TCGA-A7-A0CH-11A.tar.gz produce?

The actual tar.gz files looks different. They look like "UNCID_2207021.7b9569bc-f513-4b64-9a7c-7bb53b9be79b.110801_UNC12-SN629_0115_BD0DVEABXX_3_ACAGTG.tar.gz" But changed their names.

I will ask again. What does

tar -tvf UNCID_2207021.7b9569bc-f513-4b64-9a7c-7bb53b9be79b.110801_UNC12-SN629_0115_BD0DVEABXX_3_ACAGTG.tar.gz

show, if that is the real name of the file?

tar -xvzf or tar -xvf?

Sorry. Actually tvf. Just want to see what files are in that tar archive without extracting them.

When I did that I see this -rw-rw-r-- seqware/lbginrc 12094029903 2014-01-09 23:15 110829_UNC11-SN627_0147_AD0DFWABXX.3_2.fastq

That looks like the R2 file. Where is the R1 file?

yes there is R1 file also, in the above comment I showed only one.

110829_UNC11-SN627_0147_AD0DFWABXX.3_1.fastq

HISAT2 is currently in v.2.1.0. You are running an old version and should consider upgrading.

0 answers

No answers yet.

Log in to answer this question.