def is_bam_valid(bam_file):
try:<EOL><INDENT>f = pysam.AlignmentFile(bam_file)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise<EOL><DEDENT>except:<EOL><INDENT>raise<EOL><DEDENT>else:<EOL><INDENT>f.close()<EOL><DEDENT>return True<EOL>
Check if bam file is valid. Raises a ValueError if pysam cannot read the file.

    #TODO: pysam  does not differentiate between BAM and SAM