## Abstract

Multi-species microbial communities often display “community functions” stemming 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 species choice, selection regimen parameters, and stochastic populating 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 in some cases, even force species to evolve to coexist. 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 *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 function, 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. However, the number of combinations becomes very large even for a moderate number of species and genotypes, and some species may not be culturable in isolation.

In an alternative approach, artificial selection of whole communities could be carried out over cycles to improve community function [8, 9, 10, 11, 12] (reviewed in [13, 14, 15]). A selection cycle starts with a collection of low-density communities with artificially-imposed boundaries (e.g. inside culture tubes). These low-density communities are incubated for a period of time during which community members multiply and interact with each other and possibly mutate, and the community function of interest develops. At the end of incubation, desired communities are chosen to “reproduce” where each is randomly partitioned into multiple low-density 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 (Figure S1). However, compared to artificial selection of individuals or mono-species groups, artificial selection of multi-species communities is more challenging. One reason is that community function has limited heredity, since species and genotype compositions can change rapidly from one selection cycle to the next due to ecological and evolutionary forces (see detailed explanation in Figure S1). For example, member species critical for community function may get lost during growth and selection cycles.

The few attempts of community selection have generated interesting results. One theoretical study simulated artificial selection on multi-species communities based on their ability to modify their abiotic environment [10]. Communities responded to selection, but the response quickly leveled off, and could be generated without mutations. Thus, in this case, selection acted on species types instead of new genotypes [10]. In experiments, complex microbial communities were selected to improve their abilities to degrade a pollutant or to alter plant physiology [8, 9, 12, 11]. For example, microbial communities selected to promote early or late flowering in plants were dominated by distinct species types [11]. However in other cases, a community trait may fail to improve despite selection, and may improve even without selection [8, 9].

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 even be needed. Second, did selection act solely on species types or also on newly-arising genotypes? If the former ([10, 11]), then without immigration of new species, community function may quickly level off [10]. If the latter, then community function could continue to improve as new genotypes evolve. Finally, why might a community trait sometimes fail to improve despite selection [8, 9]?

In this study, we simulated artificial selection on communities with defined species. Our goal is to improve a “costly” community function via selecting for genotypes that promote community function. A community function is costly if any community member’s fitness is reduced by contributing to that community function. Costly community functions are common when microbes are engineered to make a product [16]. Community function can also be costly if high community function requires some species to restrain their growth to not out-compete other species. To improve a costly community function, artificial community selection must overcome natural selection which favors low community function.

To understand how to effectively enact community selection to improve a costly community function, we simulated artificial selection of communities consisting of two defined species whose phenotypes can be modified by random mutations. A simplified two-species community would allow us to mechanisti-cally investigate how community members evolved under community selection. Simulations allow us to compare the efficacy of different selection regimens with relative ease. 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 [17, 18]), 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 phenotypes (e.g. contributing or not contributing to community function) [19], and therefore could not model community function improvement if all members started as contributors. 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 define community function and show that inappropriate definitions lead to selection failures. We will then describe how we simulate artificial community selection. From simulation results, we will demonstrate critical measures that make community selection effective, including promoting species coexistence, suppressing non-contributors, 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 normally do 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” to refer to the selection step.

### 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 [20, 21, 22], 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 helped by Helper H (Figure 1). 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 (obligatory commensalism). 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, could convert substrates (Waste and Resource) into Product.

During each community selection cycle (Figure 2), low-density “Newborn” H-M communities were assembled, each supplied with a fixed amount of Resource and excess Waste. These Newborn communities were allowed to grow (“mature”) over a fixed time *T* into high-density “Adult” communities. 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*) (Figure 2, top two rows). In Methods Section 7, we explain problems associated with alternative definitions of community function (e.g. per capita production; Figure S2). Community function *P* (*T*) is not costly to Helpers, but reduces M’s growth rate by fraction *f*_{P} (Figure 1). Therefore, artificial selection is necessary to improve community function, since natural selection always favors non-producing M (*f*_{P} = 0). Later, we will show that for a community function that is costly to both H and M, our conclusions also hold.

