A formal framework for analyzing sequence