## Abstract

Multi-species microbial communities often display “community functions” arising from interactions of member species. Interactions are often difficult to decipher, making it challenging to design communities with desired functions. Alternatively, similar to artificial selection for individuals in agriculture and industry, one could repeatedly choose communities with the highest community functions to reproduce by randomly partitioning each into multiple “Newborn” communities for the next cycle. However, previous efforts in selecting complex communities have generated mixed outcomes that are difficult to interpret. To understand how to effectively enact community selection, we simulated community selection to improve a community function that requires two species and imposes a fitness cost on one or both species. Our simulations predict that improvement could be easily stalled unless various aspects of selection, including promoting species coexistence, suppressing non-contributors, adopting a “bet-hedging” strategy when choosing communities to reproduce, and reducing stochastic fluctuations in species biomass of Newborn communities, were carefully considered. When these considerations were addressed in experimentally feasible manners, community selection could overcome natural selection to improve community function, and may even force species to evolve growth restraint to achieve species coexistence. Our conclusions hold under various alternative model assumptions, and are thus applicable to a variety of communities.

## Introduction

Multi-species microbial communities often display important *community functions*, defined 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]. Community functions arise from *interactions* where an individual alters the physiology of another individual. Thus, to improve community functions, one could identify and modify interactions [2, 3]. In reality, this is no trivial task: each species can release tens or more compounds, many of which may influence the partner species in diverse fashions [4, 5, 6, 7]. From this myriad of interactions, one would then need to identify those critical for community function, and modify them by altering species genotypes or the abiotic environment. One could also artificially assemble different combinations of species or genotypes at various ratios to screen for high community function (e.g. [8, 9]). However, some species may not be culturable in isolation, and the number of combinations becomes very large even for a moderate number of species and genotypes especially if various ratios were to be tested.

In an alternative approach, artificial selection of whole communities could be carried out over cycles to improve community function [10, 11, 12, 13, 14] (reviewed in [15, 16, 17]; Figure 1A). A selection cycle starts with a collection of low-density “Newborn” communities with artificially-imposed boundaries (e.g. inside culture tubes). These low-density communities are incubated for a period of time (“maturation”) to form “Adult” communities. During maturation, community members multiply and interact with each other and possibly mutate, and the community function of interest (purple shade) develops. At the end of maturation, desired Adult communities (e.g. darkest purple shade) are chosen to “reproduce” where each is randomly partitioned into multiple Newborn communities to start the next cycle. Superficially, this process may seem straightforward since “one gets what one selects for”. After all, artificial selection on individuals has been successfully implemented to obtain, for example, proteins of enhanced activities ([18, 19, 20]; Figure S1). However, compared to artificial selection of individuals or mono-species groups, artificial selection of multi-species communities is more challenging (see detailed explanation in Figure S1). For example, member species critical for community function may get lost during selection cycles.

The few attempts at community selection have generated interesting results. One theoretical study simulated artificial selection on multi-species communities based on the presence or absence of a member species [21]. Communities responded to selection, but only under certain conditions. In another theoretical study, multi-species communities responded to artificial selection based on their ability to modify their abiotic environment in user-defined fashions [12]. In both cases, the response to selection quickly leveled off, and could be generated without mutations. Thus, community selection acted entirely on species types instead of new genotypes [21, 12]. In experiments, complex microbial communities were selected for various traits [10, 11, 13, 14]. For example, microbial communities selected to promote early or late flowering in plants were dominated by distinct species types [13]. However in other cases, a community trait may fail to improve despite selection, and may improve even without selection [10, 11].

Because communities used in these selection attempts were complex, much remains unknown. First, was the trait under selection a community function or achievable by a single species? If the latter, then community selection may not be needed, and the simpler task of selecting individuals or mono-species groups could be performed instead (Figure S1). Second, did selection act solely on species types or also on newly-arising genotypes? If selection acted solely on species types ([21, 12, 13]), then without immigration of new species to generate new variations, community function may quickly plateau [21, 12]. If selection acted on genotypes, then community function could continue to improve as new genotypes evolve. Finally, why might a community trait sometimes fail to improve despite selection [10, 11]?

In this study, we simulated artificial selection on communities with two defined species whose phenotypes can be modified by random mutations. Our goal is to improve a “costly” community function. A community function is costly if any community member’s fitness is reduced by contributing to that community function (Figure 1B). Costly community functions are particularly challenging to improve: since contributors to community function grow slower than non-contributors, non-contributors will take over during community maturation. If all Adult communities are dominated by non-contributors, then community selection will fail. To improve a costly community function, inter-community selection during community reproduction (which occurs infrequently once every cycle) must overcome intra-community selection throughout community maturation (Figure 1B).

By simulating a simplified two-species community, we could compare the efficacy of different selection regimens with relative ease, and begin to mechanistically understand evolutionary dynamics during community selection. We also designed our simulations to mimic real lab experiments so that our conclusions could guide future experiments. For example, our simulations incorporated not only chemical mechanisms of species interactions (as advocated by [22, 23]), but also experimental procedures (e.g. pipetting cultures during community reproduction). Model parameters, including species phenotypes, mutation rate, and distribution of mutation effects, were based on a wide variety of published experiments. Note that most previous models focused on binary genotypes (e.g. contributing or not contributing to community function), and therefore could not model community function improvement driven by the evolution of quantitative phenotypes. We show that artificial community selection can improve a costly community function, but only after circumventing a multitude of failure traps.

## Results

We will first introduce the subject of our community selection simulation: a commensal two-species community that converts substrates to a valued product. We will then define community function, and describe how we simulate artificial community selection. Using simulation results, we will demonstrate critical measures that make community selection effective, including promoting species coexistence, suppressing non-contributors, adopting a “bet-hedging” strategy when choosing Adult communities to reproduce, and being mindful about how routine experimental procedures can impede selection. Finally, we show that our conclusions are robust under alternative model assumptions, applicable to mutualistic communities and communities whose member species may not coexist. To avoid confusion, we will use “community selection” or “selection” to describe the entire process of artificial community selection (community formation, growth, selection, and reproduction), and use “choose” or “inter-community selection” to refer to the selection step where the experimentalist decides which communities will reproduce.

### A Helper-Manufacturer community that converts substrates into a product

Motivated by previous successes in engineering two-species microbial communities that convert substrates into useful products [24, 25, 26], we numerically simulated selection of such communities.

In our community, Manufacturer M can manufacture Product P of value to us (e.g. a bio-fuel or a drug) at a fitness cost to self, but only if assisted by Helper H (Figure 1C). Specifically, Helper but not Manufacturer can digest an agricultural waste (e.g. cellulose), and as Helper grows biomass, Helper releases Byproduct B at no fitness cost to itself. Manufacturer requires H’s Byproduct (e.g. carbon source) to grow. In addition, Manufacturer invests *f*_{P} (0 ≤ *f*_{P} ≤ 1) fraction of its potential growth to make Product P while using the rest (1 − *f*_{P}) for its biomass growth. Both species also require a shared Resource R (e.g. nitrogen). Thus, the two species together, but not any species alone, can convert substrates (agricultural waste and Resource) into Product.

We define community function as the total amount of Product accumulated as a low-density Newborn community grows into an Adult community over maturation time *T*, i.e. *P*(*T*). In Discussions, we explain problems associated with an alternative definition of community function (e.g. per capita production; Methods Section 7; Figure S2). We will initially focus on the scenario where community function is not costly to Helpers, but incurs a fitness cost of *f*_{P} to M. Later, we will show that our conclusions also hold when community function is costly to both H and M. Below, we will describe how we simulated community selection, followed by how we chose parameters of species phenotypes and parameters of selection regimen.

### Simulating community selection

We simulated four stages of community selection (Figure 1D): (i) forming Newborn communities; (ii) Newborn communities maturing into Adult communities; (iii) choosing high-functioning Adult communities, and (iv) reproducing the chosen Adult communities by splitting each into multiple Newborn communities of the next cycle. Our simulation was individual-based. That is, it tracked phenotypes and biomass of individual H and M cells in each community as cells grew, divided, mutated, or died. Our simulations also tracked dynamics of chemicals (including Product) in each community, and accounted for actual experimental steps such as pipetting cultures during community reproduction. Below is a brief summary of our simulations, with more details in Methods (Section 6).

Each simulation started with *n*_{tot} number of Newborn communities. Each Newborn community always started with a fixed amount of Resource *R*(0) and a total biomass close to a target value *BM*_{target} (see Discussions for problems associated with not having a biomass target, such as diluting an Adult by a fixed fold into Newborns). Agricultural waste was always supplied in excess and thus did not enter our equations. Note that except for the first cycle, the relative abundance of species in a Newborn community was approximately that of its parent Adult community.