### Simulating community selection

We simulated four stages of community selection (Figure 2): forming Newborn communities; Newborn communities maturing into Adult communities; choosing highest-functioning Adult communities, and 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.

Each simulation (Methods Section 6) started with *n*_{tot} number of Newborn communities. Each Newborn community always started with a fixed amount of Resource and a total biomass close to a target value *BM*_{target} (see Methods Section 7 for problems associated with not having a biomass target). 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 inherited that of the 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 ([23]; 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 [24]. 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 ([25, 26, 27, 28]). Mutated phenotypes could range between 0 and their respective evolutionary upper bounds. On average, half of the mutations abolished the function (e.g. zero growth rate, zero affinity, or *f*_{P} = 0) based on experiments on GFP, viruses, and yeast [29, 30, 31]. 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 [32] (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 obtained community function *P* (*T*) (the total amount of Product at time *T*) for each Adult community. The highest-functioning Adult was randomly partitioned into Newborns of the 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). When the highest-functioning Adult was used up for making Newborns, the next highest-functioning Adult was chosen and reproduced until *n*_{tot} Newborns were generated for the next selection cycle.

### Overcoming the ecological and evolutionary fragility of species coexistence

In order to improve community function, 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 [20, 21, 33, 34].

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, or else M would always grow slower than H and thus go extinct (Figure 3 top). Second, upon Newborn formation, H can immediately start to grow on Waste and Resource, while M cannot grow until H’s Byproduct has accumulated to a sufficiently high level. Thus, H and M’s growth parameters (maximal growth rates in excess nutrients; affinities for nutrients) should ideally allow M to 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. Otherwise, the ratio between metabolite releaser and consumer can be extreme [33].

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 selection cycles, different species ratios would converge toward a moderate steady state value during community maturation (Figure 3, bottom). Note that if species were not chosen properly, selection might fail due to insufficient species coexistence (e.g. Figure 7A), although as we will show later, community selection could enforce species coexistence when executed properly (Figure 7).

### Choosing selection regimen parameters to avoid known failure modes

After having chosen member species with appropriate phenotypes, we need to consider parameters of selection regimen. These parameters include the total number of communities under selection (*n*_{tot}), Newborn target total biomass (*BM*_{target}), 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 [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49], community selection is more challenging (Discussions; Figure S1). However, the two types of selections do share common aspects (Discussions; Figure S1). Thus, we can apply group selection theory, together with other practical considerations, to better design 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 the experimental setup is more challenging. We chose a total of 100 communities (*n*_{tot}=100).

If the mutation rate is very low, then community function cannot rapidly improve. If the mutation rate is very high, then non-producers will be generated at a high rate, and as the fast-growing non-producers take over, community function is likely to 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 total biomass *BM*_{target} is very large, or if the number of doublings within *T* is very large, then non-producers will take over in all communities during maturation (Figure S8, 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 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 sometimes improves community function through promoting individual growth

We simulated community selection while allowing H and M’s growth parameters (maximal growth rates in excess metabolites; affinities for metabolites) and M’s *f*_{P} to be modified by mutations. 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 S9C; average *f*_{P} declining to zero in Figure S9B).

When we chose highest-functioning Adult communities to reproduce, community function improved (Figure 4B, compare i and ii). Concurrently, *f*_{P} remained nearly unchanged while H and M’s growth parameters improved (Figure S10), leading to faster H and M growth rates (Figure 4A). Community function improvement was largely due to improved H and M growth, since disallowing mutations in growth parameters greatly diminished community function improvement (Figure 4B, compare i and iii). Here, improved individual growth promoted community function because of our choices of evolutionary upper bounds: Since H could not evolve to grow so fast to overwhelm M, species ratio was maintained at a moderate level (Figure 3B), and faster H and M growth resulted in more Byproduct, larger M populations, and consequently higher Product level. With different choices of evolutionary upper bounds, increasing growth parameters decreased community function due to H dominance (Figure S7), although we will demonstrate that even in this scenario, properly executed community selection can improve community function while promoting species coexistence (Figure 7).

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

While community function improved, it could have improved significantly more. Specifically, when growth parameters were fixed to their respective upper bounds, as occured during community selection (Figure S10C), maximal community function *P**(*T*) could be achieved at (Figure 4C). *P**(*T*) was much higher than what was achieved during community selection (Figure 4C ii dark grey star).

To investigate why community selection failed to improve community function to maximum *P**(*T*), we repeated our simulations, except that we fixed H and M’s growth parameters to their upper bounds (as occured during community selection; Figure S10C) and only allowed *f*_{P} to mutate. This simplification allowed us to focus on the evolutionary dynamics of *f*_{P}, and is justified since we obtained similar conclusions regardless of whether we fixed growth parameters (Figure S13).

Could community selection increase ancestral *f*_{P} to optimal for community function, despite natural selection favoring lower *f*_{P} ? Despite thousands of selection cycles, *f*_{P} and community function *P* (*T*) barely improved, and both were far below their theoretical optima (Figure 5A 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 there-fore 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 new genotypes could not rise to high frequencies 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 6A, bottom row) and their respective progeny Newborns in the next cycle (Figure 6A, color-matched top row). Among the three determinants, was heritable (Figure 6B): 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 6C). 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 6D). This is because regardless of the species composition of Newborns, Adults would have similar steady state species composition (Figure 3B), and so would their offspring Newborns.

