Shaping bacterial population behavior through computer-interfaced control of individual cells

Bacteria in groups vary individually, and interact with other bacteria and the environment to produce population-level patterns of gene expression. Investigating such behavior in detail requires measuring and controlling populations at the single-cell level alongside precisely specified interactions and environmental characteristics. Here we present an automated, programmable platform that combines image-based gene expression and growth measurements with on-line optogenetic expression control for hundreds of individual Escherichia coli cells over days, in a dynamically adjustable environment. This integrated platform broadly enables experiments that bridge individual and population behaviors. We demonstrate: (i) population structuring by independent closed-loop control of gene expression in many individual cells, (ii) cell–cell variation control during antibiotic perturbation, (iii) hybrid bio-digital circuits in single cells, and freely specifiable digital communication between individual bacteria. These examples showcase the potential for real-time integration of theoretical models with measurement and control of many individual cells to investigate and engineer microbial population behavior.

P redicting the behavior of individual bacteria and bacterial populations is challenging and the complexity of the task increases rapidly already in the simplest laboratory conditions that include population heterogeneity and ecological or environmental interactions 1 . Even clonal groups of microbes can interact with each other and with nearby organisms [1][2][3][4][5][6] , undergo spatial and functional organization 1,6-9 , insulate their populations from transient stresses, including antibiotics 6,10 , and coordinate virulence [11][12][13] . Therefore, to understand and manipulate natural or engineered bacterial populations, we require the ability to experimentally measure and control factors in individual cells that generate emergent population behaviors.
Recent technological advances have facilitated experiments at the single-cell level in defined conditions. Microfluidic devices enable long-term observation of individual cells and precise environmental control [14][15][16] . However, differentially perturbing many individual cells is technically involved. Molecular genetics techniques permit straightforward design of synthetic genetic circuits to assay their effects at the population level 17,18 . However, in vivo behavior of even simple synthetic circuits is often hard to predict, and disentangling interactions between their components and with the host remains a laborious task [19][20][21][22] . Finally, computer-interfaced chemical and optogenetic methods of gene regulation offer new tools for specified modulation of microbial gene expression [23][24][25][26][27][28][29][30] . As yet, these methods have either been applied uniformly across populations, or in certain cases to a single cell. Online measurement and gene expression control in many individual cells at once is still lacking. Such a capability would provide a powerful way to probe and control microbial populations, including collective behaviors of populations that originate at the single-cell level.
To this end, we constructed a general purpose, automated platform to programmatically measure and control gene expression in lots of individual bacterial cells over many generations, Projector Cell 1 Cell 2 Cell 3 x 11 x 12 x 21 x 32 x Camera while dynamically modulating the chemical environment of the cells. The platform we developed combines microfluidics and optogenetics and enables simultaneous, quantifiable lightresponsive control of gene expression over several days in hundreds of individual bacteria, as well as global chemical perturbation (e.g. nutrient shifts, toxin exposure). The platform is run by a computer that defines and controls the entire experiment, analyzes the data online, and uses independent software controllers to automatically adjust scheduled light perturbation sequences on the fly for each individual bacterium. In the following, we introduce the platform and show how it provides straightforward access to important general characteristics of microbial populations.

