<p>Read groups must start with RG, that is a hardcoded requirement of the SAM format, nothing you can do about that.</p>
<p>See <a href="https://samtools.github.io/hts-specs/SAMv1.pdf" rel="nofollow noreferrer">https://samtools.github.io/hts-specs/SAMv1.pdf</a></p>

CC BY-SA 4.0
2022-06-20T18:38:59.847Z
2022-06-20T18:40:20.017Z
2022-06-20T18:40:20.017Z
Clarus Salvus
<blockquote>
<p>My sequences were generated with an MGI sequencer and the readgroups are identified like this <code>@S200031047L1C001R0020000243/1</code></p>
</blockquote>
<p>Those are <a href="https://en.wikipedia.org/wiki/DNA_nanoball_sequencing#Read_Names" rel="nofollow noreferrer">MGI read <strong>names</strong></a>, not read groups. (And the <code>@</code> is the FASTQ syntax that introduces a read name in a FASTQ file, not part of the read name or qname itself.)</p>
<p>Read <strong>groups</strong> more or less correspond to the sample that was sequenced. If a sample was sequenced across multiple sequencing machine runs and the resulting data merged into one file, there might be several read groups corresponding to the individual runs all pertaining to the same sample — though with increasing data volumes from individual sequencing runs this is perhaps less common than it used to be.</p>
<p>You get to make up the ids yourself, usually corresponding to what the sample is known as in your workflows. So your <code>-R</code> option should be something like</p>
<pre><code>-R '@RG\tID:S123\tSM:S123\tDS:Sample 123\tPL:DNBSEQ'
</code></pre>
<p>(BWA's <code>-R</code> syntax is unfortunately not very easy to use. See <a href="https://www.htslib.org/doc/samtools.html" rel="nofollow noreferrer">addreplacerg</a> for a similar <code>-r</code> option that is rather more user-friendly.)</p>
<p>The name you use for <code>${SAMPLE}</code> would usually be the same as the value of the <code>SM:</code> field within that <code>-R</code> option — the identifier that is used in your LIMS and workflows to identify that particular sample.</p>

CC BY-SA 4.0
2022-06-21T09:41:47.143Z
2022-06-21T09:41:47.143Z
John Marshall
<p><em>this question has been asked [and answered] on <a href="https://stackoverflow.com/questions/72690191/bwa-mem-and-sambamba-read-group-line-error">Stack Overflow</a></em></p>
<p>This is a two-part question:</p>
<ol>
<li>help interpreting an error;</li>
<li>help with coding.</li>
</ol>
<hr />
<ol>
<li>I'm trying to run <code>bwa-mem</code> and <code>sambamba</code> to align raw reads to a reference genome and to sort by position. These are the commands I'm using:</li>
</ol>
<pre><code>bwa mem  \
  -K 100000000 -v 3 -t 6 -Y \
  -R '\@S200031047L1C001R002\S*[1-2]' \
  /path/to/reference/GCF_009858895.2_ASM985889v3_genomic.fna \
  /path/to/raw-fastq/'S\S[^_]*_L01_[0-9]+-[0-9]+'_1.fq.gz \
  /path/to/raw-fastq/'S\S[^_]*_L01_[0-9]+-[0-9]+'_2.fq.gz | \
/path/to/genomics/sambamba-0.8.2 view -S -f bam \
  /dev/stdin | \
/path/to/genomics/sambamba-0.8.2 sort  \
  /dev/stdin \
  --out host_removal/${SAMPLE}/${SAMPLE}.hybrid.sorted.bam
</code></pre>
<p>This is the error message I'm getting: <code>[E::bwa_set_rg] the read group line is not started with @RG</code>.</p>
<p>My sequences were generated with an MGI sequencer and the readgroups are identified like this <code>@S200031047L1C001R0020000243/1</code>, i.e., they don't begin with an @RG. How can I specify to sambamba that my readgroups start with @S and not @RG?</p>
<hr />
<ol start="2">
<li>The commands written above are a published pipeline I'm modifying for my own research. However, among several changes, I'm not confident on how to define sample id as such stated in the last line of the code: <code>--out host_removal/${SAMPLE}/${SAMPLE}.hybrid.sorted.bam</code> (I'm referring to ${SAMPLE}). Any insights?</li>
</ol>
<hr />
<p>Thank you very much!</p>

<phylogenetics><ngs><genomics><bwa><sambamba>
BWA-mem and sambamba read group line error
# BWA-mem and sambamba read group line error

(Asked by: username_0 on 2022-06-20)

this question has been asked [and answered] on Stack Overflow
This is a two-part question:

help interpreting an error;
help with coding.



I'm trying to run bwa-mem and sambamba to align raw reads to a reference genome and to sort by position. These are the commands I'm using:

bwa mem  \
  -K 100000000 -v 3 -t 6 -Y \
  -R '\@S200031047L1C001R002\S*[1-2]' \
  /path/to/reference/GCF_009858895.2_ASM985889v3_genomic.fna \
  /path/to/raw-fastq/'S\S[^_]*_L01_[0-9]+-[0-9]+'_1.fq.gz \
  /path/to/raw-fastq/'S\S[^_]*_L01_[0-9]+-[0-9]+'_2.fq.gz | \
/path/to/genomics/sambamba-0.8.2 view -S -f bam \
  /dev/stdin | \
/path/to/genomics/sambamba-0.8.2 sort  \
  /dev/stdin \
  --out host_removal/${SAMPLE}/${SAMPLE}.hybrid.sorted.bam

This is the error message I'm getting: [E::bwa_set_rg] the read group line is not started with @RG.
My sequences were generated with an MGI sequencer and the readgroups are identified like this @S200031047L1C001R0020000243/1, i.e., they don't begin with an @RG. How can I specify to sambamba that my readgroups start with @S and not @RG?


The commands written above are a published pipeline I'm modifying for my own research. However, among several changes, I'm not confident on how to define sample id as such stated in the last line of the code: --out host_removal/${SAMPLE}/${SAMPLE}.hybrid.sorted.bam (I'm referring to ${SAMPLE}). Any insights?


Thank you very much!

**Tags:** phylogenetics, ngs, genomics, bwa, sambamba

---

## 2 answers

### Answer by username_1 on 2022-06-20. Score: 4

Read groups must start with RG, that is a hardcoded requirement of the SAM format, nothing you can do about that.

See <https://samtools.github.io/hts-specs/SAMv1.pdf>


---

### Answer by username_2 on 2022-06-21. Score: 1

My sequences were generated with an MGI sequencer and the readgroups are identified like this @S200031047L1C001R0020000243/1

Those are MGI read names, not read groups. (And the @ is the FASTQ syntax that introduces a read name in a FASTQ file, not part of the read name or qname itself.)
Read groups more or less correspond to the sample that was sequenced. If a sample was sequenced across multiple sequencing machine runs and the resulting data merged into one file, there might be several read groups corresponding to the individual runs all pertaining to the same sample — though with increasing data volumes from individual sequencing runs this is perhaps less common than it used to be.
You get to make up the ids yourself, usually corresponding to what the sample is known as in your workflows. So your -R option should be something like
-R '@RG\tID:S123\tSM:S123\tDS:Sample 123\tPL:DNBSEQ'

(BWA's -R syntax is unfortunately not very easy to use. See addreplacerg for a similar -r option that is rather more user-friendly.)
The name you use for ${SAMPLE} would usually be the same as the value of the SM: field within that -R option — the identifier that is used in your LIMS and workflows to identify that particular sample.


---