During community maturation, biomass of individual cells grew. The biomass growth rate of an H cell depended on Resource concentration (Monod equation; Figure S3A; Eq. 23). As H grew, it consumed Resource and simultaneously released Byproduct (Eqs. 21 and 22). The potential growth rate of an M cell depended on the concentrations of Resource and H’s Byproduct (Mankad-Bungay dual-nutrient equation [27]; Figure S3B; see experimental support in Figure S4). M cell’s actual biomass growth rate was (1 − *f*_{P}) fraction of M’s potential growth rate (Eq. 24). As M grew, it consumed Resource and Byproduct (Eqs. 21 and 22), and released Product at a rate proportional to *f*_{P} and M’s potential growth rate (Eqs. 8). Once an H or M cell’s biomass grew from 1 to 2, it divided into two cells of equal biomass with identical phenotypes, thus capturing experimental observations of continuous biomass increase (Figure S5) and discrete cell division events [28]. Meanwhile, H and M cells died stochastically at a constant death rate. Although mutations can occur during any stage of the cell cycle, we assigned mutations immediately after cell division, where each phenotype of both cells mutated independently.

Mutable phenotypes included H and M’s maximal growth rates and affinities for nutrients (“growth parameters”), and M’s *f*_{P} (the fraction of potential growth diverted for making Product), since these phenotypes have been observed to rapidly change during evolution ([29, 30, 31, 32]). Mutated phenotypes could range between 0 and their respective evolutionary upper bounds. Among mutations that alter phenotypes (denoted “mutations”), on average, half abolished the function (e.g. zero growth rate, zero affinity, or *f*_{P} = 0) based on experiments on GFP, viruses, and yeast [33, 34, 35]. Effects of the other 50% mutations were bilateral-exponentially distributed, enhancing or diminishing a phenotype by a few percent, based on our re-analysis of published yeast data sets [36] (Figure S6). We held death rates constant, since death rates were much smaller than growth rates and thus mutations in death rates would be inconsequential. We also held release and consumption coefficients constant. This is because, for example, the amount of Byproduct released per H biomass generated is constrained by biochemical stoichiometry.

At the end of community maturation time *T*, we compared community function *P*(*T*) (the total amount of Product accumulated in the community by time *T*) for each Adult community, and chose high-functioning Adults to reproduce. Each chosen Adult was randomly partitioned into Newborns with target total biomass *BM*_{target}. For example, if the chosen Adult had a total biomass of 60*BM*_{target}, then each cell would be assigned a random integer from 1 to 60, and those cells with the same random integer would be allocated to the same Newborn. Experimentally, this is equivalent to volumetric dilution using a pipette. Thus, for each Newborn, the total biomass and species ratio fluctuated around their expected values in a fashion associated with pipetting (Methods Section 9). In the “top-dog” strategy, we always chose the highest-functioning Adult available to us: after the highest-functioning Adult was used up for making Newborns, we then reproduced the next highest-functioning Adult in the same way and randomly chose enough Newborns so that a total of *n*_{tot} Newborns were generated for the next selection cycle.

### Choosing species: enhancing species coexistence

In order to improve community function through community selection, species need to coexist throughout selection cycles. That is, all species must grow at a similar average growth rate within each cycle. Furthermore, species ratio should not be extreme because otherwise, the low-abundance species could be lost by chance during Newborn formation. Species coexistence at a moderate ratio has been experimentally realized in engineered communities [24, 25, 37, 38].

To achieve species coexistence at a moderate ratio in the H-M community, three considerations need to be made. First, the fraction of growth M diverted for making Product (*f*_{P}) must not be too large, otherwise M would always grow slower than H and thus eventually go extinct (Figure 2A, top). Second, H and M’s growth parameters (maximal growth rates in excess nutrients; affinities for nutrients) must be balanced. This is because upon Newborn formation, H can immediately start to grow on agricultural waste and Resource, while M cannot grow until H’s Byproduct has accumulated to a sufficiently high level. Thus to achieve coexistence, M must grow faster than H at some point during community maturation. Third, to achieve a moderate steady-state species ratio, metabolite release and consumption need to be balanced [37]. Otherwise, the ratio between metabolite releaser and consumer can be extreme.

Based on these considerations and published yeast and *E. coli* measurements, we chose H and M’s ancestral growth parameters and their evolutionary upper bounds, as well as release, consumption, and death parameters (Table 1, Methods Section 2). This ensured that throughout evolution, different species ratios would converge toward a moderate steady state value during community maturation (Figure 2A, bottom). Note that if species were not chosen properly, selection might fail due to insufficient species coexistence (Figure 6A), although we will demonstrate that under effective community selection, requirements on species coexistence could be relaxed (Figure 6B and C).

### Choosing selection regimen parameters: avoiding known failure modes

After choosing member species with appropriate phenotypes, we need to consider the parameters of our selection regimen (Figure 1D). These parameters include the total number of communities under selection (*n*_{tot}), the number of Adult communities chosen to reproduce (*n*_{chosen}), Newborn target total biomass (*BM*_{target}) which indicates the “bottleneck size” when splitting an Adult community into Newborn communities, the amount of Resource added to each Newborn (*R*(0)), the amount of mutagenesis which controls the rate of phenotype-altering mutations (*μ*), and maturation time (*T*). Compared to the well-studied problem of group selection where the unit of selection is a mono-species group [39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53], community selection is more challenging (Discussions; Figure S1). However, the two types of selections do share some common aspects (Discussions; Figure S1). Thus, we can apply group selection theory, together with other practical considerations, to better design community selection regimen.

If the total number of communities *n*_{tot} is very large, then the chosen community will likely display a higher community function than if *n*_{tot} is small, but experimentally achieving a large *n*_{tot} is more challenging. We chose a total of 100 communities (*n*_{tot}=100).

*n*_{chosen}, the number of Adults chosen by the experimentalist to reproduce, reflects selection strength. Since the top-functioning Adult is presumably the most desirable, we reproduced it into as many Newborns as possible, and then reproduced the second best etc until we obtained *n*_{tot} Newborn communities for the next cycle (the “top-dog” strategy). Later, we will compare the “top-dog” strategy with other strategies employing weaker selection strengths.

If the mutation rate is very low, then community function cannot rapidly improve. If the mutation rate is very high, then non-contributors will be generated at a high rate, and as the fast-growing non-contributors take over during community maturation, community function will likely collapse. Here, we chose *μ*, the rate of phenotype-altering mutations, to be biologically realistic (0.002 per cell per generation per phenotype, which is lower than the highest values observed experimentally; Methods Section 4).

If Newborn target total biomass *BM*_{target} is very large, or if the number of doublings within maturation time *T* is very large, then non-contributors will take over in all communities during maturation (Figure S7, compare B-D with A), as predicted by group selection theory. On the other hand, if both *BM*_{target} and the number of generations within *T* are very small, then mutations will be rare within each cycle, and many cycles will be required to improve community function. Finally, if *BM*_{target} is very small, then a member species might get lost by chance during Newborn formation. In our simulations, we chose Newborn’s target total biomass *BM*_{target} = 100 biomass (50~100 cells). Unless otherwise stated, we fixed the input Resource *R*(0) to support a maximal total biomass of 10^{4}, and chose maturation time *T* so that even if H and M had evolved to grow as fast as possible, total biomass would undergo ~6 doublings (increasing from ~100 to ~7000). Thus, by the end of *T*, ≤70% Resource would be consumed by an average community. This meant that when implemented experimentally, we could avoid complications of Resource depletion and stationary phase, while not wasting too much Resource.

### Community selection may not be effective under conditions reflecting common lab practices

We initially simulated community selection, only allowing M’s *f*_{P} to be modified by mutations while fixing H and M’s growth parameters (maximal growth rates in excess metabolites; affinities for metabolites) to their evolutionary upper bounds. Such a simplification is justified with our particular parameter choices (Table 1) for the following reasons. First, during community selection growth parameters improved to their evolutionary upper bounds anyways (Figure S8C and F). Second, we obtained qualitatively similar conclusions regardless of whether we fixed growth parameters or not (e.g. compare final community functions in Figure 3B and E versus Figure S8A and D). Later, we will show a case where growth parameters cannot be fixed to upper bounds (Figure 6). In the current case if Newborn’s total biomass is fixed to the target value, then with only *f*_{P} mutating, we can calculate the theoretical maximal community function *P**(*T*) and its associated optimal and optimal species ratio (Figure 2B). We started with ancestral *f*_{P} lower than . Could inter-community selection for high community function increase ancestral *f*_{P} to , despite intra-community natural selection favoring lower *f*_{P}?

