def extract_from_bam(params):
bam, chromosome = params<EOL>samfile = pysam.AlignmentFile(bam, "<STR_LIT:rb>")<EOL>return [<EOL>(read.query_name,<EOL>nanomath.ave_qual(read.query_qualities),<EOL>nanomath.ave_qual(read.query_alignment_qualities),<EOL>read.query_length,<EOL>read.query_alignment_length,<EOL>read.mapping_quality,<EOL>get_pID(read))<EOL>for read in samfile.fetch(reference=chromosome, multiple_iterators=True)<EOL>if not read.is_secondary]<EOL>
Extracts metrics from bam.

    Worker function per chromosome
    loop over a bam file and create list with tuples containing metrics:
    -qualities
    -aligned qualities
    -lengths
    -aligned lengths
    -mapping qualities
    -edit distances to the reference genome scaled by read length