In successful community selections, 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 6E-G). For example, the Newborn that would achieve the highest function had a below-median (left magenta dot in Figure 6E), but had high total biomass *BM* (0) and low fraction of M biomass *Φ*_{M} (0) (Figure 6F, G). In other words, variation in community function is largely non-heritable, as they are contributed by variations 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 we had chosen maturation time so that Resource was in excess to avoid stationary phase. 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 S14). Similarly, if a Newborn started with higher-than-average fraction of 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 S14).

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

### 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 *BM* (0) and *Φ*_{M} (0). Indeed, when each Newborn received a fixed biomass of H and M (Methods, Section 6), *P* (*T*) became strongly correlated with (Figure 5L). In this case, both and community function *P* (*T*) improved under selection (Figure 5, J and K) to near the optimal. *P* (*T*) improvement was not seen if either Newborn total biomass or species fraction was allowed to fluctuate stochastically (Figure 5, D-I). *P* (*T*) also improved if fixed numbers of H and M cells (instead of biomass) were allocated into each Newborn (Figure S15, A and B; Methods, Section 6). Allocating a fixed biomass or number of cells from each species to Newborn communities could be experimentally realized by using a cell sorter if species have different fluorescence ([50]).

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 and community function improved without having to fix Newborn total biomass or species composition (Figure 5, M-O; Figure S15, C and D). 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 the length of recovery time in the next selection cycle).

As expected, the effectiveness of community selection also depends on the uncertainty in community function measurements - another source of non-heritable variations. When we added to each *P* (*T*) a measurement noise (normally distributed with mean of zero and standard deviation of 5% of the ancestral *P* (*T*) value), community function improved at a slower rate than zero measurement uncertainty (compare Figure S16 left panel with Figure 5 J & K). When measurement uncertainty doubled, community selection failed (Figure S16 right panels). Thus, multiple measurements to reduce measurement uncertainty can make community selection more effective.

### Robust conclusions under alternative model assumptions

