def _get_query_alignment_pos_in_inferred_read(clippings, is_reverse, inferred_read_length, query_alignment_pos):
    """
    Convert query alignment position (such as aln.query_alignment_start) in coordinate of forward read.

    CIGAR   : 7H3S10M2I10M6D10M4S5H
                   7H 3S    10M      2I     10M      6D        10M   4S   5H  --> direction
    REF     :             MMMMMMMMMM -- MMMMMMMMMM DDDDDD MMMMMMMMMM
    READ    : HHHHHHHSSS  MMMMMMMMMM II MMMMMMMMMM ------ MMMMMMMMMM SSSS HHHHH
                          |             |                 |        |
    QUERY ALN POS        [3,            15,               25,      34]
    QUERY ALN POS IN FORWARD READ
             [0,          10,           22,               32,               ,50]
    ...doctest:
       >>> clippings = (7, 5, 3, 4)
       >>> [_get_query_alignment_pos_in_inferred_read(clippings, False, 51, i) for i in (3, 4, 10, 24, 25)]
       [10, 11, 17, 31, 32]

    CIGAR   : 7H3S10M2I10M6D10M4S5H
                7H 3S    10M     2I     10M      6D        10M   4S   5H    <-- direction
    REF     :          MMMMMMMMMM -- MMMMMMMMMM DDDDDD MMMMMMMMMM
           HHHHHHHSSS  MMMMMMMMMM II MMMMMMMMMM ------ MMMMMMMMMM SSSS HHHHH  : <--  REVERSE COMPLEMENT READ
                       |             |                 |        |          |
    QUERY ALN POS     [3,            15,               25,      34]

    QUERY ALN POS IN REVERSE COMPLEMENTARY OF (READ)
          [0,         10                                        41,       ,50]

    QUERY ALN POS IN READ
          [50,        40                                        9,        ,0]
    ...doctest:
       >>> clippings = (7, 5, 3, 4)
       >>> [_get_query_alignment_pos_in_inferred_read(clippings, True, 51, i) for i in (3, 4, 34)]
       [40, 39, 9]
    """
    l_hardclip, r_hardclip, l_softclip, r_softclip = clippings
    ret = l_hardclip + query_alignment_pos if not is_reverse else  inferred_read_length - l_hardclip - query_alignment_pos - 1
    assert ret <= inferred_read_length # allow exclusive end
    assert ret >= -1 # allow exclusive start
    return ret