Identify aligner from the BAM header; handling pre-aligned inputs.

def aligner_from_header(in_bam):
    """Identify aligner from the BAM header; handling pre-aligned inputs.
    """
    from bcbio.pipeline.alignment import TOOLS
    with pysam.Samfile(in_bam, "rb") as bamfile:
        for pg in bamfile.header.get("PG", []):
            for ka in TOOLS.keys():
                if pg.get("PN", "").lower().find(ka) >= 0:
                    return ka