## Abstract

Multi-species microbial communities often display functions - biochemical activities unattainable by member species alone, such as fighting pathogens. To improve community function, we can artificially select communities by growing “Newborn” communities over “maturation time” into “Adult” communities, and selecting highest-functioning Adults to “reproduce” by diluting each into multiple Newborns of the next cycle. Community selection has been attempted a few times on complex communities, often generating mixed results that are difficult to interpret. Here, we ask how costly community function may be improved via mutations and community selection. We simulate selection of two-species communities where Helpers digest Waste and generate Byproduct essential to Manufacturers; Manufacturers divert a fraction of their growth to make Product. Community function, the total Product in an “Adult”, is sub-optimal even when both species have been pre-optimized as monocultures. If we dilute an Adult into Newborns by pipetting (a common experimental procedure), stochastic fluctuations in Newborn composition prevents community function from improving. Reducing fluctuations via cell sorting allows selection to work. Our conclusions hold regardless of whether H and M are commensal or mutualistic, or variations in model assumptions.

## Introduction

Multi-species microbial communities often display important *functions*, defined here as biochemical activities not achievable by member species in isolation. For example, a six-species microbial community, but not any member species alone, cleared relapsing *Clostridium difficile* infections in mice [1]. As another example, cellulose-degrading communities often harbor non-cellulolytic aerobic bacteria that, by depleting oxygen, establish a proper anaerobic environment for cellulolytic bacteria [2].

Community functions arise from *interactions* where an individual alters the physiology of another individual. Thus, to improve community function, one could identify and modify interactions [3, 4]. In reality, this is no trivial task given that even two species can engage in complex interactions: each can release tens or more compounds, many of which may influence the partner species in diverse fashions [5, 6, 7, 8]. Then, from this myriad of interactions, we will need to identify those critical for community function, and modify them by altering species genotypes or the abiotic environment.

Alternatively, one could artificially select for microbial communities exhibiting high community function. In theory, artificial selection can be applied to any population of entities. An entity can be an individual (Figure S1A), a mono-species group of individuals (Figure S1B), or a multi-species community (Figure S1C) [9]. The boundary of a group or a community is artificially imposed (e.g. in microtiter wells or fluidic droplets). Here in artificial community selection, we allow low-density “Newborn communities” (Newborns) to “mature” over time *T* into “Adult communities” (Adults) when cells grow and mutate, and choose Adult communities expressing the highest community function to reproduce by splitting each into multiple Newborns to start the next cycle. Artificial selection of multi-species communities is predicted to be more challenging than artificial selection of mono-species groups or individuals (see Figure S1 for an explanation).

How effective is community selection? So far, community selection has been attempted only several times [10, 11, 12, 13]. In simulations, multi-species communities were selected based on how similar or dissimilar various chemical concentrations in the community abiotic environment are to arbitrarily-chosen target values [10]. Indeed, community selection produced the intended response, although the response quickly leveled off and was generated even without mutations. Thus in these simulations, community selection likely acted on preexisting variations in community species composition. In experiments, complex microbial communities were selected to improve their abilities to degrade a pollutant or alter plant physiology [11, 12, 14, 15]. For example, microbial communities could be selected to promote early or late flowering in plants, and communities associated with early-flowering versus late-flowering have distinct species makeups [15]. Strikingly in other studies, a community trait may fail to improve despite selection, and may improve even in control experiments random communities were selected to reproduce [11, 12].

Intriguing as these selection attempts might be, how they operated is often unknown. First, is the trait under selection a community function or simply a trait of one member species? If the latter, then community selection is not even needed. Second, does selection act solely on species make-ups or also on newly-arising genotypes? If selection acts mainly on species make-ups, which is likely the case for previous experiments [15], then without immigration of new species, community function will quickly level off [10]. If selection acts on genotypes, then community function can potentially continue to improve as new genotypes emerge. Third, does community selection run counter to natural selection? For example, during pollutant remediation, microbes may pay a fitness cost to release a pollutant-degrading enzyme. In this case, selecting high-degradation communities would favor high-degraders, while natural selection would favor low-degraders. Alternatively, microbes may exploit pollutant as a nutrient for growth. In this case, high-degraders are also fast growers, and are favored by both natural selection and community selection. In this case, community selection may not even be necessary.

In this article, we seek to understand how to effectively perform community selection so that we can improve a phenotype that is costly to the individual but beneficial to community function. Unlike mathematical models that, for example, focus on two genotypes (e.g. contributing or not contributing to community function), we seek a greater level of biological realism by simulating mechanisms of species interactions and incorporating experimentally-measured mutational processes. This allows our theoretical insights to guide future experiments.

## Results

### Species coexistence in a Helper-Manufacturer community

We consider a community that can convert waste (such as cellulose) to a useful product (such as a biofuel or an anti-cancer drug). Such communities have been engineered in the laboratory [16, 17, 18, 19]. In our Helper-Manufacturer community (Figure 1A), Helper H but not Manufacturer M can grow by digesting Waste. Waste is supplied in excess and thus its concentration change does not affect H growth rate. As H grows, it releases Byproduct B, which serves as the only carbon source for M. Thus, M depends on H (obligatory commensalism). H and M also compete for a shared Resource R (such as reduced nitrogen). M invests *f*_{P} fraction of its growth potential (*f*_{P} *g*_{M}) to make Product P, and uses the rest (1 - *f*_{P})*g*_{M} for its actual biomass growth. Community function *P*(*T*) is defined as the total amount of Product P accumulated when a newly-assembled “Newborn” community matures into an “Adult” community over maturation time *T* (Figure 1B). Thus, community function incurs a fitness cost *f*_{P} to M. In Methods Section 7, we explain problems associated with two alternative definitions of community function.

To convert Waste to Product, H and M must coexist. Species coexistence is possible since H and M engage in obligatory commensalism [20]. Once a Newborn is formed, H immediately starts to grow on Waste and Resource, while M needs to wait for H’s Byproduct. Once Byproduct has accumulated, if M can grow faster than H to “catch up”, then H and M can stably coexist: different initial species ratios will converge to a positive steady state (Figure 1C, bottom). This requires *f*_{P} to be sufficiently small because otherwise, M will always grow slower than H (or even stop growing when *f*_{P} = 1) and go extinct (Figure 1C, top).

### Simulating community selection

To simulate community selection experiments, we design our model (Methods Section 6) to be biologically realistic. Our parameter values (Table 1) are based on various experimental measurements on yeast and *E. coli* (details in Methods Section 2). As we will show, our conclusions are robust against variations in model assumptions.

Our model tracks individual cells. Cell biomass starts at 1, and once it grows to the division threshold of 2, the cell divides into two equal halves. Thus, our model captures continuous biomass increase (Figure S2) as well as discrete cell division events, similar to experimental observations of *E. coli* growth [21]. Biomass growth rate (*g*_{H} for H; (1 - *f*_{P})*g*_{M} for M) increases with concentration(s) of required nutrient(s) until maximal growth rate is achieved. For H, since Waste is in excess, we model growth rate as a function of Resource using the Monod Equation (Figure S3A). For M which requires both Resource and Byproduct, we adopt a dual-substrate model by Mankad and Bungay (Figure S3B) due to its experimental support [22] (Figure S4). Cell death occurs stochastically to individuals at a probability determined by death rate. Changes in quantities of metabolites (Resource *R*, Byproduct *B*, and Product *P*) are due to release and/or consumption.

*f*_{P} and growth parameters (maximal growth rates and affinities for metabolites) can mutate within the range of 0 and respective biological upper bounds (Table 1), as these phenotypes have been shown to evolve rapidly ([23, 24, 25, 26]). We choose ancestral growth parameters and their upper bounds so that H and M can coexist for a sizable range of *f*_{P} (e.g. *f*_{P} ≤ 0.5) during evolution. We hold H and M’s death rates constant during evolution, because death rates are much smaller than growth rates and thus any changes are likely inconsequential. We also hold release and consumption parameters constant due to the stoichiometric constraints of biochemical reactions.

