def trim_start(transcript, cds_start, max_length=0):
    """
    Method to trim the beginning of a transcript, given both
    the cds_start and the maximal allowed length after trimming.
    :param transcript: the transcript to be trimmed
    :type transcript: Transcript

    :param cds_start: the position at which the CDS starts for this transcript.
    :type cds_start: int

    :param max_length: maximum length of terminal exons.
    :type max_length: int

    :rtype: Transcript

    """
    first = transcript.exons[0]
    if first[1] < cds_start:
        if first[1] - first[0] + 1 > max_length:
            newfirst = tuple([first[1] - max_length, first[1]])
            transcript.remove_exon(first)
            transcript.add_exon(newfirst)
        else:
            newfirst = first
    elif first[0] < cds_start <= first[1]:
        if first[1] - first[0] + 1 > max_length:
            newfirst = tuple([min(cds_start, first[1] - max_length), first[1]])
            transcript.remove_exon(first)
            transcript.add_exon(newfirst)
            transcript.add_exon((cds_start, newfirst[1]), feature='CDS')
        else:
            newfirst = first
    else:
        newfirst = first
    transcript.start = newfirst[0]
    return transcript
