Instead of
ord(pileupread.alignment.qual[pileupread.query_position]) - 33
use
pileupread.alignment.query_qualities[pileupread.query_position]
The attribute .query_qualities is easier to work with than the .qual
attribute and should be preferred (no need for ord() and no need for
subtracting 33). It was introduced a few pysam versions back.
The .qual attribute still exists, but is unfortunately very slow. It is
actually a property that converts the full sequence of qualities from
the internal representation every time it is accessed.
Marcel