Experimentally-measured mutation rates vary from 10^{-8} to 10^{-3} phenotype-altering mutations (short-handed as “mutations”) per cell per generation depending on whether the phenotype is qualitative (e.g. survival under a stress) or quantitative (e.g. growth rate), and a variety of other factors (Methods Section 4). Mutation rate can be elevated by 100-fold in hyper-mutators with defective DNA repair machinery [27, 28, 29]. Here for each mutable phenotype, we assume a high but biologically feasible rate of 0.002 mutation per cell per generation, in part to speed up computation. 50% mutations create null mutants (*f*_{P} or growth phenotype =0), as per experiments on GFP, viruses, and yeast [30, 31, 32]. Effects of the other 50% mutations are exponentially distributed, enhancing or diminishing a phenotype by an average of 5% and 6.7% respectively, as per our re-analysis of published data sets [33] (Figure 2B). We further assume that the effects of sequential mutations are multiplicative (i.e. no epistasis). We will show that using a lower mutation rate, adopting a different of mutation effects, or incorporating epistasis does not alter our conclusions.

Variables of a selection regimen (Figure 2A) include the total number of communities under selection (*n*_{tot}), Newborn species biomass composition, the amount of Resource in Newborn, maturation time *T*, and how we reproduce an Adult. Large *n*_{tot} allows more variations to be selected, but experimental setup becomes more demanding. Here, we start with 100 Newborns which can be screened in 96-well plates. Species ratio will rapidly converge to a steady state value (Figure 1C, bottom). If Newborns have a large total biomass *N*(0) or are allowed to grow to a large size, then all communities will share similar evolutionary dynamics of accumulating and being overtaken by non-producing Manufacturers [34, 35, 36], which impedes selection (similar to Figure S1B, top). At very small *N*(0), a member species could get lost by chance, and a very large number of communities are required to sample those rare mutations that improve community function. Thus, we choose *N*_{0}, the target biomass of a Newborn community, to be 100 (e.g. 100 cells of biomass 1). The number of cell generations within a selection cycle should be sufficiently large to entertain new mutations, but sufficiently short to prevent non-producers from taking over. Thus, we supply each Newborn with Resource to support a maximal total biomass of 10^{4}, and set *T* such that the total biomass would grow from the initial ∼100 to generally ∼6 × 10^{3} even for the fastest-growing H and M. At the rate of 2×10^{-3} mutations per cell per generation, a community growing from 10^{2} to ∼6 ×10^{3} (∼6 generations) will on average sample ∼20 new mutations per mutable phenotype. Within 6 generations, non-producers with a 20% fitness advantage over producers will rise from 2% to 6%, for example. Moreover, Resource will be in ∼40% excess by the end of *T*, and this circumvents stationary phase. To reproduce an Adult, we do not allow mixing among communities to prevent non-producers from migrating to high-functioning communities. We reproduce the top-functioning Adult by randomly partitioning it into Newborns with *N*(0) ∼ target *N*_{0}. Experimentally, this can be achieved by calculating fold-dilution (dividing Adult turbidity by the target Newborn turbidity), and repeatedly pipetting 1/fold-dilution volume of Adult into fresh medium to form Newborns. Since total biomass generally increases by 10∼60 fold during *T* depending on whether H and M are ancestral or evolved, each Adult can give rise to 10∼60 Newborns. We then use the next top-functioning Adult until we generate *n*_{tot} = 100 Newborns for the next selection cycle.

### Improving individual growth sometimes improves community function

When we select random Adults to reproduce, community function and average *f*_{P} rapidly decline to zero in all replicates (Figure S8B and C). This is expected since without community selection, natural selection favors fast-growing non-producers. Consistent with natural selection, maximal growth rates rapidly increase to their upper bounds, and nutrient affinities also improve (Figure S8A).

When we select top-functioning Adults to reproduce, *P*(*T*) initially increases (Figure 3A). Average does not decline, and remains at near the ancestral value. Concurrently, H and M’s growth phenotypes (maximal growth rates and nutrient affinities) improve toward their respective upper bounds (Figure 3C). Improving individual growth does not always improve community function (Figure S9). For example, if H evolves to always grow faster than M, then H will out-compete M and community function will decline. However, we have chosen ancestral growth parameters and their biological upper bounds such that improving H and M’s growth generally improves community function (Methods Section 3; Figures S10, S11, and S12). Thus, mutations that decrease growth parameters will be selected against by both natural selection and community selection. Fixing all growth parameters at their upper bounds greatly simplifies our analysis, as we demonstrate below.

*f*_{P} optimal for monoculture function may not be optimal for community function

It is unclear from Figure 3A how close the *P*(*T*) plateau is to maximal *P**(*T*). Given the nonlinear equations in our model (Methods Section 1), identifying global maximal is mathematically challenging.

Instead, after fixing all growth parameters to upper bounds and fixing total Newborn biomass to the target value (*N*_{0} = 100), we can identify (fraction of M growth diverted to making Product) and (fraction of M biomass in Newborn) corresponding to maximal community function (Methods, Section 3). For any *ϕ*_{M} (0), an intermediate *f*_{P} value maximizes community function (Figure 4A). This is not surprising: at zero *f*_{P}, no Product is made; at high *f*_{P}, H out-competes M. Importantly, the maximal *P**(*T*) identified above cannot be further improved if we allow all growth and production parameters to mutate (Figure S14). Thus, *P**(*T*) is locally maximal in the sense that small perturbations will always reduce *P*(*T*).

Although community selection in Figure 3 yields H and M whose growth parameters are fixed at their upper bounds, *P*(*T*) plateaus far below *P**(*T*), and *f*_{P} remains far below . To improve *f*_{P}, one might artificially select M for high production. Specifically, we may start with *n*_{tot} of 100 Newborn M groups, each inoculated with one M cell (to facilitate group selection, Figure S1B bottom panel). We supply each Newborn M group with the same amount of Resource as we supply Newborn H-M communities. For simplicity, we supply excess Byproduct to Newborn M groups since it is difficult to reproduce community Byproduct dynamics in M groups. Since here Newborn groups start with a single M individual, M-group selection can also be viewed as artificial selection of M individuals where the trait under selection is an individual’s ability to make Product over time *T* as the individual grows into a population. Regardless, our calculations show that *f*_{P} optimal for *P*(*T*) in monocultures also occurs at an intermediate value (0.13; Figure 4B): at zero *f*_{P}, production is zero; at *f*_{P} = 1, M cannot grow and may even die, and thus *P*(*T*) is low. Consistent with this calculation, when we select for high *P*(*T*) in M groups, *f*_{P} gradually increases to 0.13 (Figure S15). However, *f*_{P} optimal for monoculture *P*(*T*) is still much lower than *f*_{P} optimal for community *P*(*T*) (Figure 4; see Methods Section 8 for an explanation). How can we perform community selection to improve *f*_{P} and *P*(*T*) against natural selection’s pressure of reducing them?

### Community function fails to improve due to non-heritable variations

Starting with Newborns of mono-optimized H and M (all growth parameters at upper bounds and *f*_{P} = 0.13), we simulate artificial community selection (Figure 2; Methods Section 6). We only allow mutations to alter *f*_{P} as communities mature. Similar to Figure 3, we reproduce highest-functioning Adults by randomly partitioning them into Newborns with target total biomass *N*_{0} (Figure 2C). Experimentally, this is equivalent to calculating the fold-dilution by dividing *N*(*T*) (the turbidity of an Adult) by target *N*_{0} (the target turbidity of a Newborn), and performing this dilution by pipetting an appropriate volume of the Adult community into fresh medium (Methods Section 6). In this selection regimen, total biomass *N*(0) and fraction of M biomass *ϕ*_{M} (0) fluctuate stochastically in a Poissonian fashion (Methods Section 9). Similar to Figure 3, and community function fail to increase and remain far below optimum (Figure 6A, B).