We have demonstrated that during selection for high H-M community function, seemingly innocuous experimental procedures (e.g. pipetting) could be problematic, and more precise procedures 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 S17), 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 increased or decreased *f*_{P} by on average 2%, Figure S18), or incorporating epistasis (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 S19; Figure S20; 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* [51]. We obtained similar conclusions in this mutualistic H-M community (Figure S22).

### 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 forcing species coexistence. Consider an H-M community where 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. When community selection was ineffective (“pipetting”; Figure 7A), H’s maximal growth rate evolved to exceed M’s maximal growth rate (Figure S21A, compare i and iv). This drove M to almost extinction, and community function was very low (Figure 7A; Figure S21A, vi). During effective community selection (fixing H and M’s biomass in Newborns; Figure 7B), H’s maximal growth rate remained far below its evolutionary upper bound, and H’s affinity for Resource even decreased from its ancestral value (Figure S21B, iv and v). In this case, H and M can coexist at a moderate ratio, and community function improved (Figure 7B).

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 approach is to identify appropriate combinations of species types [8, 9, 12, 11, 15]. However, if we solely rely on species types, then without a constant influx of new species, community function will likely level off quickly [10]. Here, we consider artificial selection of communities with defined member species so that improvement of community function requires new genotypes that contribute more toward the community function at a cost to itself.

Artificial selection of whole communities to improve a costly community function requires careful considerations. These considerations include the definition of community function (Methods, Section 7), species choice (Figures 3 and 4), mutation rate, the total number of communities under selection, Newborn target total biomass (Figure S8), the number of generations during maturation (which in turn depends on the amount of Resource added to each Newborn and the maturation time; Figure S8), how we reproduce a selected Adult (e.g. volumetric dilution versus cell sorting, Figure 5), and the uncertainty in community function measurements (Figure S16).

Some of these considerations concern the heredity of the community function under selection. If a community function is highly sensitive to species biomass in Newborn communities, such as *P* (*T*) of the H-M community, community selection faces a dilemma: On the one hand, a large Newborn size (*BM*_{target}) would lead to reproducible take-over by non-producers (Figure S8). On the other hand, a small Newborn size means that large non-heritable variations in community function can readily arise (e.g. during pipetting) and interfere with selection (Figure 5A-C). In this case, suppressing such non-heritable variations (e.g. sorting a fixed biomass or a fixed cell number of each species into Newborns) was critical to successful community selection (Figure 5J-L; Figure S15). Similar conclusions hold when we varied model assumptions (Results).

In the work of [8], 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.

In certain regards, community selection is similar to selection of mono-species groups. Group selection, and in a related sense, kin selection [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49], 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) ^{1}. In both group selection and community selection, Newborn size must not be too large [57, 58] 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 [59]; Figure S1B; Figure S8).

Community selection and group selection do differ in other aspects. First, species interactions in a community could drive species composition to a value sub-optimal for community function ([60]). This problem does not exist for group selection especially when a group does not differentiate into interacting subgroups. Second, 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 5). 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 ^{2}.

Community function may not be maximized through pre-optimizing member species in monocultures. This is due to the difficulty of recapitulating community dynamics in monocultures. For example, we could start with H and M with all growth parameters at respective upper bounds (similar to Figure 5), and then improve M’s *f*_{P} by mono-species group selection (Figure S1B). Specifically, we could start with *n*_{tot} of 100 Newborn M groups, each inoculated with one M cell (to facilitate group selection, Figure S1B bottom panel) [57]. 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) ^{3}. After incubating these M groups for the same maturation time *T,* the group with the highest level of Product, *P* (*T*), would be selected and reproduced into Newborn M groups for the next cycle. Optimal *f*_{P} for monoculture *P* (*T*) occurred at an intermediate value (; Figure S23; Figure S24). However, optimal *f*_{P} for monoculture *P* (*T*) is much lower than optimal *f*_{P} for community *P* (*T*) (Figure S23; see Methods Section 8 for an explanation). Thus, optimizing monoculture activity does not necessarily lead to optimized community function.

A general ramification of our work is that before launching a selection experiment, one should carefully consider 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 [61, 33]), many are. How might we check? In the first method, 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 [62] 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). In the second method, if significant variations in community function naturally arise within the first few cycles, one could experimentally evaluate whether community functions of the previous cycle (Figure 6A, bottom row) are correlated with community functions of the current cycle (Figure 6A, top row) across independent lineages.

