def fastq_infer_rg(read):
    """
    Infer the read group from appended read information, such as produced by the
    samtools fastq command.

    Requires the read to be formatted such the rg tag is added to the end of the
    read name delimited by a ``_``. Returns the read group tag.
    """
    rgstr = read.name.split(sep='_')[1]
    assert rgstr[0:2] == 'RG'
    return rgstr.split(':')[-1]