def trim_seq(seq):
    """
    Remove 'N's and non-ATCG from beginning and ends
    """
    good = ['A','T','C','G']
    seq = seq.upper()
    n = len(seq)
    i = 0
    while i < n and seq[i] not in good: i += 1
    j = len(seq)-1
    while j >= 0 and seq[j] not in good: j -= 1
    return seq[i:j+1]