Microbes can co-evolve with each other and with their host in nature [63, 64, 65]. Some have proposed that complex microbial communities such as the gut microbiota could serve as a unit of selection [14]. Our work suggests that if selection for a costly microbial community function should occur in nature, then mechanisms for suppressing non-heritable variations in community function should be in place.

## Methods

### 1. 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 Waste is in excess, Waste 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 [23] 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 factor, see 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 [66]. 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 S25). 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 **??**).

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. [34], Figure 2 Source Data 1, bioRxiv). Thus, if we choose 10 *µ*L as the community volume and 2 *µ*M as the initial Resource concentration, then 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} (Figure 1), 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 , meaning that Byproduct released during one H biomass growth is sufficient to generate 3 potential M biomass, which is biologically achievable ([33, 67]). When we chose , H and M can coexist for a range of *f*_{P} (Figure 3). 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 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 ([67]). 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 [68]. 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 simulations shown in Figures 4B, S9, S10, S13, 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 ([25, 26, 27, 28]). For example, several-fold improvement in nutrient affinity and ∼20% increase in maximal growth rate have been observed in experimental evolution [28, 26]. 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 (Figure 4A). 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. [26]), 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 ([68]). 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 (Figure 4A). 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 *P**(*T*) is achieved (Figure **??**A; magenta dashed line in Figure 5).

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 natural selection and artificial selection on the community function.

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 S26). Moreover, mutants with a reduced growth parameter are out-competed by their growth-adapted counterparts (magenta lines in bottom panels of Figure S26).

When (optimal for M-monoculture function in Figure S23; 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 S26). 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 S26). Mathematically speaking, this is a consequence of the Mankad-Bungay model [23] (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 [69] 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 S27). At the end of each cycle, the opposite is true (Figure S27). 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 S27A).

Regardless, decreased M affinity for Resource (1*/K*_{MR}) only leads to a very slight increase in M fitness (Figure S26J) and a very slight decrease in *P* (*T*) (Figure S27B). 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 S28), 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 S28D with Figure 5A).

## 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 [70]. Furthermore, mutations wtih 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 [71, 72]. As another example, the same mutation in an antibiotic-degrading gene can be neutral under low antibiotic concentrations, but deleterious under high antibiotic concentrations [73]. 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*_{MR}, 1*/K*_{MB}) enhance the fitness of an individual (“beneficial mutations”). In contrast, enhancing mutations in *f*_{p} diminish the fitness of an individual (“deleterious mutations”).

Depending on the phenotype, the rate of phenotype-altering mutations is highly variable. Although mutations that cause qualitative phenotypic changes (e.g. drug resistance) occur at a rate of 10^{-8}∼10^{-6} per genome per generation in bacteria and yeast [74, 75], 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. [76]), and mutations that reduce growth rate occur at a rate of 10^{-4}∼ 10^{-3} per genome per generation [31, 77]. Moreover, mutation rate can be elevated by as much as 100-fold in hyper-mutators where DNA repair is dysfunctional [78, 79, 77]. 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 S17).

