def get_sorted_exons(session, transcript, protein_coding=False):
    """ Retrieve all Exons associated with input Transcript and return in sorted order. Option to
    filter on protein coding Exons only

    Parameters
    session:    A session connected to the DB where the Exons and Transcripts live
    transcript (Transcript):
                Transcript for which the Exons will be retrieved
    protein_coding (Bool):
                If True, only protein coding Exons will be returned

    Returns
    List of (filtered) Exons, sorted by order of appearance in the protein, so for Transcripts from the 
    reverse strand, order will be descending.
    """
    exons = []
    for exon in transcript.exons:
        if protein_coding and not exon.cds:
            continue
        exons.append(exon)

    if transcript.gene.strand == "fw":
        return list(sorted(exons, key=lambda x : x.begin))
    elif transcript.gene.strand == "rv":
        return list(sorted(exons, key=lambda x : x.begin, reverse=True))