Results
Experimental setup. We constructed the setup outlined above to perform a measurement-and-control loop (Fig. 1a, b, Methods) on E.coli cells bearing a light-regulated gene transcription module. Long-term control of individual cells necessitates a microculture environment that can operate stably for hundreds of generations. We therefore employ a microfluidic "mother machine" device to grow and track the individual cells confined at closed ends of short (~23 μm) cell-width channels over hours or days on a temperature-controlled fluorescence microscope (Methods, Supplementary Figs. 1 and 2) 14 . In these devices, larger channels intersect the growth channels, supplying fresh nutrient media and chemical perturbations and removing waste and progeny of each channel's focal "mother" cell. Gene expression is estimated using image intensities of a fluorescent reporter. Since reporter levels vary too much for reliable segmentation, morphological cell data are acquired by imaging a second, constitutively expressed, fluorescent reporter. Software controllers, associated with individual cells or cell groups, process these data and return expression activation/repression signals for delivery to each cell. Cells are individually stimulated by projecting an RGB image of the signal intensities, mapped to appropriate color channel and cell locations, onto the light-responsive cells using a modified overhead projector (Methods, Supplementary Figs. 1 and 2, Supplementary Movie 1). Maximum cell numbers are thus constrained by the time required to visit and set up each field of view, perform data acquisition, analysis and control computations, and stimulate every cell at a sufficient frequency. In our experiments, six minute control intervals permit initial tracking and control of 200-400 cells in four to eight fields of view at ×100 magnification, with maximum cell attrition-limited durations of several days (Methods).
In closed-loop mode, once defined, experiments are implemented entirely programmatically and without intervention. To enable fully autonomous operation, we wrote custom MATLAB software to manage all aspects of the experiment (Methods). The modular software eases modifications of the physical system, and simplifies revision of controllers and experiment protocols.
To independently regulate expression in single cells, we rely on light-responsive transcription mechanisms. We employ a recently optimized ccaSR-based system with low leak and large dynamic range, which includes a synthesis pathway for the necessary phycocyanobilin (PCB) chromophore 31 . Illumination with green (~535 nm) or red (~670 nm) light, respectively, activates or deactivates expression from the P cpcG2-172 promoter with timescales on the order of several minutes, without differentially affecting growth 27,31,32 . For testing our setup, we have placed a cyan fluorescent protein expression reporter, Cerulean (cfp), under the control of the P cpcG2-172 promoter (Fig. 1c).
Single-cell control. We verified our system by controlling gene expression patterns in a small population of Escherichia coli. In cell population control, mean and individual error represent two important deviations of expression from target levels, and depend broadly on the control type (Table 1).
Open loop (OL) controllers precompute light stimulation sequences based on an average cell response model. OL controllers suffer from both mean and individual error. Mismatches between modeled and actual population responses produce systematic errors in mean expression that are sensitive to unmodeled changes in cell behavior (e.g., with environment). Further, "average cell" stimuli fail to account for cell-to-cell differences in response, and cannot contain the resulting variation in expression. By comparing expected and measured responses to the control stimulus, population-level closed loop (pCL) controllers substantially reduce mean target deviations by adjusting global stimuli on-the-fly 23,24,27,33 . However, stimuli applied uniformly across the population cannot contain variation stemming from differences between cells. To reduce such individual error, controllers should operate at the single cell level at which the error is generated. Closed loop control has been demonstrated at the level of a single yeast cell 26 , and we tested whether extending this to parallel, individual-level closed loop (iCL) control of a population of many cells within our device could mitigate both sources of error.
To control gene expression in individual cells, we used a receding-horizon control scheme (Fig. 2) based on a simplistic (although predictive) stochastic kinetic model that we identified from several calibration experiments (Supplementary Methods). The model incorporates an internal (unmeasured) state, hereafter termed "cell responsiveness" (Fig. 2) that can vary between cells and in time. Every 6 min, for each cell, the controller compares the recorded fluorescence level to a predicted level calculated from the model and updates its estimate about the cell's responsiveness by weighting prediction and measurement according to their uncertainties. Measurement uncertainty stems from technical errors in recording cells' fluorescence whereas prediction uncertainty is a consequence of stochasticity in modeled chemical reactions and the imperfectly known, possibly time-varying, cell responsiveness. The prediction uncertainty can be efficiently calculated from the stochastic model of the system using moment equations (Supplementary Methods). The controller then uses the updated estimate of the cell's responsiveness to identify a light sequence that minimizes the deviation of the expected fluorescence levels in the cell from the desired target profile over a certain planning horizon (Fig. 2).
We tested this control scheme by making individual cells track a target fluorescence profile consisting of steps and a sine-wave. To quantify control performance, we split the cells into two groups. For the first group, we used OL control to pre-calculate the entire optimal light sequence (based on a mean population response model identified from calibration experiments) without online learning of the responsiveness or feedback of the cells. The second group was iCL feedback-controlled as described in Fig. 2 (see sample cells, Supplementary Movie 2). The resulting mean  25 for further results of this type). However, the control performance is less satisfactory for individual cells (gray lines). Heterogeneity in a population exposed to an identical light stimulation pattern results in widely varying fluorescence trajectories across the cells and, thus, high variance around the mean response. In particular, fluorescence of some cells is either far above or far below the average for long periods of time. We expect individualized light patterns based on online learning of each cell's responsiveness to decrease stimulation of over-responsive cells and increase it for under-responsive cells, reducing both the mean error and expression heterogeneity of the population. Indeed, the iCL-controlled cells exhibit both a reduced error in mean fluorescence, and a narrower distribution around that mean than cells under OL control (Fig. 3a,

