Answers.Body: <p>It seems the sequencing is single-end, and there is only one fastq per sample. If so:</p>
  <pre><code>staridx=/path/to/star/genome/index
  
  mkdir /plates/star/
  cd /plates/star/
  
  files=$(find /plates/plate_1/rawdata/ -name &quot;*_R1.fastq&quot;)
  
  for i in ${files}
  do
  
    sample=<span class="math-container">$(basename $</span>i &quot;_R1.fastq&quot;)
  
    STAR --genomeDir <span class="math-container">$staridx --runThreadN 8 --outFileNamePrefix $</span>{sample}. \
      --readFilesIn $i --outSAMtype BAM
  
  done
  </code></pre>
  <p>All fastq files will be mapped individually, and all bam files will be saved to <code>/plates/star/</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-08T19:44:47.390Z
Answers.LastActivityDate: 2021-12-08T19:44:47.390Z
Answers.UserDisplayName: h.mon
Body: <p>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?</p>
  <p>Folder structure:</p>
  <pre><code>/plates/plate_1/rawdata/A1/A1_R1.fastq
  /plates/plate_1/rawdata/B1/B1_R1.fastq
  ...
  /plates/plate_1/rawdata/O24/O24_R1.fastq
  /plates/plate_1/rawdata/P24/P24_R1.fastq
  </code></pre>
  <p>It’s 384 sample folders A1, A2, B3, F5,,, so on</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-03-05T07:13:54.170Z
Comments.Text: Thanks I added the path structure
Comments.UserDisplayName: mobasher barsi
Tags: <phylogenetics><genome><bash><star><loop>
Title: STAR aligner multiple fastq files
ThreadText: # STAR aligner multiple fastq files
  
  (Asked by: username_0 on 2021-03-04)
  
  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:
  
  ```
  /plates/plate_1/rawdata/A1/A1_R1.fastq
  /plates/plate_1/rawdata/B1/B1_R1.fastq
  ...
  /plates/plate_1/rawdata/O24/O24_R1.fastq
  /plates/plate_1/rawdata/P24/P24_R1.fastq
  
  ```
  
  It’s 384 sample folders A1, A2, B3, F5,,, so on
  
  **Tags:** phylogenetics, genome, bash, star, loop
  
  > **Comments:**
  > **username_0**: Thanks I added the path structure  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-12-08. Score: 2
  
  It seems the sequencing is single-end, and there is only one fastq per sample. If so:
  
  ```
  staridx=/path/to/star/genome/index
  
  mkdir /plates/star/
  cd /plates/star/
  
  files=$(find /plates/plate_1/rawdata/ -name "*_R1.fastq")
  
  for i in ${files}
  do
  
    sample=$(basename $i "_R1.fastq")
  
    STAR --genomeDir $staridx --runThreadN 8 --outFileNamePrefix ${sample}. \
      --readFilesIn $i --outSAMtype BAM
  
  done
  
  ```
  
  All fastq files will be mapped individually, and all bam files will be saved to `/plates/star/`.
  
  
  ---
  
  