To investigate the reason for this lack of improvement, we examine correlation between *P*(*T*) and Newborn composition in terms of average , Newborn total biomass *N*(0), and the fraction of M biomass in Newborn *ϕ*_{M} (0) (Figure 5). Here, *P*(*T*) largely depends on Newborn composition because new genotypes do not have enough time to rise to high frequencies during the short *T* (6 generations) to impact *P*(*T*). *P*(*T*) should ideally depend on *f*_{P} whose variations are heritable. However during community selection, we observe little correlation between *P*(*T*) and (Figure 5A). For example, the Adult displaying the highest function (left magenta dot) has a below-median .

In contrast, *P*(*T*) correlates strongly with *N*(0) and *ϕ*_{M} (0) (Figure 5B-C). *N*(0) and *ϕ*_{M} (0) can fluctuate stochastically during community reproduction. (Figure 5B-C; Methods 9). The reason for these strong correlations becomes clear when we examine community dynamics. To minimize stationary phase, we have chosen maturation time *T* so that a typical community depletes the majority but not all of Resource. A Newborn begins with abundant Resource and no Byproduct, so H will grow first and release Byproduct. As Byproduct accumulates, M will start to grow. When a Newborn starts with a higher-than-average *N*(0) (dotted lines in top panels of Figure S17), M will grow to a higher biomass, deplete Resource more thoroughly, and make more Product. Similarly, if a Newborn starts with a lower-than-average *ϕ*_{M} (0) (dotted lines in bottom panels of Figure S17), it will have a higher-than-average fraction of Helper. Consequently, M will endure a shorter growth lag, grow to a higher biomass, deplete Resource more thoroughly, and make more Product. Stochastic fluctuations in *N*(0) and *ϕ*_{M} (0) generate relatively large non-heritable variations in *P*(*T*) compared to *P*(*T*) variations caused by mutations in *f*_{P} (Figure 5 legend). Consequently, communities with the highest average *f*_{P} may not get selected (Figure 5A).

### Reducing non-heritable variations enables community function to improve

Reducing non-heritable variations should enable community selection to work. Indeed, if we fix both *N*(0) and *ϕ*_{M} (0) (Methods, Section 6), then *P*(*T*) becomes strongly correlated with (Figure 5D). Both and *P*(*T*) improve (Figure 6, G and H) to near the optimal. Experimentally, this can be achieved by flow-sorting into each Newborn a fixed biomass of H and M based on, for example, cell fluorescence intensity. *P*(*T*) improvement is not seen if either *N*(0) or *ϕ*_{M} (0) is non-fixed (Figure 6, C-F). *P*(*T*) also improves (Figure S18) if we distribute fixed H and M cell numbers (instead of biomass) into each Newborn (Methods, Section 6), which can be realized experimentally by flow sorting individual cells.

Alternatively, we can reduce non-heritable variations in *P*(*T*) by extending maturation time *T* so that an average community will deplete Resource by *T*. In this selection regimen, Newborns still experience Poissonian fluctuations in *N*(0) and *ϕ*_{M} (0) during community reproduction. However, those “unlucky” communities with smaller-than-average *N*(0) and/or larger-than-average *ϕ*_{M} (0) will have time to “catch up” as the “lucky” communities wait in stationary phase after exhausting Resource. Indeed, community function improves without having to fix *N*(0) or *ϕ*_{M} (0) (Figure 6, **I-J**). In practice, these selection regimens will only be effective if variations in stationary phase duration introduce minimal non-heritable variations in community function.

In summary, seemingly innocuous experimental procedures such as pipetting can introduce a sufficiently large non-heritable variations in community function to stall selection. If we suppress these non-heritable variations, community function can rapidly improve. These conclusions hold when we use a different mutation rate (2×10^{-5} instead of 2×10^{-3} per cell per generation, Figure S19), a different distribution of mutation effects (an non-null mutation increases or decreases *f*_{P} by on average 2%, Figure S20), or incorporating epistasis (Figure S21, an non-null mutation is more likely to reduce *f*_{P} if the current *f*_{P} is high, or enhance *f*_{P} if the current *f*_{P} is low; Methods Section 5; Figure S7). We have also modified the H-M community to be mutualistic. Specifically, Byproduct is now inhibitory to H. Thus, H benefits M by providing Byproduct, and M benefits H by removing Byproduct, similar to the syntrophic community of *Desulfovibrio vulgaris* and *Methanococcus maripaludis* [37]. We observe similar evolutionary dynamics in this mutualistic H-M community (Figure S22).

## Discussion

How might we improve functions of multi-species microbial communities via artificial selection? Currently, the most common approach is to enrich for the appropriate species combination [11, 12, 14, 15, 13]. For example, soil microbial communities that promote early or late flowering can be selected over ∼10 cycles, and the two types of communities have different species compositions [15]. However, if we solely rely on species combinations to improve community function, then without a constant influx of new species, community function will likely level off quickly [10].

Here, we consider artificial selection of communities with defined member species, with selection acting on genotypes. The conventional wisdom may suggest “you get what you select for”. But is this true? We have studied a Helper-Manufacturer community where community function is costly to Manufacturer. For community selection to be effective, we need to ensure that member species can stably coexist (Figure 2). Improving individual fitness can improve community function (Figures 3 and S10), although under different parameter choices, this is not true (Figure S9). Despite pre-optimizing member species in monocultures, community function may still be sub-optimal (Figure 4) due to the difficulty in recapitulating community dynamics in monocultures. Further improvements in community function can be achieved via artificial community selection, if performed properly.

Many aspects need to be taken into consideration when performing artificial community selection. Although suppressing non-heritable variations in a trait will always increase selection efficacy, here we show that for community selection, large non-heritable variations in community function can readily arise during routine experimental procedures such as pipetting. For example, if we choose maturation time *T* such that Resource is in excess to avoid stationary phase, then pipetting a volume of an Adult to seed a Newborn can already introduce non-heritable variations in community function (Figure 5B-C) sufficiently large to impede selection (Figure 6A-B). In contrast, if we fix both *N*(0) and *ϕ*_{M} (0) (via cell sorting for example), then community function rapidly improves (Figure 6G-H). If we extend maturation time *T* so that Resource will on average be nearly depleted by the end of *T*, then community function also improves (Figure 6I-J), provided that variations in stationary phase duration will not generate large, non-heritable variations in community function. We observe similar phenomena when we vary model assumptions such as using a lower mutation rate (Figure S19), employing a different distribution of mutation effects (Figure S20), considering epistatsis (Figure S21), as well as in mutualistic H-M communities (Figure S22).

In the work of Ref. [11], authors tested two selection regimens with Newborn sizes differing by 100-fold. The authors hypothesized that smaller Newborns would have a high level of variation which should facilitate selection. However, the hypothesis was not corroborated by experiments, and as a possible explanation, the authors invoked the “butterfly effect” (the sensitivity of chaotic systems to initial conditions). Our results suggest that even for non-chaotic systems like the H-M community, selection could fail because fluctuations in species compositions in small Newborns compromise heredity.

A general ramification of our theory is that before launching a selection experiment, we should experimentally evaluate how much non-heritable variations in community function might arise under different selection regimens. One could inoculate replicate Newborns with as identical initial conditions as possible (e.g. via cell sorting). However, some levels of stochasticity, such as non-genetic phenotypic variations [38], stochasticity in cell birth and death, and errors in community function measurements, are inevitable. If community function variations among these replicate communities are significant compared to those among communities harboring different genotypes (i.e. noise is large compared to signal), community selection may be ineffective. On the other hand, if variations among replicate communities are small, then one can test whether less precise procedures such as cell culture pipetting could be used instead.