Among phenotype-altering mutations, tens of percent create null mutants, as illustrated by experimental studies on protein, viruses, and yeast [29, 30, 31]. 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) [80]. The relative abundance of enhancing versus diminishing mutations also strongly depends on the starting phenotype [29, 73, 71]. 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 [73]. 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 [73]. 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 [32]. 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*_{W T} (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 . Repeating this process for the wild-type collection, we obtained the PDF of the relative fitness change of wild-type strains *µ*_{w}(Δ *s*_{W T}). Next, from *µ*_{w}(Δ *s*_{W T}) and *µ*_{m}(Δ *s*_{MT}), we derived *µ* _{Δ s}(Δ *s*), the PDF of Δ *s* with bin width 0.04:
assuming that µ*s*_{MT} and Δ*s*_{W T} 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,* 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*_{W T} = *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 ±.003.

Interestingly, exponential distribution described the fitness effects of deleterious mutations in an RNA virus remarkably well [29]. Based on extreme value theory, the fitness effects of beneficial mutations were predicted to follow an exponential distribution [81, 82], which has gained experimental support from bacterium and virus [83, 84, 85] (although see [86, 76] for counter examples). Evolutionary models based on exponential distributions of fitness effects have shown good agreements with experimental data [80, 87].

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% [31], and the mean selection coefficient of beneficial mutations in *E. coli* was 1%∼2% [83, 80]. As an alternative, we also simulated with *s*_{+} = *s*_{-} = 0.02, and obtained the same conclusions (Figure S18).

## 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 [88, 89, 90, 91, 92]. 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 [89] to being symmetrically distributed around zero [90]. Furthermore, a beneficial mutation tends to confer a lower beneficial effect if the background already has high fitness (“diminishing returns”) [93, 90, 94].

A mathematical model by Wiser et al. incorporates diminishing-returns epistasis [87]. 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*_{P} ≥ − 1). Then, *µ*(Δ*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*_{P} */f*_{P, init} − 1)), where *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*_{-init} × (1+*g* ×(*f*_{P} */f*_{P, init} *-*1)) is the mean |Δ*f*_{P} | for diminishing mutations at current *f*_{P}. In the initial background, since *f*_{P} = *f*_{P, init}, we have *s*_{+}(*f*_{P}) = *s*_{+init} and *s*_{-}(*f*_{P}) = *s*_{-init} (*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 S19 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 S19 left panel). In summary, our model captured not only diminishing-returns epistasis, but also our understanding of mutational effects on protein stability [71].

## 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 selected 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 S29).

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*_{P} */f*_{P, init}*-*1)) were used in Eq. 26 to calculated Δ*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*_{H}, are generally smaller than the numerical values of biomass *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 selected 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*_{target}.⌋. Here *BM*_{target} = 100 was the pre-set target for Newborn total biomass, and ⌊*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*_{D} were uniformly generated so that each M and H cell was assigned a random integer between 1 and *n*_{D}. All cells assigned with the same random integer were then assigned to the same Newborn, generating *n*_{D} newborn communities. This partition regimen can be experimentally implemented by pipetting 1*/n*_{D} volume of an Adult community into a new well. If *n*_{D} was less than *n*_{tot} (the total number of communities under selection), all *n*_{D} newborn communities were kept and the Adult with the next highest function was partitioned to obtain an additional batch of Newborns until we obtain *n*_{tot} Newborns. The next cycle then began.

To fix *BM* (0) to *BM*_{target} and *ϕ*_{M} (0) to *ϕ*_{M} (*T*) of the parent Adult, the code randomly assigned M cells from the selected 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*_{target}(1*-ϕ*_{M} (*T*)) *-*2 and *BM*_{target}(1 *- ϕ*_{M} (*T*)). Variations in *BM* (0) and *ϕ*_{M} (0) were sufficiently small so that community selection improved (Figure 5 K and L). We also simulated sorting cells so that the H and M cell numbers (instead of biomass) were fixed in Newborns. Specifically, ⌊ *BM*_{target}*ϕ*_{M} (*T*)*/*1.5 ⌋ M cells and ⌊ *BM*_{target}(1*-ϕ*_{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. We obtained the same conclusion (Figure S15, right panels).

To fix Newborn total biomass *BM* (0) to the target total biomass *BM*_{target} while allowing *ϕ*_{M} (0) to fluctuate (Figure 5 D and E), H and M cells were randomly assigned to a Newborn community until *BM* (0) came closest to *BM*_{target} without exceeding it (otherwise, *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*_{target}, but rather between *BM*_{target} 2 and *BM*_{target}. Experimentally, total biomass can be determined from the optical density, or from the total fluorescence if cells are fluorescently labeled ([50]). To fix the total cell number (instead of total biomass) in a Newborn, the code randomly assigned a total of ⌊ *BM*_{target}*/*1.5 ⌋cells into each Newborn, assuming an average cell biomass of 1.5. We obtained the same conclusion, as shown in Figure S15.