right panel, See Supplementary
Methods for a comparison of pCL and iCL controllers).
Defining population expression distributions. The effectiveness of iCL control in reducing mean error and cell-to-cell variation in expression suggested that -beyond simply narrowing population expression around single targets-we could use such control to specify more complex distributions of gene expression. Recent studies suggest that phenotypic distributions in isogenic populations could have strong fitness effects, e.g., as bet hedging strategies for rare but toxic environments 6,15,34,35 . Testing such ideas rigorously would benefit from an experimental capacity to specify desired expression distributions and expose them to precisely modulated environments.
To evaluate iCL control for specifying expression distributions, we targeted halves of a population to two nearby CFP fluorescence levels (10, 20 a.u). The experiment ran for 780 min in OL mode (precomputed, global light stimulation) to steer expression to the two targets (Fig. 3b). While mean population fluorescence levels initially approach the targets, there are large residual errors in the mean and high variability. Both mean and individual errors interfere with separating the joint population into clearly defined subpopulations with distinct targets (Fig. 3b, center right panel). After 780 min, the controllers switched to iCL mode, adjusting stimulation sequences based on individual cell responses (Fig. 3b, bottom; Supplementary Movie 4). Shortly thereafter, mean error and variation within each subpopulation are sharply reduced. Comparing average mean-subtracted power spectra of individual cells' expression during OL and iCL control, we observe that iCL control reduces amplitudes of slow expression fluctuations (f < 1 h −1 ; Fig. 3c). The population resolves into two accurately targeted groups of cells (Fig. 3b, rightmost panel). Reversing the control order and Fluorescence (a.u.)  switching from iCL to OL has the opposite effect ( Supplementary  Fig. 3). Independent and parallel control of expression in individual cells enables specifying not only stationary distributions, but also precise temporal gene expression patterns in groups of cells. As an example, we used our setup to straightforwardly program a population of 24 cells under iCL control to track distinct dynamic CFP expression targets over a 24 h interval (Fig. 3d).