How does artificial selection of multi-species communities compare with artificial selection of monospecies groups? Group selection, and in a related sense, kin selection [39, 40, 41, 34, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52], have been extensively examined to explain, for example, the evolution of traits that lower individual fitness (e.g. sterile ants) but increase the success of a group. In both group selection and community selection, Newborn size must not be too large and maturation time must not be too long, because otherwise, all entities will accumulate non-producers in a similar fashion, which interferes with selection [34, 53, 35] (Figure S1B). Community selection and group selection differ in two aspects. First, inter-species interactions in a community could drive species composition to a value sub-optimal for community function ([54]), and this problem does not exist for group selection especially when individuals in a group do not differentiate into interacting subgroups. Second, in group selection, when a Newborn group starts with a small number of individuals, a fraction of Newborn groups will show high similarity to the Newborn of the previous cycle (Figure S1B, bottom panel). This heredity facilitates group selection. In contrast, when a Newborn community starts with a small number of total individuals, large stochastic fluctuations in Newborn community composition can interfere with community selection (Figure 6). In the extreme case, a member species can even get lost by chance. Even if a fixed number of cells from each species are sorted into Newborns, heredity is much reduced in community selection compared to group selection. For example, if Newborn groups are initiated with a single cooperator and if the highest-functioning Adult group has accumulated 50% cheaters, then 50% Newborns of the next cycle will be initiated with a single cooperator. In contrast, if a Newborn community starts with a single cooperator from each of the two species and if the highest-functioning Adult has accumulated 50% cheaters in each species, then only 50% 50%= 25% Newborns of the next cycle will be initiated with pure cooperators.

When the total population size of a Newborn community is small, then each Newborn will inherit a small subset of genotypes from its parent Adult. If many communities are under selection, then in rare Newborns, beneficial genotypes from multiple species are simultaneously sampled. These Newborns harbor beneficial genotypes at high frequencies due to small Newborn size, and thus bear limited resemblance to Newborns of the previous cycle. In this case, reduction of heredity actually speeds up community selection, similar to sexual recombination: sexual recombination reduces heredity, but when population size is large, sexual recombination speeds up adaptation [55, 56, 57].

Microbes can coevolve with each other and with their host in nature [58, 59, 60]. This coevolution is mainly driven by natural selection. Might microbial community as a whole become a unit of selection in nature? Our work suggests that if selection for a costly microbial community function should occur in nature, then mechanisms for suppressing non-heritable variations in community function should be in place.

## Methods

### 1 A mathematical model of the H-M community

The initial conditions of a Newborn community include initial H biomass *H*(0), initial M biomass *M*(0), and the initial amounts of Resource , Byproduct (*B*(0) = 0), and Product (*P*(0) = 0). Starting from these initial conditions, the dynamics of H-< community comprising homogeneous H and M populations can be described by the following equations.

*H*, the biomass of H, changes as a function of growth and death,

Grow rate *g*_{H} depends on the level of Resource as described by the Monod growth model (Figure S3)
where is the at which *g*_{Hmax}*/*2 is achieved.

*M*, the biomass of M, changes as a function of growth and death,

Growth rate *g*_{M} depends on the levels of Resource and Byproduct ( and ) according to the Mankad-Bungay model [22]:
where and (Figure S3). 1 - *f*_{P} fraction of M growth is channeled to biomass increase. *f*_{P} fraction of M growth is channeled to making Product:
where is the amount of Product made at the cost of one M biomass.

Resource is consumed proportionally to the growth of M and H; Byproduct is released proportionally to H growth and consumed proportionally to M growth:

Here, *ĉ*_{RM} and *ĉ*_{RH} are the amounts of consumed per M and H biomass, respectively. *ĉ*_{BM} is the amount of consumed per M biomass. is the amount of released per H biomass grown. Our model assumes that Byproduct or Product is generated proportionally to H or M biomass grown, which is reasonable given the stoichiometry of metabolic reactions and the experimental support [61]. The volume of a community *V* is set to be 1, and thus cell or metabolite quantities (which are considered here) are numerically identical to cell or metabolite concentrations.

In equations above, scaling factors are marked by “∼”, and will become 1 after scaling. Variables and parameters with hats will be scaled and lose their hats afterwards. Variables and parameters without hats will not be scaled. We scale Resource-related variable and parameters (, and *ĉ*_{RH}) against (Resource supplied to Newborn), Byproduct-related variable and parameters ( and *ĉ*_{BM}) against (amount of Byproduct released per H biomass grown), and Product-related variable against (amount of Product made at the cost of one M biomass). For biologists who usually think of quantities with units, the purpose of scaling (and getting rid of units) is to reduce the number of parameters. For example, H biomass growth rate can be re-written as:
where and . Thus, the unscaled and the scaled *g*_{H} (*R*) share identical forms. After scaling, the value of becomes irrelevant (1 with no unit). Similarly, since and .

Thus, scaled equations are

We have not scaled time here, although time can also be scaled by, for example, the community maturation time. Here, time has the unit of unit time (e.g. hr), and to avoid repetition, we often drop the time unit. After scaling, values of all parameters (including scaling factors) are in Table 1, and variables in our model and simulations are summarized in Table 2.

### 2 Parameter choices

With Waste in excess, H can grow on Resource. For ancestral H, we set *g*_{Hmax} = 0.25, *K*_{HR} = 1 (i.e. *K*_{HR} is one unit of ) and *c*_{RH} = 10^{-4}. This way, ancestral H can grow by about 10-fold by the end of *T* = 17. These parameters are biologically realistic: time unit can be arbitrarily chosen, and if we choose hour as the unit, then *g*_{Hmax} translates to a doubling time of 2.8 hrs. For a *lys-S. cerevisiae* strain with lysine as Resource, un-scaled Monod constant is , and consumption ĉ is 2 fmole/cell (Ref. [62], Figure 2 Source Data 1; bioRxiv). Thus, if we choose 10 *µ*L as volume and 2 *µ*M as initial Resource concentration, then fmole. After scaling, and cell.

To ensure the coexistence of H and M, M must grow faster than H for part of the maturation cycle. Thus, i) *g*_{Mmax} must exceed *g*_{Hmax} (Figure 1) since we have assumed M and H to have the same affinity for R (Table 1); ii) M’s affinity for Byproduct (1*/K*_{MB}) must be sufficiently large; and iii) Byproduct consumed per Manufacturer *c*_{BM} must be sufficiently small so that growth of M can be supported by H. Thus for ancestral M, we choose *g*_{Mmax} = 0.58 (equivalent to a doubling time of 1.2 hrs). We set units of *r*(i.e. ). This means that Byproduct released during one H biomass growth is sufficient to generate 3 M biomass, which is biologically achievable ([63, 64]). When we choose units of (i.e. ), H and M can coexist for a range of *f*_{P} (Figure 1). This value is realistic. For example, let B be hypoxanthine. A hypoxanthine-requiring *S. cerevisiae* strain evolved under hypoxanthine limitation could achieve a Monod constant for hypoxanthine at 0.1 *µ*M (bioRxiv). If the volume of the community is 10 *µ*L, then corresponds to an absolute release rate fmole per releaser biomass born. At 8 hour doubling time, this translates to 6 fmole/(1 cell×8 hr)≈ 0.75 fmole/cell/hr, within the ballpark of experimental observation (∼0.3 fmole/cell/hr, bioRxiv). As a comparison, a lysine-overproducing yeast strain reaches a release rate of 0.8 fmole/cell/hr (bioRxiv) and a leucine-overproducing strain reaches a release rate of 4.2 fmole/cell/hr ([64]). Death rates *δ*_{H} and *δ*_{M} are chosen to be 0.5% of the upper bound of maximal growth rate, which is within the ballpark of experimental observations (e.g. the death rate of a *lys-* strain in lysine-limited chemostat is 0.4% of maximal growth rate, bioRxiv).

Since the biomass of various microbes share similar compositions of elements such as carbon or nitrogen [65], we assume that H and M consume the same amount of R per new cell (*c*_{RH} = *c*_{RM}). Since *c*_{RH} = *c*_{RM} = 10^{-4} after scaling against , the maximum yield is 10^{4} total biomass.

