Decomposition theory for automata and biological systems