Adaptive dynamics of temperate phages