Growth parameters (maximal growth rates *g*_{Mmax} and *g*_{Hmax} and affinities for nutrients 1*/K*_{MR}, 1*/K*_{MB}, and 1*/K*_{HR}) and production parameter (*f*_{P} ∈ [0, 1]) are allowed to change during evolution, since these phenotypes have been observed to rapidly evolve within tens to hundreds of generations ([23, 24, 25, 26]). For example, several-fold improvement in nutrient affinity [24] and ∼20% increase in maximal growth rate [26] have been observed in experimental evolution. Thus we allow affinities 1*/K*_{MR}, 1*/K*_{HR}, and 1*/K*_{MB} to increase by 3-fold, 5-fold, and 5-fold respectively, and allow *g*_{Hmax} and *g*_{Mmax} to increase by 20%. These bounds also ensure that evolved H and M can coexist for *f*_{p} *<* 0.5, and that Resource is on average not depleted by *T* to avoid cells entering stationary phase. Although maximal growth rate and nutrient affinity can sometimes show trade-off (e.g. Ref. [24]), for simplicity we assume here that they are independent of each other. We hold metabolite consumption (*c*_{RM}, *c*_{BM}, *c*_{RH}) constant because conversion of essential elements such as carbon and nitrogen into biomass is unlikely to evolve quickly and dramatically, especially when these elements are not in large excess ([65]). Similarly, we hold the scaling factors and constant, assuming that they do not change rapidly during evolution due to stoichiometric constraints of biochemical reactions. We hold death rates (*δ*_{M}, *δ*_{H}) constant because they are much smaller than growth rates in general and thus any changes are likely inconsequential.

### 3 Choosing growth parameters to simplify evolutionary modeling

Although improving individual growth (maximal growth rate and affinity for metabolites) does not always lead to improved community function (Figure S9), we have chosen ancestral growth parameters and their upper bounds so that improving individual growth improves community function. This way, we can assemble Newborn communities using mono-adapted H and M where all growth parameters are fixed at their respective biological upper bounds.

Fixing growth parameters of H and M to upper bounds also allows us to identify a locally maximal community function: For a Newborn with total biomass *N*(0) = 100, we can calculate *P*(*T*) under various *f*_{P} and *ϕ*_{M} (0). Since both numbers range between 0 and 1, we calculate *P*(*T, f*_{P} = 0.01 × *i, ϕ*_{M} (0) =0.01 × *j*) for integers *i* and *j* between 1 and 99. There is a single maximum for *P*(*T*) when *i* = 41 and *j* = 54. In other words, when Newborn total biomass is fixed to 100, if M invests of its growth to make Product and fraction of M biomass in Newborn , maximal community function *P**(*T*) is achieved (Figure 4A; magenta dashed line in Figure 6).

Let’s first consider the case where . If we fix four of the five growth parameters to their upper bounds, then as the remaining growth parameter improves, both individual fitness and community function increase (magenta lines in Figure S10). Thus, if community function is already maximized, then deviations (reductions) from growth parameter upper bounds are disfavored by both community selection and natural selection, and hence growth parameters are naturally fixed.

Now let’s consider the case where *f*_{P} = 0.13, which is optimal for M-monoculture function (grey dotted line in Figure 4B) and our starting point for community selection. Community function and individual fitness generally increase as growth parameters improve (black dashed lines in Figure S10). However, individual fitness declines slightly when M’s affinity for Resource (1*/K*_{MR}) improves.

Mathematically speaking, this is a consequence of the Mankad-Bungay model [22] (Figure S4B). Let and . Then,

If (corresponding to limiting S_{1} and abundant S_{2}),
and thus *∂g/∂K*_{1} *<* 0. This is the familiar case where growth rate increases as the Monod constant decreases (i.e. affinity increases). However, if
and thus *∂g/∂K*_{1} *>* 0. In this case, growth rate decreases as the Monod constant decreases (i.e. affinity increases). This is equivalent to decreased affinity for the abundant nutrient improving growth rate. Transporter competition for membrane space [66] could lead to this result, since reduced affinity for abundant nutrient may increase affinity for rare nutrient.

In the case of M, let S_{1} represent R and let S_{2} represent B. Thus, *K*_{1} corresponds to *K*_{MR} and *K*_{2} corresponds to *K*_{MB}. At the beginning of each cycle, R is abundant and B is limiting (Eq. 12). Thus M cells with lower affinity for R will grow faster than those with higher affinity (Figure S11). At the end of each cycle, the opposite is true (Figure S11). As *f*_{P} decreases, M has the capacity to grow faster and the first stage becomes more important. Thus at low *f*_{P}, M can gain higher overall fitness by lowering affinity for R (Figure S11A), which decreaes *P*(*T*) very slightly (Figure S11B).

Regardless, decreased M affinity for Resource (1*/K*_{MR}) only leads to a very slight increase in M fitness and a very slight decrease in *P*(*T*). Moreover, this only occurs at low *f*_{P} at the beginning of community selection, and thus may be neglected. Indeed, if we start all growth parameters at their upper bounds and *f*_{P} = 0.13, and perform community selection while allowing all parameters to vary (Figure S12), then 1*/K*_{MR} decreases somewhat, yet the dynamics of *f*_{P} is similar to when we only allow *f*_{P} to change (compare Figure S12D with Figure 6A). Indeed, allowing both *f*_{P} and 1*/K*_{MR} to evolve does not change our conclusions as shown in Figure S13.

### 4 Mutation rate and phenotype spectrum

Among mutations, a fraction will be phenotypically neutral in that they do not affect the phenotype of interest. For example, the vast majority of synonymous mutations are neutral [67]. Experimentally, the fraction of neutral mutations is difficult to determine. Consider organismal fitness as the phenotype of interest. Whether a mutation is neutral or not can vary as a function of effective population size, and selection condition. For example, at low population size due to genetic drift (i.e. changes in allele frequencies due to chance), a beneficial or deleterious mutation may not be selected for or selected against, and is thus neutral with respect to selection [68, 69]. Mutations in an antibiotic-degrading gene can be neutral under low antibiotic concentrations, but deleterious under high antibiotic concentrations [70]. When considering single mutations, a larger fraction of neutral mutations is equivalent to a lower rate of phenotype-altering mutations. Herein, our “mutation rate” refers to the rate of mutations that either enhance a phenotype (“enhancing mutations”) or diminish a phenotype (“diminishing mutations”). Enhancing mutations of maximal growth rate (*g*_{Hmax} and *g*_{Mmax}) and of nutrient affinity (1*/K*_{HR}, 1*/K*_{MR}, 1*/K*_{MB}) enhance the fitness of an individual (“beneficial mutations”). In contrast, enhancing mutations in *f*_{p} diminish the fitness of an individual (“deleterious mutations”).

Depending on the phenotype, the rate of phenotype-altering mutations is highly variable. Although mutations that cause qualitative phenotypic changes (e.g. drug resistance) occur at a rate of 10^{-8}∼10^{-6} per genome per generation in bacteria and yeast [71, 72], mutations affecting quantitative traits such as growth rate occur much more frequently. For example in yeast, mutations that increase growth rate by ≥2% occur at a rate of ∼10^{-4} per genome per generation (calculated from Figure 3 of Ref. [73]), and mutations that reduce growth rate occur at a rate of 10^{-4} ∼10^{-3} per genome per generation [32, 29]. Moreover, mutation rate can be elevated by as much as 100-fold in hyper-mutators where DNA repair is dysfunctional [27, 28, 29]. Here for a mutable phenotype, we assume a high, but biologically feasible, rate of 2×10^{-3} phenotype-altering mutations per cell per generation to speed up computation. We have also tried 100-fold lower mutation rate. As expected, evolutionary dynamics slows down, but all of our conclusions still hold (Figure S19).

Among phenotype-altering mutations, tens of percent create null mutants, as illustrated by experimental studies on protein, viruses, and yeast [30, 31, 32]. Thus, we assume that 50% of phenotype-altering mutations are null (i.e. zero maximal growth rate, zero affinity for metabolite, or zero *f*_{P}). Among non-null mutations, the relative abundances of enhancing versus diminishing mutations are highly variable in different experiments. It can be impacted by effective population size. For example, with a large effective population size, the survival rate of beneficial mutations is 1000-fold lower due to clonal interference (competition between beneficial mutations) [74]. The relative abundance of enhancing versus diminishing mutations also strongly depends on the starting phenotype [30, 70, 68]. For example with ampicillin as a substrate, the TEM-1 *β*-lactamase acts as a “perfect” enzyme. Consequently, mutations were either neutral or diminishing, and few enhanced enzyme activity [70]. In contrast with a novel substrate such as cefotaxime, the enzyme had undetectable activity, and diminishing mutations were not detected while 2% of tested mutations were enhancing [70]. When we model H-M communities, we assume that the ancestral H and M have intermediate phenotypes that can be enhanced or diminished.

