def bam_has_index(bam_file):
has_index = None<EOL>with pysam.AlignmentFile(bam_file, '<STR_LIT:rb>') as bam_fileobj:<EOL><INDENT>try:<EOL><INDENT>bam_fileobj.fetch(bam_fileobj.references[<NUM_LIT:0>])<EOL><DEDENT>except ValueError as err:<EOL><INDENT>if err.message == '<STR_LIT>':<EOL><INDENT>bam_fileobj.close()<EOL>has_index = False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>has_index = True<EOL><DEDENT><DEDENT>return has_index<EOL>
Check if bam file has an index. Returns True/False.