I’m using STAR to align fastq files from SMART-seq2. I have raw data folder containing sub-folders with samples names the sub-folders each contain fastq file. How can I make a bash command in order for STAR to go in each of sub-folders and make alignment for the fastq file and retrieve the bam files in one folder?

Folder structure:


It’s 384 sample folders A1, A2, B3, F5,,, so on

  • $\begingroup$ Thanks I added the path structure $\endgroup$ Mar 5, 2021 at 7:13

1 Answer 1


It seems the sequencing is single-end, and there is only one fastq per sample. If so:


mkdir /plates/star/
cd /plates/star/

files=$(find /plates/plate_1/rawdata/ -name "*_R1.fastq")

for i in ${files}

  sample=$(basename $i "_R1.fastq")

  STAR --genomeDir $staridx --runThreadN 8 --outFileNamePrefix ${sample}. \
    --readFilesIn $i --outSAMtype BAM


All fastq files will be mapped individually, and all bam files will be saved to /plates/star/.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.