We base our distribution of mutation effects on experimental studies where a large number of enhancing and diminishing mutants have been quantified in an unbiased fashion. An example is a study from the Dunham lab where the fitness effects of thousands of *S. cerevisiae* mutations were quantified under various nutrient limitations [33]. Specifically for each nutrient limitation, the authors first measured , the deviation in relative fitness of thousands of bar-coded wild-type control strains from the wild-type mean fitness. Due to experimental noise, Δ*s*_{WT} is distributed with zero mean and non-zero variance. Then, the authors measured thousands of Δ*s*_{MT}, each corresponding to the relative fitness change of a bar-coded mutant strain with respect to the mean of wild-type fitness (i.e. ). From these two distributions, we derive *µ*_{Δs}, the probability density function (PDF) of relative fitness change caused by mutations Δ*s* = Δ*s*_{MT} Δ*s*_{WT} (see Figure 2B for interpreting PDF), in the following manner.

First, we calculate *µ*_{m}(Δ*s*_{MT}), discrete PDF of mutant strain relative fitness change, with bin width 0.04. In other words, *µ*_{m}(Δ*s*_{MT}) =counts in the bin of [Δ*s*_{MT} 0.02, −Δ*s*_{MT} + 0.02] / total counts/0.04 where ranges from 0 6 and 0.6 which is sufficient to cover the range of experimental outcome. The Poissonian uncertainty of *µ*_{m} is . Repeating this process for wild-type collection, we obtain PDF of wild-type strain relative fitness *µ*_{w}(Δ*s*_{WT}). Next, from *µ*_{w}(Δ*s*_{WT}) and *µ*_{m}(Δ*s*_{MT}), we derive *µ*_{Δs}(Δ*s*), the PDF of Δ*s* with bin width 0.04:
assuming that Δ*s*_{MT} and Δ*s*_{WT} are independent from each other. Here, *i* is an integer from -15 to 15. The uncertainty for *µ*_{Δs} is calculated by propagation of error. That is, if *f* is a function of *x*_{i} (*i* = 1, 2, …,*n*), then *s*_{f}, the error of *f*, is where is the error or uncertainty of *x*_{i}. Thus,
where *µ*_{w}(*j*) is short-hand notation for *µ*_{w}(Δ*s*_{WT} = *j*× 0.04) and so on. Our calculated *µ*_{Δs}(Δ*s*) with error bar of is shown in Figure S6.

Our reanalysis demonstrates that distributions of mutation fitness effects *µ*_{Δs}(Δ*s*) are largely conserved regardless of nutrient conditions and mutation types (Figure S6B). In all cases, the relative fitness changes caused by beneficial (fitness-enhancing) and deleterious (fitness-diminishing) mutations can be approximated by separate exponential distributions with different means *s*_{+} and *s*_{−}, respectively. After normalization to have a total probability of 1, we have:

We fit the Dunham lab haploid data (since microbes are often haploid) to Eq. 15, using as the weight for non-linear least squared regression (green lines in Figure S6B). We obtain *s*_{+} = 0.050 ± 0.002 and *s*_{-} = 0.067 ± 0.003.

Interestingly, exponential distribution described the fitness effects of deleterious mutations in an RNA virus significantly well [30]. Based on extreme value theory, the fitness effects of beneficial mutations are predicted to follow an exponential distribution [75, 76], which has gained experimental support from bacterium and virus [77, 78, 79] (although see [80, 73] for counter examples). Evolutionary models based on exponential distributions of fitness effects have shown good agreements with experimental data [74, 81].

We have also tried smaller average mutational effects based on measurements of spontaneous or chemically-induced (instead of deletion) mutations. For example, the fitness effects of nonlethal deleterious mutations in *S. cerevisiae* are mostly 1%∼5% [32], and the mean selection coefficient of beneficial mutations in *E. coli* was 1%∼2% [77, 74]. Thus, as an alternative, we choose *s*_{+} = 0.02; *s*_{−} = −0.02, and obtain similar conclusions (Figure S20).

### 5 Modeling epistasis on *f*_{P}

Epistasis, where the effect of a new mutation depends on prior mutations (“genetic background”), is known to affect evolutionary dynamics. Epistatic effects have been quantified in various ways. Experiments on viruses, bacteria, yeast, and proteins have demonstrated that for two mutations that are both deleterious or random, viable double mutants experience epistatic effects that are nearly symmetrically distributed around a value near zero [82, 83, 84, 85, 86]. In other words, a significant fraction of mutation pairs show no epistasis, and a small fraction show positive or negative epistasis (i.e. a double mutant displays a stronger or weaker phenotype than expected from additive effects of the two single mutants). Epistasis between two beneficial mutations can vary from being predominantly negative [83] to being symmetrically distributed around zero [84]. Furthermore, a beneficial mutation tends to confer a lower beneficial effect if the background already has high fitness (“diminishing returns”) [87, 84, 88].

A mathematical model by Wiser et al. incorporates diminishing returns epistasis [81]. In this model, beneficial mutations of advantage *s* in the ancestral background are exponentially distributed with probability density *α* exp(-*αs*), where 1*/α >* 0 is the mean advantage. After a mutation with advantage *s* has occurred, the mean advantage of the next mutation would be reduced to 1*/*[*α*(1 + *gs*)], where *g >* 0 is the “diminishing returns parameter”. Wiser et al. estimates *g*≈6. This model quantitatively explains the fitness dynamics of evolving *E. coli* populations.

Based on experimental and theoretical literature, we model epistasis on *f*_{P} in the following manner. Let the relative mutation effect on *f*_{P} be Δ*f*_{P} = (*f*_{P,mut} - *f*_{P}) */f*_{P} ≥ -1. Then, *µ*(Δ*f*_{P}, *f*_{P}), the probability density function of Δ*f*_{P} at the current *f*_{P} value, is described by a form similar to Eq. 15:

Here, *s*_{+}(*f*_{P}) and *s*_{-}(*f*_{P}) are respectively the mean Δ*f*_{P} for enhancing and diminishing mutations at current *f*_{P}. *s*_{+}(*f*_{P}) = *s*_{+init}*/*(1 + *g* × (*f*_{P} */f*_{P,init} *-* 1)), where *f*_{P,init} is the *f*_{P} of the initial background (e.g. 0.13 for mono-adapted Manufacturer), *s*_{+init} is the mean enhancing Δ*f*_{P} occurring in the initial background, and 0 *< g <* 1 is the epistatic factor. Similarly, *s*_{−} (*f*_{P}) = *s*_{−init} × (1 + *g* × (*f*_{P} */f*_{P,init} −1)) is the mean |Δ*f*_{P}*|* for diminishing mutations at current *f*_{P}. In the initial background since *f*_{P} = *f*_{P,init}, we have *s*_{+}(*f*_{P}) = *s*_{+init} and *s*_{−} (*f*_{P}) = *s*_{−init} where *s*_{+init} = 0.050 and *s*_{−init} = 0.067 (Figure S6). For subsequent mutations, PDF of Δ*f*_{P} is modified by epistatic factor *g* according to Eq. 16. Consistent with the diminishing returns principle, if current *f*_{P} *> f*_{P,init}, then a new enhancing mutation becomes less likely and its mean effect also becomes smaller, while a new diminishing mutation becomes more likely and its mean effect also becomes bigger (ensured by *g >* 0; Figure S7 right panel). Similarly, if current *f*_{P} *< f*_{P,init}, then a new enhancing mutation becomes more likely and its mean effect also becomes bigger, while a diminishing mutation becomes less likely and its mean effect also becomes smaller (ensured by 0 *< g <* 1; Figure S7 left panel). In summary, our model captures not only diminishing returns of enhancing mutations, but also our understanding of mutational effects on protein stability [68].

### 6 Simulation code of community selection cycle

