def get_template_length(record):
    """Returns the template length of the given record for paired or collapsed
    reads; for single-ended reads, None is returned."""
    if record.is_paired:
        return record.tlen
    elif record.qname.startswith("M_"):
        return record.alen
    return None