text: user9669: I'm trying to use the code specified in this link to create a .bam file without the need for a .sam file.
  Here is the code I'm using:
  bwa mem -R "@RG\tID:$SAMPLE\tPL:illumina\tSM:$SAMPLE" \
      $REF_PATH/hg38.fasta \
      mapping/R1.fastq.gz \
      mapping/R2.fastq.gz | \
      samtools sort - | \
      tee mapping/$SAMPLE\.bam | \
      samtools index - mapping/$SAMPLE\.bam.bai \
      2>> log
  
  and I get the following error:
  [M::bwa_idx_load_from_disk] read 0 ALT contigs
  `[E::main_mem] fail to open file ` '.
  
  The ref path and file locations work when creating and converting a .sam to a .bam file.
  Any ideas?
  
  user9693: This is an error from bwa saying that it can't find your input files:
  Here's a checklist:
  
  Check that you have no whitespace after your \ newline breaks. I.e. \ is the very last character
  Check that you have no whitespace in any path names
  Quote your variables: $REF_PATH -> "$REF_PATH"
  Use set -x at the top of your bash script to debug.
  In general, read this
  
  
original_text: 9669: <p>I'm trying to use the code specified in <a href="https://biology.stackexchange.com/questions/59493/how-to-convert-bwa-mem-output-to-bam-format-without-saving-sam-file?fbclid=IwAR1oClXdwhtsqvQqkmmc8a1af-dTaALbtkQ2kKW3cGnIrLZCaa_6HxjvrfY">this link</a> to create a .bam file without the need for a .sam file.</p>
  <p>Here is the code I'm using:</p>
  <pre><code>bwa mem -R &quot;@RG\tID:<span class="math-container">$SAMPLE\tPL:illumina\tSM:$</span>SAMPLE&quot; \
      <span class="math-container">$REF_PATH/hg38.fasta \
      mapping/R1.fastq.gz \
      mapping/R2.fastq.gz | \
      samtools sort - | \
      tee mapping/$</span>SAMPLE\.bam | \
      samtools index - mapping/$SAMPLE\.bam.bai \
      2&gt;&gt; log
  </code></pre>
  <p>and I get the following error:</p>
  <pre><code>[M::bwa_idx_load_from_disk] read 0 ALT contigs
  `[E::main_mem] fail to open file ` '.
  </code></pre>
  <p>The ref path and file locations work when creating and converting a .sam to a .bam file.
  Any ideas?</p>
   9693: <p>This is an error from <code>bwa</code> saying that it can't find your input files:</p>
  <p>Here's a checklist:</p>
  <ol>
  <li>Check that you have no whitespace after your <code>\</code> newline breaks. I.e. <code>\</code> is the <em>very last character</em></li>
  <li>Check that you have no whitespace in any path names</li>
  <li><em>Quote your variables</em>: <code>$REF_PATH</code> -&gt; <code>&quot;$REF_PATH&quot;</code></li>
  <li>Use <code>set -x</code> at the top of your bash script to debug.</li>
  <li>In general, read <a href="https://kvz.io/bash-best-practices.html" rel="noreferrer">this</a></li>
  </ol>
  