In our simulation, cell mutation, cell death, and community reproduction are stochastic. All other processes (biomass growth, cell division, and changes in chemical concentrations) are deterministic.

The code starts with a total of *n*_{tot} = 100 Newborn communities with identical configuration:

each community has 100 total cells of biomass 1. Thus, total biomass

*N*(0) = 100.40 cells are H. 60 cells are M with identical

*f*_{P}. Thus,*M*(0) = 60 and*ϕ*_{M}(0) = 0.6.

In the beginning, a random number is used to seed the random number generator for each Newborn community, and this number is saved so that the sequence of random numbers used below can be exactly repeated for subsequent data analysis. The initial amount of Resource is 1 unit of , the initial Byproduct is *B*(0) = 0. and the initial Product *P*(0) = 0. The cycle time is divided into time steps of Δ*τ* = 0.05.

Below, we describe in detail what happens during each step of Δ*τ*. During an interval [*τ*, *τ* + Δ*τ*], Resource *R*(*t*) and Byproduct *B*(*t*) between [*τ*, *τ* + Δ*τ*] are calculated by solving the following equations between [*τ, τ* + Δ*τ*] with the initial condition *R*(*τ*) and *B*(*τ*) using the ode23s solver in Matlab:
where *M*(*τ*) and *H*(*τ*) are the biomass of M and H at time *τ*, respectively. The solutions from Eq. 17 and 18 are used in the integrals below.

We track the phenotypes of every H and M cell which are rod-shaped organisms of a fixed diameter. Let the biomass (length) of an H cell be *L*_{H} (*τ*). The continuous growth of *L*_{H} during *τ* and *τ* + Δ*τ* can be described as
thus *L*_{H} (*τ* + Δ*τ*) is
and

Similarly, let the length of an M cell be *L*_{M} (*τ*). The continuous growth of M can be described as

Thus during the interval [*τ, τ* + Δ*τ*],

Thus for an M cell, its length *L*_{M} (*τ* + Δ*τ*) is

From Eq. 7 and 8, within Δ*τ*,
and we get
where *M*(*τ* + Δ*τ*) = Σ *L*_{M} (*τ* + Δ*τ*) is the sum of the lengths of all M cells.

At the end of each Δ*τ*, each H and M cell has a probability of *δ*_{H} Δ*τ* and *δ*_{M} Δ*τ* to die, respectively. This is simulated by assigning a random number between [0, 1] for each cell and those receive a random number less than *δ*_{H} Δ*τ* or *δ*_{M} Δ*τ* get eliminated. For surviving cells, if a cell’s length ≥2, this cell will divide into two cells with half the original length.

After division, each cell has a probability of *P*_{mut} = 0.002 to acquire a mutation that changes each of its mutable phenotype (Methods, Section 4). As an example, let’s consider mutations in *f*_{P}. After mutation, *f*_{P} will be multiplied by (1 + Δ*f*_{P}), where Δ*f*_{P} is determined as below.

First, a uniform random number *u*_{1} between 0 and 1 is generated. If *u*_{1} ≤ 0.5, Δ*f*_{P} = −1, which represents 50% chance of a null mutation (*f*_{P} = 0). If 0.5 < *u*_{1} ≤ 1, Δ*f*_{P} follows the distribution defined by Eq. 16 with *s*_{+}(*f*_{P}) = 0.05 for *f*_{P} -enhancing mutations and *s*_{−} (*f*_{P}) = 0.067 for *f*_{P} -diminishing mutations when epistasis is not considered (Methods, Section 4). In the simulation, Δ*f*_{P} is generated via inverse transform sampling. Specifically, *C*(Δ*f*_{P}), the cumulative distribution function (CDF) of Δ*f*_{P}, can be found by integrating Eq. 15 from -1 to Δ*f*_{P} :

The two parts of Eq. 21 overlap at .

In order to generate Δ*f*_{P} satisfying the distribution in Eq. 15, a uniform random number *u*_{2} between 0 and 1 is generated and we set *C*(Δ*f*_{P}) = *u*_{2}. Inverting Eq. 21 yields

When epistasis is considered, *s*_{+}(*f*_{P}) = *s*_{+init}*/*(1 + *g* × (*f*_{P} */f*_{P,init} − 1)) and *s*_{−}(*f*_{P}) = *s*_{−init} × (1 + *g* × (*f*_{P} */f*_{P,init} − 1)) are used in Eq. 22 to calculated Δ*f*_{P} for each cell with different current *f*_{P} (Methods Section 5).

If a mutation increases or decreases the phenotypic parameter beyond its bound, the phenotypic parameter is set to the bound value.

The above growth-death/birth-mutation cycle is repeated from time 0 to *T*. Note that since the size of each M and H cell can be larger than 1, the integer numbers of M and H cells, *I*_{M} and *I*_{H}, are generally smaller than biomass *M* and *H*, respectively. At the end of *T*, the communities are sorted according to *P*(*T*).

For community reproduction, we save the current random number generator state to generate random numbers for partitioning the Adult. When we do not fix total biomass or total cell number or *ϕ*_{M} (0), we do the following. We select the Adult community with the highest function (or a randomly-chosen Adult community in control simulations). The fold by which this Adult will be diluted is *n*_{D} = ⌊ (*M*(*T*) + *H*(*T*)) */N*_{0}⌋ where *N*_{0} = 100 is the pre-set target for Newborn total biomass, and ⌊*x*⌋ is the floor function that generates the largest integer that is smaller than *x. I*_{H} + *I*_{M} random integers between 1 and *n*_{D} are uniformly generated so that each M and H cell is assigned a random integer between 1 and *n*_{D}. All cells assigned with the same random integer belong to the same Newborn. This generates *n*_{D} newborn communities. This partition regimen can be experimentally implemented by pipetting 1*/n*_{D} volume of an Adult community into a new well. If *n*_{D} is less than *n*_{tot} (the total number of communities under selection), all *n*_{D} newborn communities are kept. Then, we partition the Adult with the next highest function (or a random community in control simulations) to obtain an additional batch of *n*_{D} Newborns until we obtain *n*_{tot} Newborns. The next cycle then begins.

To “fix” Newborn total biomass *N*(0) to the target total biomass *N*_{0} (while allowing *ϕ*_{M} (0) to fluctuate), total biomass *N*(0) is counted so that *N*(0) comes closest to the target *N*_{0} without exceeding it (otherwise, *P*(*T*) may exceed the theoretical maximum). For example, suppose that a certain number of M and H cells have been sorted into a Newborn so that the total biomass is 98.6. If the next cell, either M or H, has a biomass of 1.3, this cell goes into the community so that the total biomass is 98.6 + 1.3 = 99.9. However, if a cell of mass 1.6 happens to be picked, this cell doesn’t go into this community so that this Newborn has a total biomass of 98.6 and the cell of mass 1.6 goes to the next Newborn. Thus, each Newborn may not have exactly the biomass of *N*_{0}, but rather between *N*_{0} − 2 and *N*_{0}. Experimentally, total biomass can be determined from the optical density, or from the total fluorescence if cells are fluorescently labeled (bioRxiv). To fix Newborn total cell number (instead of total biomass), we perform simulations where the we sort a total of ⌊*N*_{0}*/*1.5⌋ cells into each Newborn, assuming that the average biomass of an M or H cell is 1.5. We obtain the same conclusion, as shown in Figure S18.

To fix *ϕ*_{M} (0) (while allowing *N*(0) to fluctuate), we generate Newborn communities so that *ϕ*_{M} (0) = *ϕ*_{M} (*T*) of the selected Adult community from the previous cycle. Again, because each M and H has a biomass (or length) between 1 and 2, *ϕ*_{M} (0) of each Newborn community may not be exactly *ϕ*_{M} (*T*) of the selected Adult community. In the code, dilution fold *n*_{D} is calculated in the same fashion as mentioned above. *I*_{M} (*T*) random integers between [1, *n*_{D}] are then generated for each M cell. All M cells assigned the same random integer belong to the same Newborn community. A total biomass of *M*(0)(1−*ϕ*_{M} (*T*))*/ϕ*_{M} (*T*) of H cells should be sorted into this Newborn community. In the code, H cells are randomly dispensed into each Newborn community until the total biomass of H comes closest to *M*(0)(1−*ϕ*_{M} (*T*))*/ϕ*_{M} (*T*) without exceeding it. Again, because each H cell has a biomass between 1 and 2, the total biomass of H might not be exactly *M*(0)(1−*ϕ*_{M} (*T*))*/ϕ*_{M} (*T*) but between *M*(0)(1−*ϕ*_{M} (*T*))*/ϕ*_{M} (*T*)−2 and *M*(0)(1−*ϕ*_{M} (*T*))*/ϕ*_{M} (*T*). We have also performed simulations where the ratio of M and H cell numbers in the Newborn community, *I*_{M} (0)*/I*_{H} (0), is set to *I*_{M} (*T*)*/I*_{H} (*T*) of the Adult community, and obtain the same conclusion (Figure S18 center panels).