As expected, in control simulations where Adult communities were randomly chosen to reproduce, community function was driven to zero by natural selection as fast-growing non-producing M took over (Figure S9).

When we used the “top-dog” strategy and chose the top-functioning communities to reproduce, *f*_{P} and community function *P*(*T*) did not decline to zero, but they barely improved, and both were far below their theoretical optima (Figure 3A and B).

### Common lab practices can generate sufficiently large non-heritable variations in community function to interfere with selection

Why did community selection fail to improve *f*_{P} and community function? One possibility is that community function was not sufficiently heritable from one cycle to the next (Figure S1). We therefore investigated the heredity of community function by examining the heredity of community function determinants.

Community function *P*(*T*) was largely determined by phenotypes of cells in the Newborn community. This is because maturation time was sufficiently short (~6 doublings) that newly-arising genotypes could not rise to high frequencies within one cycle to significantly affect community function. Since all phenotypes except for *f*_{P} were fixed, community function had three independent determinants: Newborn’s total biomass *BM*(0), Newborn’s fraction of M biomass *ϕ*_{M}(0), and the average *f*_{P} over all M cells in Newborn (Eq 6-10).

A community function determinant is considered heritable if it is correlated between Newborns of one cycle (Figure 4A, bottom row) and their respective progeny Newborns in the next cycle (Figure 4A, color-matched top row). Among the three determinants, was heritable (Figure 4B): if a Newborn community had a high average *f*_{P}, so would the mature Adult community and Newborn communities reproduced from it. On the other hand, Newborn total biomass *BM*(0) was not heritable (Figure 4C). This is because when an Adult community reproduced via pipette dilution, the dilution factor was adjusted so that the total biomass of a progeny Newborn community was on average the target biomass *BM*_{target}. Newborn’s fraction of M biomass *ϕ*_{M}(0), which fluctuated around that of its parent Adult, was not heritable either (Figure 4D). This is because regardless of the species composition of Newborns, Adults would have similar steady state species composition (Figure 2A bottom panel), and so would their offspring Newborns.

In successful community selection, variations in community function should be mainly caused by variations in its heritable determinants. However, we found that community function *P*(*T*) weakly correlated with its heritable determinant , but strongly correlated with its non-heritable determinants (Figure 4E-G). For example, the Newborn that would achieve the highest function had a below-median (left magenta dot in Figure 4E), but had high total biomass *BM*(0) and low fraction of M biomass *ϕ*_{M}(0) (Figure 4F, G). In other words, variation in community function is largely non-heritable, as it largely arises from variation in non-heritable determinants.

The reason for strong correlations between *P*(*T*) and the two non-heritable determinants became clear by examining community dynamics. Recall that to avoid stationary phase, we had chosen maturation time so that Resource would be in excess by the end of maturation. Thus, a “lucky” Newborn community starting with a higher-than-average total biomass would convert more Resource to Product (dotted lines in top panels of Figure S11). Similarly, if a Newborn started with higher-than-average fraction of Helper H biomass, then H would produce higher-than-average Byproduct which meant that M would endure a shorter growth lag and make more Product (dotted lines in bottom panels of Figure S11).

To summarize, when community function significantly correlated with its non-heritable determinants (Figure 4F & G), community selection failed to improve community function (Figure 3B).

### Reducing non-heritable variations in an experimentally feasible manner promotes artificial community selection

Reducing non-heritable variations in community function should enable community selection to work. One possibility would be to reduce the stochastic fluctuations in non-heritable determinants. Indeed, when each Newborn received a fixed biomass of Helper H and Manufacturer M (“cell-sorting”; i.e. fixing *BM*(0) and *ϕ*_{M}(0); Methods, Section 6), community function *P*(*T*) became strongly correlated with its heritable determinant (Figure 3F). In this case, both and community function *P*(*T*) improved under selection (Figure 3, D and E) to near the optimal. *P*(*T*) improvement was not seen if either Newborn total biomass or species fraction was allowed to fluctuate stochastically (Figure S12). *P*(*T*) also improved if fixed numbers of H and M cells (instead of biomass) were allocated into each Newborn, even though each cell’s biomass fluctuated between 1 and 2 (Figure S13C; Methods, Section 6). Allocating a fixed biomass or number of cells from each species to Newborn communities could be experimentally realized using a cell sorter if different species have different fluorescence ([54]).

Non-heritable variations in *P*(*T*) could also be curtailed by reducing the dependence of *P*(*T*) on non-heritable determinants. For example, we could extend the maturation time *T* to nearly deplete Resource. In this selection regimen, Newborns would still experience stochastic fluctuations in Newborn total biomass *BM*(0) and fraction of M biomass *ϕ*_{M}(0). However, all communities would end up with similar *P*(*T*) since “unlucky” communities would have time to “catch up” as “lucky” communities wait in stationary phase. Indeed, with this extended *T*, community function became strongly correlated with its heritable determinant and community function improved without having to fix Newborn total biomass or species composition (Figure 3, J-L; Figure S13D). However in practice, non-heritable variations in community function could still arise from stochastic fluctuations in the duration of stationary phase (which could affect cell survival or recovery time in the next selection cycle).

### Bet-hedging can promote community selection when non-heritable variations in community function hinder selection

Since the highest community function may not correspond to the highest *f*_{P} (Figure 3C), we examined whether a “bet-hedging” strategy might outperform the “top-dog” strategy. In the “bet-hedging” strategy, we chose, for example, the top ten Adults, each reproducing ten Newborns. Although the “bet-hedging” strategy did not work as effectively as minimizing non-heritable variations in community function (compare Figure 3 D-F “cell-sorting” with G-I “bet-hedging”; Figure S14), “bet-hedging” under a wide range of selection strengths outperformed “top-dog”. Specifically, when we used pipetting to dilute Adults into Newborns, community function failed to improve under the “top-dog” strategy, but improved when top 5 to top 50 Adult communities were chosen to reproduce (Figure S15; Figure 3, compare G-I with A-C).

The superiority of “bet-hedging” over “top-dog” rests on giving “unlucky” Adults a chance to reproduce. We reached this conclusion by noting that if we minimized non-heritable variations in community function by fixing species biomass in Newborns (“cell-sorting”), then the “top-dog” strategy is superior to the “bet-hedging” strategy (Figure S16).

As expected, uncertainty in community function measurement - another source of non-heritable variation - interferes with community selection (compare Figure 3 A-I with Figure 5 A, C). In this case, “bet-hedging” and “cell-sorting” can synergize to increase the efficacy of community selection (Figure 5, compare B and C with D). Since it is difficult to suppress non-heritable variations in community function, the “bet-hedging” strategy could be useful for experimentalists.

### Community selection can enforce species coexistence

In most communities, species coexistence may not be guaranteed due to competition for shared resources. Here, we show that properly executed community selection could also improve the functions of such communities, in part by enforcing species coexistence. Consider an H-M community where, unlike the H-M community we have considered so far, H had the evolutionary potential to grow much faster than M. In this case, high community function not only required M to pay a fitness cost of *f*_{P}, but also required H to grow sufficiently slowly to not out-compete M.

We started community selection at ancestral growth parameters, and allowed them and *f*_{P} to mutate. When community selection was ineffective (“top-dog” with “pipetting”; Figure 6A), H’s maximal growth rate evolved to exceed M’s maximal growth rate (Figure 6A, Figure S17). This drove M to almost extinction, and community function was very low (Figure 6A). During effective community selection (“top-dog” with “cell-sorting” or “bet-hedging” with “pipetting”, Figure 6B-C), H’s maximal growth rate remained far below its evolutionary upper bound and far below M’s maximal growth rate (Figure 6B-C). In this case, H and M can coexist at a moderate ratio, and community function improved (Figure 6B-C).

### Robust conclusions under alternative model assumptions

We have demonstrated that when selecting for high H-M community function, seemingly innocuous experimental procedures (e.g. choosing the top-functioning Adults and pipetting portions of them to form Newborns) could be problematic. Instead, more precise procedures (e.g. “cell-sorting”) or reduced selection strength (e.g. “bed-hedging”) might be required. Our conclusions hold when we used a much lower mutation rate (2×10^{−5} instead of 2×10^{−3} mutation per cell per generation per phenotype, Figure S18), although lower mutation rate slowed down community function improvement. Our conclusions also hold when we used a different distribution of mutation effects (a non-null mutation increasing or decreasing *f*_{P} by on average 2% or eliminating null mutants; Figure S19), or incorporating epistasis (i.e. a non-null mutation would likely reduce *f*_{P} if the current *f*_{P} was high, and enhance *f*_{P} if the current *f*_{P} was low; Figure S20; Figure S21; Methods Section 5).

