Answers.Body: <p>The first thing to do is to group the FastQ files together following this <a href="https://bioinformatics.stackexchange.com/questions/8644/how-to-merge-fastq-qz-files-into-a-single-fastq-gz-with-their-same-id-without">post</a>. Once you have your reads grouped, you could trim your files before mapping. Then you could perform your BWA alignment. Since you mentioned <code>MEM</code>, I suppose your read length should be between 70-100bp as suggested by the author:</p>
  <pre><code>It consists of three algorithms: BWA-backtrack, BWA-SW and BWA-MEM.
  The first algorithm is designed for Illumina sequence reads up to 100bp, while the rest two for
  longer sequences ranged from 70bp to 1Mbp. BWA-MEM and BWA-SW share similar features such 
  as long-read support and split alignment, but BWA-MEM, which is the latest, 
  is generally recommended for high-quality queries as it is faster and more accurate.
  BWA-MEM also has better performance than BWA-backtrack for 70-100bp Illumina reads.
  </code></pre>
  <p>Then you could run your BWA MEM, supposing you have 10 CPUs available, like so:</p>
  <pre><code>bwa mem \                                  # bwa mem algorithm
  -M \                                       # mark shorter split hits as secondary (for Picard compatibility).
  -t 10 \                                    # CPUs thread
  reference.fasta \                          # reference genome to be aligned to
  &lt; sample_r1.fastq \                        # fastQ read 1 (can be .gz)
  &lt; sample_r2.fastq | \                      # optional FastQ read 2 (can be .gz)
  samtools view -bS -@ 10 &gt; sample.bam       # pipe to samtools to convert SAM to BAM on the fly.
  </code></pre>
  <p>Hope this helps !</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T08:19:30.897Z
Answers.LastActivityDate: 2021-02-15T14:15:32.853Z
Answers.LastEditDate: 2021-02-15T14:15:32.853Z
Answers.UserDisplayName: user324810
Answers.Body: <p>Trimming is something you always want to do before mapping to make sure that the bases at each position are of sufficient quality, and to make sure that you are not aligning your adapters to the reference genome.</p>
  
  <p>I am not entirely sure what the biological difference is represented in your individual libraries (that depends on your research question). But most likely you want to demultiplex the reads before mapping with BWA as well. As a result you would indeed get a sam/bam file per library. Let me know if anything is still unclear!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T08:15:26.807Z
Answers.LastActivityDate: 2019-05-21T08:15:26.807Z
Answers.UserDisplayName: Jvstonebridge
Body: <p>I have a multiplexed lane of GBS sequencing reads as a fastq file. I understand the first step is to demultiplex and trim the adapter sequences from the reads.</p>
  <p>This yields many individual fastq files that correspond to individual libraries.</p>
  <p>I would like to genotype my samples, but I need to map the reads first. My question is how should I perform the BWA MEM alignment?</p>
  <p>Do I perform BWA MEM on each of the resulting fastq files that correspond to individual libraries...</p>
  <p>OR</p>
  <p>I should I perform BWA MEM on the large original fastq file that contains all my sequence reads before demux and read trimming?</p>
  <p>Forgive my ignorance, I've only ever used TASSEL (which works great) and I'm trying to expand my understanding and flexibility.</p>
  
Tags: <bwa><genotyping>
Title: Proper use of BWA MEM on multiplexed GBS sample
ThreadText: # Proper use of BWA MEM on multiplexed GBS sample
  
  (Asked by: username_0 on 2019-05-21)
  
  I have a multiplexed lane of GBS sequencing reads as a fastq file. I understand the first step is to demultiplex and trim the adapter sequences from the reads.
  
  This yields many individual fastq files that correspond to individual libraries.
  
  I would like to genotype my samples, but I need to map the reads first. My question is how should I perform the BWA MEM alignment?
  
  Do I perform BWA MEM on each of the resulting fastq files that correspond to individual libraries...
  
  OR
  
  I should I perform BWA MEM on the large original fastq file that contains all my sequence reads before demux and read trimming?
  
  Forgive my ignorance, I've only ever used TASSEL (which works great) and I'm trying to expand my understanding and flexibility.
  
  **Tags:** bwa, genotyping
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-05-21. Score: 1
  
  The first thing to do is to group the FastQ files together following this [post](https://bioinformatics.stackexchange.com/questions/8644/how-to-merge-fastq-qz-files-into-a-single-fastq-gz-with-their-same-id-without). Once you have your reads grouped, you could trim your files before mapping. Then you could perform your BWA alignment. Since you mentioned `MEM`, I suppose your read length should be between 70-100bp as suggested by the author:
  
  ```
  It consists of three algorithms: BWA-backtrack, BWA-SW and BWA-MEM.
  The first algorithm is designed for Illumina sequence reads up to 100bp, while the rest two for
  longer sequences ranged from 70bp to 1Mbp. BWA-MEM and BWA-SW share similar features such 
  as long-read support and split alignment, but BWA-MEM, which is the latest, 
  is generally recommended for high-quality queries as it is faster and more accurate.
  BWA-MEM also has better performance than BWA-backtrack for 70-100bp Illumina reads.
  
  ```
  
  Then you could run your BWA MEM, supposing you have 10 CPUs available, like so:
  
  ```
  bwa mem \                                  # bwa mem algorithm
  -M \                                       # mark shorter split hits as secondary (for Picard compatibility).
  -t 10 \                                    # CPUs thread
  reference.fasta \                          # reference genome to be aligned to
  < sample_r1.fastq \                        # fastQ read 1 (can be .gz)
  < sample_r2.fastq | \                      # optional FastQ read 2 (can be .gz)
  samtools view -bS -@ 10 > sample.bam       # pipe to samtools to convert SAM to BAM on the fly.
  
  ```
  
  Hope this helps !
  
  
  ---
  
  ### Answer by username_2 on 2019-05-21. Score: 0
  
  Trimming is something you always want to do before mapping to make sure that the bases at each position are of sufficient quality, and to make sure that you are not aligning your adapters to the reference genome.
  
  I am not entirely sure what the biological difference is represented in your individual libraries (that depends on your research question). But most likely you want to demultiplex the reads before mapping with BWA as well. As a result you would indeed get a sam/bam file per library. Let me know if anything is still unclear!
  
  
  ---
  
  