def _is_first_or_last_exon(row_list, row_index):
    """Determine if it is the first or the last coding exon."""
    start_exon = False
    end_exon = False
    n_rows = len(row_list)
    if row_index == 0:
        start_exon = True
    elif row_index == n_rows - 1:
        end_exon = True
    else:
        row = row_list[row_index]
        identical_to_previous = row_list[row_index - 1]['TranscriptID'] == row[
            'TranscriptID']
        identical_to_next = row_list[row_index + 1]['TranscriptID'] == row[
            'TranscriptID']
        if not identical_to_previous or row['StartPhase'] == -1:
            start_exon = True
        if not identical_to_next or row['EndPhase'] == -1:
            end_exon = True
    return start_exon, end_exon