To further test the generality of our conclusions, we simulated community selection on a mutualistic H-M community. Specifically, we assumed that Byproduct was inhibitory to H. Thus, H benefited M by providing Byproduct, and M benefited H by removing the inhibitory Byproduct, similar to the syntrophic community of *Desulfovibrio vulgaris* and *Methanococcus maripaludis* [55]. We obtained similar conclusions in this mutualistic H-M community (Figure S22). We have also shown that similar conclusions hold for communities where member species may not coexist (Figure 6).

In summary, our conclusions seem general under a variety of model assumptions, and apply to a variety of communities.

## Discussions

How might we improve functions of multi-species microbial communities via artificial selection? A common and highly valuable approach is to identify appropriate combinations of species types. For example, by using cellulose as the main carbon source in a process called “enrichment”, Kato et al. obtained a community consisting of a few species that together degrade cellulose [56]. A more elaborate scheme is to perform artificial community selection to improve a desired community trait [10, 11, 14, 13, 17]. However, if we solely rely on species types, then without a constant influx of new species, community function will likely level off quickly [12, 21]. Here, we consider artificial selection of communities with defined member species so that improvement of community function requires new genotypes that contribute more toward the community function of interest at a cost to itself.

### Community selection can be challenging but is feasible

Artificial selection of whole communities to improve a costly community function requires careful considerations. We have considered species choice (Figures 2), mutation rate, the total number of communities under selection, Newborn target total biomass (bottleneck size; Figure S7), the number of generations during maturation (which in turn depends on the amount of Resource added to each Newborn and the maturation time; Figure S7), selection strength (Figure 3), and how we reproduce Adults (e.g. volumetric pipetting versus “cell-sorting”, Figure 3), and the uncertainty in community function measurements (Figure 5).

Many of these considerations face dilemmas. For example, a large Newborn size (*BM*_{target}) would lead to reproducible take-over by non-contributors (Figure S7), but a small Newborn size would mean that large non-heritable variations in community function can readily arise and interfere with selection unless special measures are taken (Figure 3).

We can take obvious steps to mitigate non-heritable variations in community function. For example, we can repeatedly measure community function to increase measurement precision, thereby facilitating selection (Figure 5). We can also use the bet-hedging strategy so that lower-functioning communities harboring desirable genotypes can have a chance to reproduce (Figure 3). We can use a cell sorter to fix the cell number or biomass of member species in Newborns so that community function suffers less non-heritable variations (Figure 3).

The need to suppress non-heritable variations in community function can have practical implications that may initially seem non-intuitive. For example, when shared resource is non-limiting (to avoid stationary phase), we must dilute a chosen Adult community to a fixed target biomass instead of by a fixed-fold. This is because otherwise, selection would fail as we choose larger and larger Newborn size instead of higher and higher *f*_{P} (Methods, Section 7; Figure S23).