To fix *ϕ*_{M} (0) to *ϕ*_{M} (*T*) of the selected Adult community from the previous cycle while allowing *BM* (0) to fluctuate (Figure 5 G and H), the code first calculated dilution fold *n*_{D} in the same fashion as mentioned above. If the Adult community had *I*_{H} (*T*) H cells and *I*_{M} (*T*) cells, *I*_{M} (*T*) random integers between [1, *n*_{D}] 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 *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, *ϕ*_{M} (0) of each Newborn community might not be exactly *ϕ*_{M} (*T*) of the selected Adult community. We also performed simulations where the ratio between M and H cell numbers in the Newborn community, *I*_{M} (0)*/I*_{H} (0), was set to *I*_{M} (*T*)*/I*_{H} (*T*) of the Adult community, and obtain the same conclusion (Figure S15 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 3).

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

From Eq. 27, at a fixed *f*_{P}*, P* (*T*)*/M* (0) increases as *∫* _{T}*g*_{M}*dt* increases. *∫* _{T}*g*_{M}*dt* increases as *ϕ*_{M} (0) decreases, since the larger fraction of Helper, the faster the accumulation of Byproduct and the larger *∫* _{T}*g*_{M}*dt* (Figure S14B). As a result, when we select for higher *P* (*T*)*/M* (0), we end up selecting communities with small *ϕ*_{M} (0) (Figure S2). This means that Manufactures could get lost during community reproduction, and community selection then fails.

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. 27 by setting

We have or

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

M grows faster in monoculture than in community because B is supplied in excess in monoculture while in community, H-supplied Byproduct is initially limiting. Thus, *∫* _{T}*g*_{M}*dt* is larger in monoculture than in community. According to Eq. 28, 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 and , 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 [95], the growth rate of *E. coli* decreases exponentially as the exogenously added acetate concentration increases. Thus, we only need to modify the growth of H by a factor of exp(*-B/B*_{0}) where *B* is the concentration of Byproduct and *B*_{0} is the concentration of Byproduct at which H’s growth rate is reduced by *e*^{-1}∼0.37:

The larger *B*_{0}, the less inhibitory effect Byproduct has on H and when *B*_{0} → + ∞Byproduct does not inhibit the growth of H. For simulations in Figure S22, 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), and Al-varo Sanchez (Yale). Some of these discussions took place at the 2017 “Systems Biology and Molecular Economy of Microbial Communities” workshop at the International Centre for Theoretical Physics, Trieste, Italy and at 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) who generously provided sentence-by-sentence critique. This research was supported by the High Performance Computing Shared Resource of the Fred Hutch (P30 CA015704).

## Footnotes

↵

^{1}Group selection is often applied in a broader sense to spatially-structured populations to explain the evolution of cooperative traits [52, 53]. In these cases, individuals form groups. Within each cycle, individuals grow based on their genotype (e.g. cooperators or cheaters) and group environment (cooperator-dominated or cheater-dominated). At the end of each cycle, individuals migrate among groups. However, if there are no births or deaths of groups, then selection acts on individuals instead of on groups [54, 55, 56].↵

^{2}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% Newborns of the next cycle will be initiated with a single contributor. In contrast, if a Newborn community starts with one contributor from each of the two species and if the highest-functioning Adult has accumulated 50% non-contributors in each species, then only 50%*×*50%= 25% Newborns of the next cycle will be initiated with pure contributors.↵

^{3}Since Newborn groups start with a single M individual, artificial group selection here can also be viewed as artificial individual selection where the trait under selection is an individual M’s ability to make Product over time*T*as the individual grows into a population.

## 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.↵