To fix *N*(0) to *N*_{0} and *ϕ*_{M} (0) to *ϕ*_{M} (*T*) of the parent Adult, M cells are randomly picked from the Adult until the total biomass of M comes closest to *N*_{0}*ϕ*_{M} (*T*) without exceeding it. H cells are sorted similarly. Because each M and H cells has a length between 1 and 2, the biomass of M can vary between *N*_{0}*ϕ*_{M} (*T*)−2 and *N*_{0}*ϕ*_{M} (*T*) and the biomass of H can vary between *N*_{0}(1 − *ϕ*_{M} (*T*)) − 2 and *N*_{0}(1 − *ϕ*_{M} (*T*)). Although such a partition scheme does not completely eliminate variations in species composition among Newborn communities, such variations are sufficiently small so that community selection can improve . We have also performed simulations where the total number of cells is set to ⌊*N*_{0}*/*1.5⌋ with ⌊*N*_{0}*φ*_{M} (*T*)*/*1.5⌋ M cells and ⌊*N*_{0}(1 − *φ*_{M} (*T*))*/*1.5⌋ H cells where *φ*_{M} (*T*) = *I*_{M} (*T*)*/*(*I*_{M} (*T*) + *I*_{H} (*T*)) is calculated from the numbers instead of biomass of M and H cells. We obtain the same conclusion (Figure S18, right panels).

### 7 Problems associated with alternative definitions of community function and alternative means of reproducing an Adult

We describe problems associated with two alternative definitions of community function. Let’s consider a simpler case where groups of Manufacturers are selected for high *P*, and cell death is negligible. We have
where biomass growth rate *g*_{M} is a function of *B* and *R*. When M and H compete for Resource, *g*_{M} also depends implicitly on *f*_{P} because *f*_{P} affects M:H and therefore *B* and *R*.

Since from Eq. 23 and 24
we have
if *M*(*T*) ≫ *M*(0). This is true if *T* is long enough for cells to double at least three or four times.

If we define community function as *P*(*T*)*/M*(*T*) (total Product normalized against *M* biomass in Adult community), . Under this definition, higher or higher *f*_{P} always leads to higher community function, and higher *f*_{P} in turn leads to *M* extinction (Figure 1).

If the community function is instead defined as *P*(*T*)*/M*(0), then

From Eq. 25, at a fixed increases as *∫*_{T} *g*_{M} ^{dt} increases. *∫*_{T} *g*_{M} ^{dt} increases as *ϕ*_{M} (0) decreases, since the larger fraction of Helper, the faster the accumulation of Byproduct and the larger *∫*_{T} *g*_{M} ^{dt} (Figure S17B). Thus, we end up selecting communities with small *ϕ*_{M} (0) (Figure S5). This means that Manufactures could get lost during community reproduction, and community selection then fails.

If Resource is unlimited, then it will be problematic to reproduce an Adult by diluting it by a fixed-fold to Newborns. This is because with unlimited Resource, there is no competition between H and M. According to Eq. 25, *P*(*T*) increases linearly with *M*(0). *P*(*T*) also increases with *H*(0), since higher *H*(0) leads to higher Byproduct and consequently higher *g*_{M} *dt* in the exponent. Thus each cycle, communities with larger *N*(0) (instead of higher *f*_{p}) will get selected.

### 8 is smaller for M group than for H-M community

For groups or communities with a certain *∫*_{T} *g*_{M} ^{dt}, we can calculate *f*_{P} optimal for community function from Eq. 25 by setting

We have or

If *∫*_{T} *g*_{M} ^{dt} ≫ 1, *f*_{P} is very small, then the optimal *f*_{P} for *P*(*T*) is

M grows faster in monoculture than in community because B is supplied in excess in monoculture while in community, H-supplied Byproduct is initially limiting. Thus, *∫*_{T} *gM* ^{dt} is larger in monoculture than in community. According to Eq. 26, is smaller for monoculture than for community.

### 9 Stochastic fluctuations during community reproduction

*N*(0) fluctuates in a Poissonian fashion with a standard deviation of , where “E” means the expected value.

*M*(0) and *H*(0) fluctuate independently with a standard deviation of and , respectively. Therefore, *M*(0)*/H*(0) fluctuates with a variance of
where “Cov” means covariance and “Var” means variance, and *ϕ*_{M} (*T*) is the fraction of M biomass in the Adult community from which Newborns are generated.

### 10 Mutualistic H-M community

In the mutualistic H-M community, Byproduct inhibits the growth of H. According to [89], the growth rate of *E. coli* decreases exponentially as the exogenously added acetate concentration increases. Thus, we only need to modify the growth of H by a factor of exp(−*B/B*_{0}) where *B* is the concentration of Byproduct and *B*_{0} is the concentration of Byproduct at which H’s growth rate is reduced by *e*^{−1}∼0.37:

The larger *B*_{0}, the less inhibitory effect Byproduct has on H and when *B*_{0} → +∞ Byproduct does not inhibit the growth of H. For simulations in Figure S22, *B*_{0} = 2*K*_{MB}.

## Acknowledgment

We thank the following for discussions: members of the Shou group, Lin Chao (UCSD), Maitreya Dunham (UW Seattle), Corina Tarnita (Princeton), and Harmit Malik (Fred Hutch). We thank Alex Yuan (UW Seattle), Chichun Chen (Indiana University Bloomington), Bill Hazelton, Samuel Hart, David Skelding, and Doug Jackson for feedback on the manuscript. This research was supported by the High Performance Computing Shared Resource of the Fred Hutch (P30 CA015704).

## References

- [1].↵
- [2].↵
- [3].↵
- [4].↵
- [5].↵
- [6].↵
- [7].↵
- [8].↵
- [9].↵
- [10].↵
- [11].↵
- [12].↵
- [13].↵
- [14].↵
- [15].↵
- [16].↵
- [17].↵
- [18].↵
- [19].↵
- [20].↵
- [21].↵
- [22].↵
- [23].↵
- [24].↵
- [25].↵
- [26].↵
- [27].↵
- [28].↵
- [29].↵
- [30].↵
- [31].↵
- [32].↵
- [33].↵
- [34].↵
- [35].↵
- [36].↵
- [37].↵
- [38].↵
- [39].↵
- [40].↵
- [41].↵
- [42].↵
- [43].↵
- [44].↵
- [45].↵
- [46].↵
- [47].↵
- [48].↵
- [49].↵
- [50].↵
- [51].↵
- [52].↵
- [53].↵
- [54].↵
- [55].↵
- [56].↵
- [57].↵
- [58].↵
- [59].↵
- [60].↵
- [61].↵
- [62].↵
- [63].↵
- [64].↵
- [65].↵
- [66].↵
- [67].↵
- [68].↵
- [69].↵
- [70].↵
- [71].↵
- [72].↵
- [73].↵
- [74].↵
- [75].↵
- [76].↵
- [77].↵
- [78].↵
- [79].↵
- [80].↵
- [81].↵
- [82].↵
- [83].↵
- [84].↵
- [85].↵
- [86].↵
- [87].↵
- [88].↵
- [89].↵
- [90].↵
- [91].↵
- [92].↵
- [93].↵
- [94].↵
- [95].↵
- [96].↵