def ignore_low_quality_bases(read, methylation_index, min_qual, phred_offset):
    """Ignore low quality bases of a read that contribute to a read's methylation_index.

    Args:
        read: A pysam.AlignedSegment instance.
        methylation_index: A list of zero-based indices. Each index corresponds to the leftmost aligned position of a methylation locus in a read. For example:

        [0, 5]

        corresponds to a read with a methylation locus at the first and sixth positions of the read.
        min_qual: The minimum base quality (integer). All bases with quality < min_qual are excluded from the returned methylation_index instance.
        phred_offset: The Phred offset of the data (33 or 64).

    Returns:
        An updated version of methylation_index.

    """
    if (min_qual < 0) or (round(min_qual) != min_qual):
        raise ValueError("ignore_low_quality_bases: 'low_qual' must be a positive integer")
    if phred_offset != 33 and phred_offset != 64:
        raise ValueError("ignore_low_quality_bases: 'phred_offset' must be a 33 or 64")
    # As of pysam v0.8.1, pysam.AlignedSegment.query_qualities now returns "a python array of unsigned chars" and "no offset of 33 needs to be subtracted" (http://pysam.readthedocs.org/en/latest/api.html#api). Therefore phred64 encoded base qualities now need to have an offset 64 - 33 = 31 subtracted and phred33 base qualities do not need any offset subtracted (0 is subtracted, which is a no-op, to minimise code changes).
    phred_offset = phred_offset - 33

    ignore_these_bases = []
    for i in methylation_index:
        if (read.query_qualities[i] - phred_offset) < min_qual:
            ignore_these_bases.append(i)
    return [x for x in methylation_index if x not in ignore_these_bases]