def sample_from_bam(bam):
    """Extract sample name from BAM"""
    read_groups = bam.header["RG"]
    samples = set([rg["SM"] for rg in read_groups])
    assert len(samples) == 1, "BAM file {} must contain a single sample".format(
        bam.filename
    )
    sample, = samples  # Extract single value from set
    return sample