Population variability control under antibiotic perturbation.
A key use of our platform is to probe how populations with distributed phenotypes interact with changing environments. Such investigations depend on our ability to modify the environment precisely while maintaining a desired phenotypic distribution. The microfluidic devices we use for long-term culture of individual bacteria are uniquely suited to exert precise chemical and temporal control over cells' environments by switching between media sources. In our setup, we switch media with 1-10 min lag at junctions upstream of the device.
For a simple test of combined environmental manipulation and expression control, we elaborated our control experiments to include a switch from antibiotic-free media to media containing a sub-inhibitory level of the translation-inhibiting tetracycline antibiotic, doxycycline 36 . Sub-inhibitory antibiotic concentrations can generate diverse behaviors by modifying gene expression and cell physiology 37 . Such changes are difficult to capture in simplified models, and as cells are driven further from the regime in which the control model was identified, the increasing mismatch between model and cell should amplify the mean error between cell fluorescence and control target. Additionally, antibiotics acting on cells with small initial differences in susceptibility could increase variability (and thus mismatch with the average cell) within a population 38 .
We assessed the effect of doxycycline on population and individual control errors by measuring the change in mean and variance of an OL-controlled population with a single fluorescence target (15 a.u.) upon antibiotic exposure. To test how closed-loop control moderates these effects, we assigned a similar number of cells to the iCL control algorithm. We allowed cells 10 h to acclimatize in the absence of doxycycline before switching to media containing 0.6 μg ml −1 of the antibiotic, which rapidly slowed the average growth of both OL and iCL-controlled  populations by~30% (Fig. 4a, Methods). Since at minimum, this gross shift in dilution rate is not accounted for by our simple model of gene expression that assumes a constant growth rate identified in the absence of doxycycline, we expect its predictive accuracy to decline in the presence of the antibiotic. Indeed, following the growth rate shift, the mean fluorescence of the OLcontrolled cells diverges above the target level without stabilizing through an additional 1200 min of antibiotic exposure ( Fig. 4b and Supplementary Fig. 4). Note that mean fluorescence remains stable for approximately 300 min following the growth shift, suggesting that "fixing" the model would require more than simply incorporating active growth rate measurements. Importantly, because our platform processes cell fluorescence data online, it can detect and respond to effects of changing environmental conditions in real time by appropriately adjusting light inputs. Our simple predictive model of gene expression captured the effects of doxycycline perturbation as an increase in cells' responsiveness, informing the iCL control algorithm that less activating green light is required to maintain stable fluorescence levels. The mean fluorescence of the iCL-controlled population thus experiences only a slight, stable increase, without an appreciable increase in population variability ( Fig. 4b and Supplementary Fig. 4). The small shift in the iCL-controlled mean results from the aforementioned model mismatch under antibiotic-containing conditions relative to the conditions used for model identification (see Supplementary Information). Comparison of the probability distributions of OL and iCLcontrolled cells in 300 min intervals prior to and during antibiotic  (Fig. 4c and Supplementary Fig. 4) indicates that iCL control largely mitigates both population and individual errors stemming from model-environment mismatch, ultimately with iCL-controlled expression only slightly affected by the antibiotic.
Bio-digital circuits and specifiable cell-cell interactions. Finally we tested an idea that, besides explicitly controlling gene expression, our platform could digitally virtualize elements of transcriptional circuits. Such bio-digital circuits would permit powerful, facile specification of properties of their digital component (e.g., dynamics, connectivity, response, noisiness), while retaining their in vivo context for assay.
We therefore produced a toy hybrid version of an established circuit, an oscillator, composed of interfaced biological and digital components. Extensively studied natural genetic oscillators exhibit quantifiable phenotypes of frequency, phase, and amplitude 39 . Simple synthetic oscillators have been tested as exploratory tools and sensor readouts 40,41 . A common core architecture among biological oscillators is a delayed negative feedback loop (Fig. 5a), in which a chemical signal (S) generated by a gene product (ENZ) eventually represses the expression of the gene itself 39 . In particular regimes, the inhibitory signal is then cyclically depleted until expression resumes, producing stable oscillations 39 .
We virtualized the inhibitory signal component, digitally specifying a gene product-dependent production rate (r), first order removal rate (d), and its interaction with the gene's promoter via a digital promoter state, P (Fig. 5b). To measure gene product levels without producing real inhibitory signal, we replaced the gene with a CFP reporter, thus interfacing the biological to the digital side of the network. At each 6 min measurement and control interval (i = 1,2,3,…) the virtual signal S i accumulates in proportion to a cell's measured CFP fluorescence and is removed in proportion to its own prior level. In our toy system, the cell's digital promoter state, P i , is either fully "off" when levels of S i exceed a threshold, θ (identical for all cells and arbitrarily specified to be generally reachable), or otherwise fully "on". Last, by replacing the gene's promoter with a light-regulated one that receives virtual promoter "off" and "on" states as inhibiting (red light) or activating (green light) stimuli, respectively, the digital side is interfaced back to the biological side of the system. We tested our hybrid circuits in single cells, and observed oscillating CFP expression over 40 h (Fig. 5c  While the circuits shared similar frequency spectra (Fig. 5c, right  panel), variations in individual oscillation lengths shift phases within and between cells. Deterministic behavior of the digital component and low measurement noise suggest that this variability stems largely from the biological side of the circuit.
We asked whether re-specifying the digital component could influence the observed variability. Biological oscillators can synchronize by coupling to extracellular fields, which can either be externally imposed or be a product of the local community 42 . For instance, populations of synthetic bacterial oscillators can synchronize through molecular signals that diffuse between cells, forming weakly-coupled transcriptional networks of oscillators (Fig. 5d, top) 40 . With this biological architecture in mind, we updated our digital component to define a network of connections between the individual bacteria through which the virtualized signal is redistributed (Fig. 5d, bottom). We repeated the experiment while enforcing communication within cyclically connected groups of cells by transferring 20% of each cells' virtual signal to its nearest neighbors. Improved oscillation peak coincidence and nearly zero period-normalized cross-correlation lags indicate that oscillating cells synchronize (Fig. 5e;   Supplementary Fig. 5; Supplementary Movie 6). Given the success of this approach, we explored the behavior of our cells subject to other changes in communication. In our toy system, a freely specifiable transfer matrix T (Fig. 5d) defines the connection map, and the strengths and signs of interaction between individual cells.
By changing the signs of off-diagonal transfer matrix values, we generated groups of oscillating cells that either inhibit both neighbors' accumulation of virtual signal, or stimulate accumulation in one neighbor while inhibiting it in the other. While in our setup this change amounts to a minor change in control software, biological or mechanical implementation of similar operations on bacterial oscillators would be considerably more involved. We tested the new circuits in cyclic, four cell groups. Although we expect the group behaviors to also depend on size and connectivity, patterns in oscillation phases emerge again, but this time with nearest neighbors either a half period, or approximately a quarter period out of phase (Fig. 5f, g;  Supplementary Fig. 5; Supplementary Movies 7 and 8).
These simple examples highlight our platform's potential for straightforward access to diverse, otherwise challenging assays of transcriptional circuits and communication in individual bacteria and populations.

Discussion
We presented a versatile experimental platform that simultaneously interfaces many individual bacteria with software-defined models in a controlled environment. Very generally, this device represents a step forward in experimental systems built around real-time integration of measurement and control of bacterial cell biology with theoretical models 23,24,[26][27][28][29][30]33,43,44 . Directly interweaving "wet" and "dry" components in experiments provides a strong impetus and a 'test and measurement' environment for probing predictiveness. By actively testing and adjusting models during experiments, the system could assist in rapid model optimization and facilitate online model inference for single cells 25,45 .
The platform enables quantitative explorations of individualbased traits of bacterial populations through feedback control or digitally specified constraints on gene expression in single cells. The demonstrations above illustrate several directions which can be extended to diverse applications. For instance, distributed behaviors can prepare isogenic populations with incomplete sensory information for stochastic environmental variation 35 . Our device enables exploration of this phenomenon by specifying shapes of and dynamics within expression distributions for populations in specified environments. In such a scenario, cells can even be provided with abilities to artificially "sense" the environment via input from the cells' software controllers.
In addition, the paradigm of hybrid genetic circuits formed by interfacing biological and digitally-modeled parts allows biological systems to be characterized under constraint by virtual circuit parts. Analogous to unit testing in software development, this capacity could ease challenges in piecewise debugging of genetic circuits, and in situ development and optimization of synthetic circuits within cell factories 20,22 . In the latter, in contrast to entirely wet or entirely theoretical approaches, real impacts of virtual components such as sensors could be approximated even before biological versions are engineered, thus speeding up development.
Finally, by specifying hybrid circuits that allow information to flow between individual cells, the system enables new kinds of experiments on how collective behaviors of small groups of bacteria respond to community and environment-dependent changes in cell interactions 1,9,37 . Assays of behaviors that respond to digitally defined cell interactions and perturbations (e.g., virtual diffusion or cell arrangement) could assist in exploring interaction-targeted programs for stabilizing, disrupting, or otherwise controlling natural and artificial bacterial communities 11,13,17,18,46 .
Individual and group behaviors of microbes are hard to approach fully through simulation alone or simply through biological assay alone. By virtualizing parts of biological systems, our platform achieves benefits of both methods by allowing straightforward specifiability of a virtualized part within its full biological context. Importantly, transplanting digitally specified components into biological systems can extend the explorable space of circuits and behaviors to and even beyond what is biologically possible 47 . On the one hand, for characterizing actual genetic circuits within and between cells, the platform can guide (although not replace) traditional fully biological analyses. On the other hand, its reduced constraints allow us to ask "What if?" questions and to create, perturb, and study approximations to otherwise inaccessible biological systems. Following on the proofs of concept above, our platform can thus facilitate new modes of exploring behaviors of populations and other complex bacterial systems.

Methods
Bacterial strains and plasmids. See Table 2. Imaging and projection system. Our system integrates image data acquisition and processing, cell stimulation, and environmental regulation. All physical device control and data processing is executed through custom software in MATLAB (version 2014b, with statistics, image processing, distributed computing toolboxes) using MicroManager 48 , SUNDIALS 49 , mexOpenCV 50 , and java packages (Supplementary Software).
Light stimuli are simultaneously delivered to cells in a field of view using a variant of a custom modified LCD projector ( Supplementary Fig. 1) 51 . The projector (Panasonic PT-AE6000E) iris is disabled and lamp replaced by 530 and 660 nm LED sources (Thorlabs, M530L3, M660L3, LEDD1B). The outer, projection, lens is removed and the image projected through the zoom lens is coupled via a field lens (Thorlabs AC508-100-A-ML, f = 100 mm) into the rear port of the microscope, through a tube lens (Olympus U-TLU), and via a 50/50 beamsplitter (Thorlabs BSW10R, TOFRA filter cube slider) through the objective and onto the field of view ( Supplementary Figs. 7 and 8). Projector position is adjusted to bring the camera and projector focal planes into alignment, and submicron corrections between the focal planes to be used during the experiment are determined, per channel, at its outset.
Experimental temperature is regulated within a custom-built opaque, temperature-controlled microscope enclosure via recirculating air heater (controller: Cal controls CAL3200). Media delivery is regulated by a pair of syringe pumps (WPI, Alladin-1000).
Imaging, image processing, and cell stimulation loop. During operation, software-based focus (modified micro-manager oughtafocus function) is determined at each location/time-point using reflective imaging (475/34 nm) of PDMSglass interfaces. A focused reflection image is used for a phase correlation-based estimate of x axis and y axis corrections to stage jitter. Fluorescent images are acquired, corrected for a small, slowly varying additive offset, and divided by previously-obtained, normalized calibration images of a uniform fluorescent field 52 (10% Fluorescein 0.1%NaHCO 3 ) to correct for fluorescence shading variation. The images are then spatially registered and fluorescence-based expression estimates (constitutive, controlled channels) are extracted for the individual mother cells under control as the 97th percentile pixel intensity within a pre-specified bounding box at each cell's image location (Fig. 1, dashed box). In the present experiments, this detection region is fixed at 40 × 80 pixels (~13.5 μm 2 ), of which the 3% above the extracted value (96 pixels) sums to~0.4 μm 2 . To avoid injecting large errors into closed loops, this method was selected for its lack of cell segmentation errors and robustness to large variations in cell size, position and fluorescence. The constitutive fluorescence images are separately segmented to derive sizes of mother cells, and growth rates are estimated via a moving average of differences in log 2 (cell length), excluding extreme outliers resulting from cell division events and transient segmentation errors. This per-cell data are passed to experiment-dependent software controllers that update cell state estimates and determine the subsequent activation (~535 nm) or deactivation (~670 nm) light stimuli to be delivered to each cell (Supplementary Methods).
The list of per-cell stimuli is converted to red and green boxes in an RGB image, overlying the positions of their corresponding cells (typically covering the terminal 11 μm of channel, e.g., position of dashed yellow box in Supplementary Fig. 2). The image is then spatially transformed to register projector to camera image planes (openCV function cv.warpPerspective, using homographies determined at the experiment outset with projected chessboards and the functions cv. findChessboardCorners and cv.findHomography). Shading corrections (low-pass frequency filtered images of reflected flat field projections, generated at experiment setup) are applied to each color channel. The image is then projected onto the field of view and cells illuminated for 10 s with~10.5 red or 7.6 mW cm −2 green light (with contrast ratios relative to dark LCD panels, of 252 and 361, respectively; crosstalk between channels is <1%).
Although our setup also permits control via mixed red-green and intermediate level light dosing of the CcaSR light system (as employed by Olson et al. 27 ), we opted for a pulse-width modulation (PWM) type scheme 53 and brief monochromatic stimuli to facilitate rapid cycling through multiple fields of view. Six-minute intervals were chosen to maximize cell numbers per experiment and computational time per control loop while maintaining sufficiently fast control dynamics relative to expression and dilution timescales (Supplementary Methods).
To reduce crosstalk with the optogenetic systems, cell exposures to imaging wavelengths are minimized and kept invariant across all experiments. In addition, the interval between exposing cells to imaging wavelengths and setting their new optogenetic system state is kept to a minimum by immediately following data acquisition with application of new stimuli. When using controllers that require significant computational time to generate new light sequences, those stimuli calculated during the previous loop are applied before computing those to apply in the next. Microfluidic devices. Microfluidic mother machines allow straightforward, stable culture and observation of individual cells for hundreds of generations, in contrast to microscope culture techniques which do not actively remove progeny during growth. Our devices (23 µm × 1.3 µm × 1.3 µm (l, w, h) growth channels with 5 µm spacing along a split media trench, Supplementary Fig. 2) are fabricated by curing degassed polydimethylsiloxane (Sylgard 184, 1:10 catalyst:resin) against epoxy replicate master molds produced from primary wafer-molded devices 54,55 . Cured PDMS bulk is peeled from the molds and trimmed as appropriate, input and output ports are punched with electropolished 18ga luer stubs. The PDMS bulk and a clean cover slip are rinsed with 100% isopropanol, blown dry, baked on a hotplate at~125°C for 15 min. They are then cooled, and the surfaces to be bonded exposed to air plasma (Harrick PDC-002 plasma cleaner, medium power) for 1 min, and then brought gently into contact. The bonded devices are left at room temperature for 15 min, post baked for 1-2 h at 80°C, and then stored until use. Polyethylene tubing (Instech, BTPE-50) is press-fitted onto 22ga luer stubs and cannulae (Instech) on opposite ends for coupling to media supplies and waste, and to the devices, respectively. Experiment setup and conditions. A frozen glycerol cell stock is thawed from −80°C, diluted 1:100 into 5 ml fresh LB containing 0.01% Tween20, with 20 µg ml −1 Chloramphenicol and 100 µg ml −1 Spectinomycin to maintain plasmids, and incubated for 6-7 h at 37°C. The experimental apparatus is initialized, prewarmed and equilibrated, and the microfluidic device flushed for 1 min with 0.01% Tween20 followed by air. The device is mounted to the microscope stage to warm and verify integrity. The grown cell culture is centrifuged at 4000×g for 4 min, and the pellet resuspended in a few µl supernatant and injected into the device by pipette. Once filling of the growth channels with cells is confirmed under the microscope, media supply and waste tubes are fitted to the device and running media (LB, 0.4% glucose, 0.01% Tween20) is flowed through the device at 4 ml h −1  Fig. 9). Experiment calibration, providing per-channel camera and projector offsets from the PDMS-glass interface focal plane, projector-camera image transforms, and projector shading correction are performed. For each control location on the chip, measurement areas for individual cells are specified (typically, by a 2.6 × 5.2 μm box at the end of a growth channel), and a software controller/target program is associated with each. Once all control locations have been populated and the system begins to acquire data and stimulate the cells, it runs automatically until the conclusion of the experiment. For experiments involving media switching, a stopcock and syringe pump flows are adjusted at the appropriate time (0.3 ml media plug between the stopcock and cells is replaced after approximately two 6-min cycles).
Media. LB containing 0.01% Tween20, 100 µg ml −1 Spectinomycin, and 20 µg ml −1 Chloramphenicol is used for strain preculture and plasmid maintenance preceding insertion of cells into the device. Running media (LB, 0.01% Tween20, 0.4% Glucose) is used thereafter. For doxycycline perturbations, a 1 µg ml −1 stock solution of doxycycline is diluted in running media to a final experimental concentration, and maintained at 23°C in the dark for the duration of the experiment.
Cell classification and invalidation. Over time, bacterial cells in mother machine devices may filament and/or halt growth 14 . Optogenetic systems are also subject to mutational dysfunction and plasmid loss from cells. Finally, cells can temporarily shift from focal locations or escape from channels entirely. In contrast to experimental setups that sample new cells from batch culture at each time point, such pathological cells and locations persist indefinitely in microfluidic mother machines without being outgrown or replaced. They must therefore be algorithmically classified and invalidated to avoid corrupting data of otherwise normal populations or from injecting spurious signals into closed loops.
To remove such pathological cells and locations from our experiments, we run a classification algorithm in which the mother cells in our device are automatically evaluated for continuous presence, growth, and maintenance of the optogenetic system. We use our cells' constitutively expressed YFP to verify cell presence at control locations and fluorescence measurement quality (YFP signal loss or excessive noisiness invalidates cells/locations). In addition, YFP images are segmented to extract cell shapes and invalidate non-growing cells whose smoothed elongation rate has fallen below a minimum threshold. Besides complete growth arrest, loss of plasmids from our system can occur, resulting in either: (i) a reduced YFP level due to a substantially increased growth and dilution rate (pSR43.6) or (ii) complete, extended loss of responsiveness and CFP signal (pSR58.6_cerulean). These are used to automatically classify cells as invalid when locally time-averaged YFP level or controller-estimated responsiveness fall below set thresholds. In general, cells that are ruled invalid in one test are eliminated for the remainder of the experiment.
If cell classification is used for post-experiment analysis, the data of invalidated cells is truncated to 150 min before the threshold violation to reduce inclusion of post-failure, pre-invalidation data. However, where cells are directly coupled through a controller, as in our pCL control experiments, then cell classification and invalidation is implemented and cells are removed in real time from the population contributing to control (although they can continue to receive light stimuli). In such cases, infrequently appearing cells that increase to extremely high levels of CFP fluorescence before being invalidated remain an impediment to good control. Therefore, in these cases, a second algorithm is used to rapidly identify such cells and block their contribution to the population until they are invalidated (Supplementary Methods, section 2.4).