def spectrum_embedding(x, p=2, binary=False):
    """
	Computes the spectrum embedding of a seuqnce.
	The feature space contains the number of occurrences of all possible substrings

	p: the length of substructures
	binary: counts of occurrences or 1/0
	"""
    vx = {}
    for i in range(len(x) - p + 1):
        u = x[i:i + p]
        vx[u] = 1 if u not in vx or binary else vx[u] + 1
    return vx