The definition of community function is also critical. If we had defined community function as Product per M biomass in the Adult community *P*(*T*)/*M*(*T*) (which is approximately proportional to : see Methods Section 7), then we will be selecting for higher and higher *f*_{P}, and M can go extinct (Figure S2). Note that certain types of community function might be easier to improve if they are insensitive to fluctuations in Newborn species biomass. An example is the H:M ratio which converges to a fixed value during maturation (Figure 2A bottom panel).

### Intra-community selection versus inter-community selection

When improving a costly community function, intra-community selection and inter-community selection are both important. Intra-community selection occurs during community maturation, and favors fast growers. Inter-community selection occurs during community reproduction, and favors high community function.

For production cost *f*_{P}, intra-community selection favors low *f*_{P}, while inter-community selection favors , the *f*_{P} leading to the highest community function. Thus, when current , inter-community selection runs against intra-community selection. When current , intra- and inter-community selections are aligned.

For growth parameters (maximal growth rates, affinities for metabolites), depending on their evolutionary upper bounds, the two selection forces may or may not be aligned. For example, using parameters in Table 1, improving growth parameters promoted community function (Figure S8A-C; Figure S24A). This is because with these choices of evolutionary upper bounds, H could not evolve to grow so fast to overwhelm M, Thus, with sufficient Resource and without the danger of species loss (Figure 2 bottom), faster H and M growth resulted in more Byproduct, larger M populations, and consequently higher Product level. If H could evolve to grow faster than M, then increasing growth parameters could decrease community function due to H dominance (Figure 6A; Figure S17A; Figure S24B), although properly executed community selection can improve community function while promoting species coexistence (Figure 6B, C).

### Contrasting selection at different levels

From a “gene-centric” perspective, selection of individuals bears resemblance to selection of communities, as the survival of an individual relies on synergistic interactions between different genes at different activity levels. To ensure sufficient heredity between an individual and its offspring, elaborate cellular mechanisms have evolved, and they include cell cycle checkpoints to ensure accurate DNA replication and segregation [57], small RNA-mediated silencing of transposons [58], and CRISPR-Cas degradation of foreign viral DNA [59]. In community selection, heredity-enhancing mechanisms such as stable species ratio (Figure 2A bottom panel) could already be in place or arise due to mutations that affect species interactions. If a mechanism such as endosymbiosis should evolve in response to community selection, then community selection could transition to individual selection.

Group selection, and in a related sense, kin selection [39, 40, 60, 41, 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 but increase the success of a group (e.g. sterile ants helping the survival of an ant colony). Note that the term “group selection” has often been used to describe individual selection in spatially-structured populations without group births and deaths, although such usage has been criticized [61]. Interestingly, artificial group selection can sometimes be viewed as artificial individual selection. For example, when Newborn groups start with a single contributor, then artificial group selection is equivalent to artificial individual selection where the trait under selection is the founder’s ability to produce a product over time as it grows into a population. On the other hand, if group function relies on distinct genotypes interacting synergistically, then group selection is similar to community selection.

Group selection can be thought of as a special case of community selection, except that group function can arise as a single founder multiplies. Therefore, group selection and community selection are similar in some aspects, but differ in other aspects. First, in both group selection and community selection, Newborn size must not be too large [62, 63] and maturation time must not be too long. Otherwise, all entities (groups or communities) will accumulate non-contributors in a similar fashion, and this low inter-entity variation impedes selection (Price equation [53]; Figure S1B; Figure S7). Second, species interactions in a community could drive species composition to a value sub-optimal for community function ([64]). This could also occur during artificial group selection if the founder genotype gives rise to sub-populations of distinct phenotypes interacting synergistically to generate group function (e.g. the growth of cyanobacteria filaments relying on differentiating into nitrogen-fixing cells and photosynthetic cells [65]). Otherwise, the problem of sub-optimal composition does not exist for group selection. Finally, in group selection, when a Newborn group starts with a small number of individuals (e.g. one individual), a fraction of Newborn groups of the next cycle will be highly similar to the original Newborn group (Figure S1B, bottom panel). This facilitates group selection. In contrast, when a Newborn community starts with a small number of total individuals, large stochastic fluctuations in Newborn composition can interfere with community selection (Figure 3). In the extreme case, a member species may even be lost by chance. Even if a fixed biomass of each species is sorted into Newborns, heredity is much reduced during community selection due to random sampling of genotypes from member species. For example, if Newborn groups are initiated with a single contributor and if the highest-functioning Adult group has accumulated 50% non-contributors, then 50% Newborn groups of the next cycle will be initiated with a single contributor and thus display group function. In contrast, if a Newborn community starts with one contributor from each of the two species and 50% non-contributors have accumulated in each species, then only 50%×50%= 25% Newborn communities of the next cycle will be initiated with contributors from both species and display community function.

### Community function may not be maximized through pre-optimizing member species in monocultures

If we know how each member species contributes to community function, might we pre-optimize member species in monocultures before assembling them into high-functioning communities? This turned out to be challenging due to the difficulty of recapitulating community dynamics in monocultures. For example, when we tried to improve M’s *f*_{P} by artificial group selection, *f*_{P} failed to improve to optimal for community function. Specifically, we started with *n*_{tot} of 100 Newborn M groups, each inoculated with one M cell (to facilitate group selection, Figure S1B bottom panel) [62]. We would supply each Newborn M group with the same amount of Resource as we would for H-M communities and excess Byproduct (since it is difficult to reproduce community Byproduct dynamics in M groups). After incubating these M groups for the same maturation time *T*, the group with the highest level of Product, *P*(*T*), would be chosen and reproduced into Newborn M groups for the next cycle. M’s growth parameters improved to evolutionary upper bounds (Figure S25A), since with Resource and Byproduct in excess, more M cells would lead to higher group function. When growth parameters were fixed to evolutionary upper bounds, optimal *f*_{P} for monoculture *P*(*T*) could be calculated to occur at an intermediate value (; Figure S25B). Optimal group function was indeed realized during selection (Figure S25A). However, optimal *f*_{P} for group function is much lower than optimal *f*_{P} for community function (; see Methods Section 8 for an explanation). Thus, optimizing monoculture activity does not necessarily lead to optimized community function.

### Implications of our work

In light of this study, we offer an alternative interpretation of previous work. In the work of [10], 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. 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 due to interference from non-heritable variations. This is because in Newborns with small sizes, fluctuations in community composition can be large, which compromises heredity of community trait.

A general implication of our work is that before launching a selection experiment, one should carefully design the selection regimen. Although some community functions are not sensitive to fluctuations in Newborn biomass compositions (e.g. steady state ratio or growth rate of mutualistic communities [66, 37]), many are. How might we check? The first method involves estimating the “signal to noise” ratio: one could initiate Newborn community replicates and measure community functions using the most precise method (e.g. cell-sorting during Newborn formation; many repeated measurements of community function). Despite this, some levels of non-heritable variations in community function are inevitable due to, for example, non-genetic phenotypic variations among cells [67] or stochasticity in cell birth and death. If “noises” (variations among community replicates) are small compared to “signals” (variations among communities with different genotypes and thus different community functions), then one can test and possibly adopt less precise procedures (e.g. cell culture pipetting during Newborn formation; fewer repeated measurements of community function). The second method involves estimating the heritability empirically if significant variations in community function naturally arise within the first few cycles. In this case, one could experimentally evaluate whether community functions of the previous cycle are correlated with community functions of the current cycle (across independent lineages (similar to Figure 4). Regardless, given the ubiquitous nature of non-heritable variations in community function, the bet-hedging strategy should be tested.

Microbes can co-evolve with each other and with their host in nature [68, 69, 70]. Some have proposed that complex microbial communities such as the gut microbiota could serve as a unit of selection [16]. 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.

### Future directions

Our work touched upon only the tip of the iceberg of community selection. We expect that certain rules will be insensitive to details of a community. For example, reducing non-heritable variations in community function and judicious bet-hedging can facilitate community selection. Regardless, many fascinating questions remain. Here, we outline a few:

How might we best “hedge bets” when choosing Adult communities to reproduce? We have chosen top ten communities to contribute an equal number of Newborns, but alternative strategies (e.g. allowing higher-functioning Adults to contribute more Newborns) may work better. This aspect might be explored through applying population genetics theories, which has considered the balance between the strength of selection and variation among the individuals.

How might migration (community mixing) impact selection? Here, we did not consider migration. Excessive migration could deter community selection by allowing fast-growing non-contributors to spread. However, by combining the best genotypes of multiple member species, migration could speed up community selection, much like the effects of sexual recombination in the evolution of finite populations [71].

How might interaction structure affect selection efficacy? We have shown that our conclusions hold for two-species communities engaging in commensalism or mutualism. We have also shown that our conclusions hold regardless of whether the two species can evolve to coexist or not. The next step would be to test other types of interactions and complex interaction networks. For example, when species mutually inhibit each other, multistability could arise such that species dominance [72] and thus community function are sensitive to stochastic fluctuations in Newborn species density. How might multistability affect community selection?

For a complex community, there might be multiple optima of community function, especially when the optimal community function requires multiple species with partially redundant activities. Consider the community function of waste degradation where one species degrades high-concentration waste incompletely while a complementary species degrades waste thoroughly but requires low starting waste concentration. If during Newborn formation, any one species is lost by chance, then community function would be stuck at local sub-optima. In this case, “bet-hedging” with community migration (mixing) could recover the lost species and help community selection reach a higher optimum.

Develop a general theory to understand how the rate of community function improvement depends on variations and heredity in community function, which are in turn affected by experimental parameters including Newborn size, the number of generations during maturation, mutation rate, the total number of communities under selection, selection strength, migration frequency, precision in community function measurement, and fluctuations during community reproduction.

Experimentally test model predictions. The assay for community function should be fast and precise. If community function is sensitive to species biomass in Newborns, then member species should ideally be distinguishable by flow cytometer (e.g. different fluorescence or different scattering patterns). Note that cell-sorting only needs to be performed on several high-functioning communities, and thus would not be cost prohibitive.

Discover interaction mechanisms important for community function. Once high-functioning communities are obtained through selection, we could compare metagenomes of evolved communities with those of ancestral communities. This would illuminate species interactions that are important for community function.

## Methods

### 1 Equations

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

Grow rate *g*_{H} depends on the level of Resource (hat representing pre-scaled value) as described by the Monod growth model
where is the at which *g*_{Hmax}/2 is achieved. *δ*_{H} is the death rate of H. Note that since agricultural waste is in excess, its level does not change and thus does not enter the equation.

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

Total potential growth rate of M *g*_{M} depends on the levels of Resource and Byproduct ( and ) according to the Mankad-Bungay model [27] due to its experimental support:
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 (tilde ~ representing scaling below and Table 1).

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, and are the amounts of consumed per potential M biomass and H biomass, respectively. is the amount of consumed per potential 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 experimental support [73]. The volume of community 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 ) against (Resource supplied to Newborn), Byproduct-related variable and parameters ( and ) 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 (Figure S3). After scaling, the value of becomes irrelevant (1 with no unit). Similarly, since and (Figure S4).

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.

From Eq. 10:

If we approximate Eq. 6-7 by ignoring the death rates so that and , Eq. 11 becomes

If B is the limiting factor for the growth of M so that B is mostly depleted, we can approximate *B* ≈ 0. If *T* is large enough so that both M and H has multiplied significantly and *H*(*T*) ≫ *H*(0) and *M*(*T*) ≫ *M*(0), Eq. 12 becomes
the M:H ratio at time *T* is

The steady state *ϕ*_{M}, *ϕ*_{M,SS}, is then
because if a community has *ϕ*_{M}(0) = *ϕ*_{M,SS} at its Newborn stage, it has the same *ϕ*_{M}(*T*) = *ϕ*_{M,SS} at its Adult stage.

In our simulations, because we supplied the H-M community with abundant R to avoid stationary phase, H grows almost at the maximal rate through *T* and releases B. If *f*_{P} is not too large (*f*_{P} < 0.4), which is satisfied in our simulations, M grows at a maximal rate allowed by B and keeps B at a low level. Thus, Eq. 14 is applicable and predicts the steady-state *ϕ*_{M,SS} well (see Figure S26). Note that significant deviation occurs when *f*_{P} > 0.4. This is because when *f*_{P} is large, M’s biomass does not grow fast enough to deplete B so that we cannot approximate *B*(*T*) ≈ 0 anymore.

### 2 Parameter choices

Our parameter choices are based on experimental measurements from a variety of organisms. Additionally, we chose growth parameters (maximal growth rates and affinities for metabolites) of ancestral and evolved H and M so that 1) the two species can coexist at a moderate ratio for a range of *f*_{P} over multiple selection cycles and 2) improving all growth parameters up to their evolutionary upper bounds generally improves community function (Methods Section 3). This way, we could simplify our simulation by fixing growth parameters at their respective evolutionary upper bounds. With only one mutable parameter (*f*_{P}), we can identify the optimal associated with maximal community function (Figure 2B).

For ancestral H, we set *g*_{Hmax} = 0.25 (equivalent to 2.8-hr doubling time if we choose hr as the time unit), *K*_{HR} = 1 and *c*_{RH} = 10^{−4} (both with unit of ) (Table 1). This way, ancestral H can grow by about 10-fold by the end of *T* = 17. These parameters are biologically realistic. For example, for a *lys-S. cerevisiae* strain with lysine as Resource, un-scaled Monod constant is , and consumption is 2 fmole/cell (Ref. [38]’s Figure 2 and Source Data 1, bioRxiv). Thus, if we choose 10 *μ*L as the community volume and 2 *μ*M as the initial Resource concentration, then fmole. After scaling, and , comparable to values in Table 1.

To ensure the coexistence of H and M, M must grow faster than H for part of the maturation cycle. Since we have assumed M and H to have the same affinity for R (Table 1), *g*_{Mmax} must exceed *g*_{Hmax}, and M’s affinity for Byproduct (1/*K*_{MB}) must be sufficiently large. Moreover, metabolite release and consumption need to be balanced to avoid extreme ratios between metabolite releaser and consumer. Thus for ancestral M, we chose *g*_{Mmax} = 0.58 (equivalent to a doubling time of 1.2 hrs). We set (units of ), meaning that Byproduct released during one H biomass growth is sufficient to generate 3 potential M biomass, which is biologically achievable ([37, 74]). When we chose (units of ), H and M can coexist for a range of *f*_{P} (Figure 2). This value is biologically realistic. For example, suppose that H releases hypoxanthine as Byproduct. A hypoxanthine-requiring *S. cerevisiae* M 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 (units of ) 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 ([74]). Death rates *δ*_{H} and *δ*_{M} were chosen to be 0.5% of H and M’s respective upper bound of maximal growth rate, which are 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).

We assume that H and M consume the same amount of R per new cell (*c*_{RH} = *c*_{RM}) since the biomass of various microbes share similar elemental (e.g. carbon or nitrogen) compositions [75]. Specifically, *c*_{RH} = *c*_{RM} = 10^{−4} (units of ), meaning that the Resource supplied to each Newborn community can yield a maximum of 10^{4} total biomass.

In some simulations (e.g. Figures 6, S8, S17), 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 cost parameter (0 ≤ *f*_{P} ≤ 1) were allowed to change from ancestral values during community maturation, since these phenotypes have been observed to rapidly evolve within tens to hundreds of generations ([29, 30, 31, 32]). For example, several-fold improvement in nutrient affinity and ~20% increase in maximal growth rate have been observed in experimental evolution [32, 30]. We therefore allowed affinities 1/*K*_{MR}, 1/*K*_{HR}, and 1/*K*_{MB} to increase by up to 3-fold, 5-fold, and 5-fold respectively, and allowed *g*_{Hmax} and *g*_{Mmax} to increase by up to 20%. These bounds also ensured that evolved H and M could coexist for *f*_{p} < 0.5, and that Resource was on average not depleted by *T* to avoid cells entering stationary phase.

We also simulated community selection where improved growth parameters could reduce community function (Figures 6 and S17). In this simulation, *g*_{Hmax} was allowed to increase by up to 220% and each Newborn community was supplied with R that can support up to 10^{5} cells (10 units of ).

Although maximal growth rate and nutrient affinity can sometimes show trade-off (e.g. Ref. [30]), for simplicity we assumed here that they are independent of each other. We held 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 ([75]). Similarly, we held the scaling factors and constant, assuming that they do not change rapidly during evolution due to stoichiometric constraints of biochemical reactions. We held 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 parameter ranges so that we can fix growth parameters to upper bounds

Improving individual growth (maximal growth rate and affinity for metabolites) does not always lead to improved community function (Figures 6 and S17). However, we have chosen H and M growth parameters so that improving them from their ancestral values up to upper bounds generally improves community function (see below). When Newborn communities are assembled from “growth-adapted” H and M with growth parameters at upper bounds, two advantages are apparent.

First, after fixing growth parameters of H and M to their upper bounds, we can identify a locally maximal community function. Specifically, for a Newborn with total biomass *BM*(0) = 100 and fixed Resource *R*, we can calculate *P*(*T*) under various *f*_{P} and *ϕ*_{M}(0), assuming that all M cells have the same *f*_{P}. 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, if M invests of its potential growth to make Product and if the fraction of M biomass in Newborn , then maximal community function is achieved (Figure 2B; magenta dashed line in Figure 3).

Second, growth-adapted H and M are evolutionarily stable in the sense that deviations (reductions) from upper bounds will reduce both individual fitness and community function, and are therefore disfavored by intra-community selection and inter-community selection.

Below, we present evidence that within our parameter ranges (Table 1), improving growth parameters generally improves community function. When *f*_{P} is optimal for community function , if we fix four of the five growth parameters to their upper bounds, then as the remaining growth parameter improves, community function increases (magenta lines in top panels of Figure S27). Moreover, mutants with a reduced growth parameter are out-competed by their growth-adapted counterparts (magenta lines in bottom panels of Figure S27).

When (optimal for M-monoculture function in Figure S25; the starting genotype for most community selection trials in this paper), community function and individual fitness generally increase as growth parameters improve (black dashed lines in Figure S27). However, when M’s affinity for Resource (1/*K*_{MR}) is reduced from upper bound, fitness improves slightly (black dashed line in Panel J, Figure S27). Mathematically speaking, this is a consequence of the Mankad-Bungay model [27] (Figure S4B). Let *R*_{M} = *R/K*_{MR} and *B*_{M} = *B/K*_{MB}. Then,

If *R*_{M} ≪ 1 ≪ *B*_{M} (corresponding to limiting R and abundant B),
and thus . This is the familiar case where growth rate increases as the Monod constant decreases (i.e. affinity increases). However, if *B*_{M} ≪ 1 ≪ *R*_{M}
and thus . In this case, growth rate decreases as the Monod constant decreases (i.e. affinity increases). In other words, decreased affinity for the abundant nutrient improves growth rate. Transporter competition for membrane space [76] could lead to this result, since reduced affinity for abundant nutrient may increase affinity for rare nutrient. At the beginning of each cycle, R is abundant and B is limiting (Eq. 16). Therefore M cells with lower affinity for R will grow faster than those with higher affinity (Figure S28). At the end of each cycle, the opposite is true (Figure S28). As *f*_{P} decreases, M diverts more toward biomass growth and the first stage of B limitation lasts longer. Consequently, M can gain a slightly higher overall fitness by lowering the affinity for R (Figure S28A).

Regardless, decreased M affinity for Resource (1*/K _{MR}*) only leads to a very slight increase in M fitness (Figure S27J) and a very slight decrease in

