def check_bam(bam, o):
try:<EOL><INDENT>p = sp.Popen(['<STR_LIT>', '<STR_LIT>', bam], stdout=sp.PIPE)<EOL>paired = <NUM_LIT:0><EOL>read_lengths = defaultdict(int)<EOL>while o > <NUM_LIT:0>:  <EOL><INDENT>line = p.stdout.readline().decode().split("<STR_LIT:\t>")<EOL>flag = int(line[<NUM_LIT:1>])<EOL>read_lengths[len(line[<NUM_LIT:9>])] += <NUM_LIT:1><EOL>if <NUM_LIT:1> & flag:  <EOL><INDENT>paired += <NUM_LIT:1><EOL><DEDENT>o -= <NUM_LIT:1><EOL><DEDENT>p.kill()<EOL><DEDENT>except OSError:<EOL><INDENT>reason = "<STR_LIT>""<STR_LIT>""<STR_LIT>""<STR_LIT>"<EOL>raise OSError(reason)<EOL><DEDENT>_LOGGER.debug("<STR_LIT>".format(read_lengths))<EOL>_LOGGER.debug("<STR_LIT>".format(paired))<EOL>return read_lengths, paired<EOL>
Check reads in BAM file for read type and lengths.

:param str bam: BAM file path.
:param int o: Number of reads to look at for estimation.