from typing import Counter


def seq_stats(seq):
    """Calculate basic sequence statistics."""
    counter = Counter(seq)
    gc = 0
    at = 0
    n = 0
    masked = 0
    for base in ["g", "c", "G", "C"]:
        if base in counter:
            gc += counter[base]
    for base in ["a", "t", "A", "T"]:
        if base in counter:
            at += counter[base]
    for base in ["n", "N"]:
        if base in counter:
            n += counter[base]
    for base in ["a", "c", "g", "t", "n"]:
        if base in counter:
            masked += counter[base]
    atgc = at + gc
    if atgc > 0:
        gc = gc / atgc
    else:
        gc = 0
    return {"gc": gc, "n": n / len(seq), "ncount": n, "masked": masked / len(seq)}