*P*(

*T*) (Figure S28B). 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 S29), 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 S29D with Figure 3A).

### 4 Mutation rate and the distribution of mutation effects

Literature values of mutation rate and the distribution of mutation effects are highly variable. Below, we briefly review the literature and discuss rationales of our choices.

Among mutations, a fraction is neutral in that they do not affect the phenotype of interest. For example, the vast majority of synonymous mutations are neutral [77]. Furthermore, mutations with small effects may appear neutral, which can depend on the 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 [78, 79]. As another example, the same mutation in an antibiotic-degrading gene can be neutral under low antibiotic concentrations, but deleterious under high antibiotic concentrations [80]. We term all these cases as “neutral” mutations.

Since a larger fraction of neutral mutations is equivalent to a lower rate of phenotype-altering mutations, our simulations define “mutation rate” as the rate of non-neutral mutations that either enhance a phenotype (“enhancing mutations”) or diminish a phenotype (“diminishing mutations”). Enhancing mutations of maximal growth rates (*g*_{Hmax} and *g*_{Mmax}) and of nutrient affinities (1/*K _{HR}*, 1/

*K*, 1/

_{M R}*K*

_{M B}) 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 [81, 82], 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. [83]), and mutations that reduce growth rate occur at a rate of 10^{−4} ~ 10^{−3} per genome per generation [35, 84]. Moreover, mutation rate can be elevated by as much as 100-fold in hyper-mutators where DNA repair is dysfunctional [85, 86, 84]. In our simulations, we assume a high, but biologically feasible, rate of 2 × 10^{−3} phenotype-altering mutations per cell per generation per phenotype to speed up computation. At this rate, an average community would sample ~20 new mutations per phenotype during maturation. We have also simulated with a 100-fold lower mutation rate. As expected, evolutionary dynamics slowed down, but all of our conclusions still held (Figure S18).

Among phenotype-altering mutations, tens of percent create null mutants, as illustrated by experimental studies on protein, viruses, and yeast [33, 34, 35]. Thus, we assumed that 50% of phenotype-altering mutations were null (i.e. resulting in 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) [87]. The relative abundance of enhancing versus diminishing mutations also strongly depends on the starting phenotype [33, 80, 78]. For example with ampicillin as a substrate, the wild-type TEM-1 *β*-lactamase is a “perfect” enzyme. Consequently, mutations were either neutral or diminishing, and few enhanced enzyme activity [80]. 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 [80]. When modeling H-M communities, we assumed that the ancestral H and M had intermediate phenotypes that can be enhanced or diminished.

We based 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 [36]. Specifically for each nutrient limitation, the authors first measured , the deviation in relative fitness of thousands of barcoded wild-type control strains from the wild-type mean fitness (i.e. selection coefficients). 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 derived *μ*_{Δs}, the probability density function (PDF) of relative fitness change caused by mutations Δ*s* = Δ*s*_{MT} − Δ*s*_{WT} (see Figure S6 for interpreting PDF), in the following manner.

First, we calculated *μ _{m}*(Δ

*s*

_{MT}), the discrete PDF of the relative fitness change of mutant strains, 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 Δ

*s*

_{MT}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 the wild-type collection, we obtained the PDF of the relative fitness change of wild-type strains

*μ*(Δ

_{w}*s*

_{WT}). Next, from

*μ*(Δ

_{w}*s*

_{WT}) and

*μ*(Δ

_{m}*s*

_{MT}), we derived

*μ*

_{Δ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}was 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

*δμ*

_{Δs}is shown in Figure S6.

Our reanalysis demonstrated 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 a bilateral exponential distribution with means *s*_{+} and *s*_{−} for the positive and negative halves, respectively. After normalizing the total probability to 1, we have:

We fitted the Dunham lab haploid data (since microbes are often haploid) to Eq. 19, using *μ*_{Δs}(*i*)/*δμ*_{Δs}(*i*) as the weight for non-linear least squared regression (green lines in Figure S6B). We obtained *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 remarkably well [33]. Based on extreme value theory, the fitness effects of beneficial mutations were predicted to follow an exponential distribution [88, 89], which has gained experimental support from bacterium and virus [90, 91, 92] (although see [93, 83] for counter examples). Evolutionary models based on exponential distributions of fitness effects have shown good agreements with experimental data [87, 94].

We have also simulated 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* were mostly 1%~5% [35], and the mean selection coefficient of beneficial mutations in *E. coli* was 1%~2% [90, 87]. As an alternative, we also simulated with *s*_{+} = *s*_{−} = 0.02, and obtained the same conclusions (Figure S19).

### 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 if two mutations were both deleterious or random, viable double mutants experienced epistatic effects that distributed nearly symmetrically around a value close to zero [95, 96, 97, 98, 99]. 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 [96] to being symmetrically distributed around zero [97]. Furthermore, a beneficial mutation tends to confer a lower beneficial effect if the background already has high fitness (“diminishing returns”) [100, 97, 101].

A mathematical model by Wiser et al. incorporates diminishing-returns epistasis [94]. In this model, beneficial mutations of advantage *s* in the ancestral background are exponentially distributed with probability density function (PDF) *α* 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 the above experimental and theoretical literature, we modeled 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}(note Δ

*f*≥ −1). Then,

_{P}*μ*(Δ

*f*,

_{P}*f*

_{P}), the PDF of Δ

*f*

_{P}at the current

*f*

_{P}value, is described by a form similar to Eq. 19:

Here, *s*_{+}(*f*_{P}) and *s _{−}*(

*f*

_{P}) are respectively the mean Δ

*f*

_{P}for enhancing and diminishing mutations at current

*f*

_{P}. We assigned

*s*

_{+}(

*f*

_{P}) =

*s*

_{+init}/(1 +

*g*× (

*f*− 1)), where

_{P}/f_{P, init}*f*

_{P, init}is the

*f*

_{P}of the initial background in a community selection simulation ,

*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*×(1+

_{−init}*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*, we have

_{P, init}*s*

_{+}(

*f*

_{P}) =

*s*

_{+init}and

*s*(

_{−}*f*

_{P}) =

*s*

_{−init}(

*s*

_{+init}= 0.050 and

*s*

_{−init}= 0.067 in Figure S6). Consistent with the diminishing returns principle, for subsequent mutations that alter

*f*

_{P}, if current

*f*

_{P}>

*f*

_{P,init}, then a new enhancing mutation became less likely and its mean effect smaller, while a new diminishing mutation became more likely and its mean effect bigger (ensured by

*g*> 0; Figure S20 right panel). Similarly, if current

*f*

_{P}<

*f*

_{P,init}, then a new enhancing mutation became more likely and its mean effect bigger, while a diminishing mutation became less likely and its mean effect smaller (ensured by 0 <

*g*< 1; Figure S20 left panel). In summary, our model captured not only diminishing-returns epistasis, but also our understanding of mutational effects on protein stability [78].

### 6 Simulation code of community selection

As described in the main text, our simulations tracked the biomass and phenotypes of individual cells as well as the amounts of Resource, Byproduct, and Product in each community throughout community selection. Cell biomass growth, cell division, and changes in chemical concentrations were calculated deterministically. Stochastic processes including cell death, mutation, and the partitioning of cells of a chosen Adult community into Newborn communities were simulated using the Monte Carlo method.

Specifically, each simulation was initialized with a total of *n*_{tot} = 100 Newborn communities with identical configuration:

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

*BM*(0) = 100.40 cells were H. 60 cells were M with identical

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

Our community selection simulations did not consider mutations arising during pre-growth prior to inoculating Newborns of the first cycle, because incorporating pre-growth had little impact on evolution dynamics (Figure S30). Thus, all M cells have the same phenotype, and all H cells have the same phenotype.

At the beginning of each selection cycle, a random number was used to seed the random number generator for each Newborn community. This number was saved so that the maturation of each Newborn community can be replayed. In most simulations, the initial amount of Resource was 1 unit of unless otherwise specified, the initial Byproduct was *B*(0) = 0 and the initial Product *P* (0) = 0.

The maturation time *T* was divided into time steps of Δ*τ* = 0.05. Resource *R*(*t*) and Byproduct *B*(*t*) during each time interval [*τ*, *τ* + Δ*τ*] were calculated by solving the following equations (similar to Eqs. 9-10) using the initial condition *R*(*τ*) and *B*(*τ*) via the ode23s solver in Matlab:
where *M*(*τ*) and *H*(*τ*) were the biomass of M and H at time *τ* (treated as constants during time interval [*τ*, *τ* + Δ*τ*]), respectively. The solutions from Eq. 21 and 22 were used in the integrals below to calculate the biomass growth of H and M cells.

Suppose that H and M were rod-shaped organisms with a fixed diameter. Thus, the biomass of an H cell at time *τ* could be written as the length variable *L*_{H}(*τ*). The continuous growth of *L*_{H} during *τ* and *τ* + Δ*τ* could be described as
or

Thus,

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

Thus for an M cell, its length *L*_{M}(*τ* + Δ*τ*) could be described as

From Eq. 7 and 8, within Δ*τ*,
and therefore
where *M*(*τ* + Δ*τ*) = Σ*L*_{M} (*τ* + Δ*τ*) represented the sum of the biomass (or lengths) of all M cells at *τ* + Δ*τ*.

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

After division, each mutable phenotype of each cell had a probability of *P _{mut}* to be modified by a mutation (Methods, Section 4). As an example, let’s consider mutations in

*f*

_{P}. If a mutation occurred, then

*f*

_{P}would be multiplied by (1 + Δ

*f*

_{P}), where Δ

*f*

_{P}was determined as below.

First, a uniform random number *u*_{1} between 0 and 1 was generated. If *u*_{1} ≤ 0.5, Δ*f*_{P} = −1, which represented 50% chance of a null mutation (*f*_{P} = 0). If 0.5 < *u*_{1} ≤ 1, Δ*f*_{P} followed the distribution defined by Eq. 20 with *s*_{+}(*f*_{P}) = 0.05 for *f*_{P}-enhancing mutations and *s _{−}*(

*f*

_{P}) = 0.067 for

*f*

_{P}-diminishing mutations when epistasis was not considered (Methods, Section 4). In the simulation, Δ

*f*

_{P}was generated via inverse transform sampling. Specifically,

*C*(Δ

*f*

_{P}), the cumulative distribution function (CDF) of Δ

*f*

_{P}, could be found by integrating Eq. 19 from −1 to Δ

*f*

_{P}:

The two parts of Eq. 25 overlap at *C*(Δ*f*_{P} = 0) = *s _{−}* (1−exp(−1/

*s*

_{−}))/ [

*s*

_{+}+

*s*

_{−}(1−exp(1/

*s*

_{−}))]. In order to generate Δ

*f*

_{P}satisfying the distribution in Eq. 19, a uniform random number

*u*

_{2}between 0 and 1 was generated and we set

*C*(Δ

*f*

_{P}) =

*u*

_{2}. Inverting Eq. 25 yielded

When epistasis was considered, *s*_{+}(*f*_{P}) = *s*_{+init}/(1 + *g* × (*f _{P} /f_{P, init}* − 1)) and

*s*

_{−}(

*f*

_{P}) =

*s*

_{−init}×(1 +

*g*× (

*f*)) were used in Eq. 26 to calculated Δ

_{P}/f_{P, init}− 1*f*

_{P}for each cell. (Methods Section 5).

If a mutation increased or decreased the phenotypic parameter beyond its bound (Table 1), the phenotypic parameter was set to the bound value.

The above growth/death/division/mutation cycle was 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*, are generally smaller than the numerical values of biomass

_{H}*M*and

*H*, respectively. At the end of

*T*, Adult communities were sorted according to their

*P*(

*T*) values. The Adult community with the highest

*P*(

*T*) (or a randomly-chosen Adult in control simulations) was chosen for reproduction.

Before community reproduction, the current random number generator state was saved so that the random partitioning of Adult communities could be replayed. To mimic partitioning Adult communities via pipetting into Newborn communities with an average total biomass of *BM _{target}*, we first calculated the fold by which this Adult would be diluted as

*n*

_{D}= ⌊(

*M*(

*T*) +

*H*(

*T*)) /

*BM*⌋. Here

_{target}*BM*= 100 was the pre-set target for Newborn total biomass, and ⌊

_{target}*x*⌋ is the floor (round down) function that generates the largest integer that is smaller than

*x*. If the Adult community had

*I*(

_{H}*T*) H cells and

*I*(

_{M}*T*) cells,

*I*(

_{H}*T*) +

*I*(

_{M}*T*) random integers between 1 and

*n*were uniformly generated so that each M and H cell was assigned a random integer between 1 and

_{D}*n*. All cells assigned with the same random integer were then assigned to the same Newborn, generating

_{D}*n*newborn communities. This partition regimen can be experimentally implemented by pipetting 1/

_{D}*n*volume of an Adult community into a new well. If

_{D}*n*was less than

_{D}*n*(the total number of communities under selection), all

_{tot}*n*newborn communities were kept and the Adult with the next highest function was partitioned to obtain an additional batch of Newborns until we obtain

_{D}*n*Newborns. The next cycle then began.

_{tot}To fix *BM*(0) to *BM _{target}* and

*ϕ*(0) to

_{M}*ϕ*(

_{M}*T*) of the parent Adult, the code randomly assigned M cells from the chosen Adult until the total biomass of M came closest to

*BM*(

_{target}ϕ_{M}*T*) without exceeding it. H cells were assigned similarly. Because each M and H cells had a length between 1 and 2, the biomass of M could vary between

*BM*(

_{target}ϕ_{M}*T*) − 2 and

*BM*(

_{target}ϕ_{M}*T*) and the biomass of H could vary between

*BM*(1 −

_{target}*ϕ*(

_{M}*T*)) − 2 and

*BM*(1 −

_{target}*ϕ*(

_{M}*T*)). Variations in

*BM*(0) and

*ϕ*(0) were sufficiently small so that community selection improved

_{M}*f*(

_{P}*T*) (Figure 3D and E). We also simulated sorting cells where H and M cell numbers (instead of biomass) were fixed in Newborns. Specifically, ⌊

*BM*

_{target}φ_{M}(

*T*)/1.5⌋ M cells and ⌊

*BM*(1 −

_{target}*φ*(

_{M}*T*))/1.5⌋ H cells were sorted into each Newborn community, where we assumed that the average biomass of a cell was 1.5, and

*υ*(

_{M}*T*) =

*I*(

_{M}*T*)/(

*I*(

_{M}*T*) +

*I*(

_{H}*T*)) was calculated from cell numbers in the parent Adult community. We obtained the same conclusion (Figure S13, right panels).

To fix Newborn total biomass *BM*(0) to the target total biomass *BM _{target}* while allowing

*ϕ*(0) to fluctuate (Figure S12 left panels), H and M cells were randomly assigned to a Newborn community until

_{M}*BM*(0) came closest to

*BM*without exceeding it (otherwise,

_{target}*P*(

*T*) might exceed the theoretical maximum). For example, suppose that a certain number of M and H cells had been sorted into a Newborn so that the total biomass was 98.6. If the next cell, either M or H, had a biomass of 1.3, this cell would go into the community so that the total biomass would be 98.6 + 1.3 = 99.9. However, if a cell of mass 1.6 happened to be picked, this cell would not go into this community so that this Newborn had a total biomass of 98.6 and the cell of mass 1.6 would go to the next Newborn. Thus, each Newborn might not have exactly the biomass of

*BM*, but rather between

_{target}*BM*− 2 and

_{target}*BM*. Experimentally, total biomass can be determined from the optical density, or from the total fluorescence if cells are fluorescently labeled ([54]). To fix the total cell number (instead of total biomass) in a Newborn, the code randomly assigned a total of ⌊

_{target}*BM*1.5⌋ cells into each Newborn, assuming an average cell biomass of 1.5. We obtained the same conclusion, as shown in Figure S13 left panel.

_{target}/To fix *ϕ _{M}*(0) to

*ϕ*(

_{M}*T*) of the chosen Adult community from the previous cycle while allowing

*BM*(0) to fluctuate (Figure S12 right panels), the code first calculated dilution fold

*n*in the same fashion as mentioned above. If the Adult community had

_{D}*I*(

_{H}*T*) H cells and

*I*(

_{M}*T*) cells,

*I*(

_{M}*T*) random integers between [1,

*n*] were then generated for each M cell. All M cells assigned the same random integer joined the same Newborn community. The code then randomly dispensed H cells into each Newborn until the total biomass of H came closest to

_{D}*M*(0)(1 −

*ϕ*(

_{M}*T*))/

*ϕ*(

_{M}*T*) without exceeding it, where

*M*(0) was the biomass of all M cells in this Newborn community. Again, because each M and H had a biomass (or length) between 1 and 2,

*ϕ*(0) of each Newborn community might not be exactly

_{M}*ϕ*(

_{M}*T*) of the chosen Adult community. We also performed simulations where the ratio between M and H cell numbers in the Newborn community,

*I*(0)/

_{M}*I*(0), was set to

_{H}*I*(

_{M}*T*)/

*I*(

_{H}*T*) of the Adult community, and obtained the same conclusion (Figure S13 center panels).

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

Here we describe problems associated with two alternative definitions of community function and one alternative method of community reproduction.

One alternative definition of community function is Product per M biomass in an Adult community: *P*(*T*)/*M*(*T*). To illustrate problems with this definition, let’s calculate *P*(*T*)/*M*(*T*) assuming that cell death is negligible. From Eq. 7 and 8,
where biomass growth rate *g*_{M} is a function of *B* and *R*. Thus,
and we have
if *M*(*T*) ≫ *M*(0) (true if *T* is long enough for cells to double at least three or four times).

If we define community function as , then higher community function requires higher or higher *f*_{P}. However, if we select for very high *f*_{P}, then M can go extinct (Figure 2).

In our community selection scheme, the average total biomass of Newborn communities was set to a constant *BM*_{target}. Alternatively, each Adult community can be partitioned into a constant number of Newborn communities. If Resource is not limiting, there is no competition between H and M, and *P*(*T*) increases as *M*(0) and *H*(0) increase. Therefore, selection for higher *P*(*T*) results in selection for higher Newborn total biomass (instead of higher *f*_{p}). This will continue until Resource becomes limiting, and then communities will get into the stationary phase.

### 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. **??** 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, *g dt* is larger in monoculture than in community. According to Eq. 27, is smaller for monoculture than for community.

### 9 Stochastic fluctuations during community reproduction

The number of cells in a Newborn community is approximately , where is the average biomass (or length) of M and H cells. This number fluctuates in a Poissonian fashion with a standard deviation of . As a result, the biomass of a Newborn communities fluctuates around *BM*_{target} with a standard deviation of .

Similarly, *M*(0) and *H*(0) fluctuate independently with a standard deviation of , respectively, where “E” means the expected value. 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 [102], 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*^{−}~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, we set *B*_{0} = 2*K*_{MB}.

## Acknowledgment

We thank the following for discussions: Lin Chao (UCSD), Maitreya Dunham (UW Seattle), Corina Tarnita (Princeton), Harmit Malik (Fred Hutch), Jeff Gore (MIT), Daniel Weissman (Emory), Tony Long (UC Irvine), and Alvaro Sanchez (Yale). Some of these discussions took place at the 2017 “Eco-Evolutionary Dynamics in Nature and the Lab" workshop at Kavli Institute of Theoretical Physics, UC Santa Barbara, the 2017 “Systems Biology and Molecular Economy of Microbial Communities” workshop at the International Centre for Theoretical Physics, Trieste, Italy, and the 2018 “Physical Principles Governing the Organization of Microbial Communities” workshop at the Aspen Center for Physics, Colorado, USA. We thank Chichun Chen, Bill Hazelton, Samuel Hart, David Skelding, Doug Jackson, Maxine Linial, Delia Pinto-Santini, Kirill Korolev (Boston University), and Alex Sigal (K-RITH) for feedback on the manuscript. We are particularly indebted to Jim Bull (UT Austin) and reviewers (Sara Mitri, James Boedicker, and two anonymous reviewers) who generously provided detailed critiques. This research was facilitated 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].↵
- [97].↵
- [98].↵
- [99].↵
- [100].↵
- [101].↵
- [102].↵
- [103].↵
- [104].↵
- [105].↵
- [106].↵