Context-dependent dynamics lead to the assembly of functionally distinct microbial communities