Oscillatory surface rheotaxis of swimming E. coli bacteria

Bacterial contamination of biological channels, catheters or water resources is a major threat to public health, which can be amplified by the ability of bacteria to swim upstream. The mechanisms of this ‘rheotaxis’, the reorientation with respect to flow gradients, are still poorly understood. Here, we follow individual E. coli bacteria swimming at surfaces under shear flow using 3D Lagrangian tracking and fluorescent flagellar labelling. Three transitions are identified with increasing shear rate: Above a first critical shear rate, bacteria shift to swimming upstream. After a second threshold, we report the discovery of an oscillatory rheotaxis. Beyond a third transition, we further observe coexistence of rheotaxis along the positive and negative vorticity directions. A theoretical analysis explains these rheotaxis regimes and predicts the corresponding critical shear rates. Our results shed light on bacterial transport and reveal strategies for contamination prevention, rheotactic cell sorting, and microswimmer navigation in complex flow environments.

To date, predictions for this transition from upstream to transversal rheotaxis for bacteria are actively sought after.Moreover, bacterial rheotaxis at surfaces has been quantified by measuring instantaneous orientation distributions [32] or average transport velocities [34], but a dynamical picture of the underlying mechanisms is still missing.
Here, we investigate, for the first time, the timeresolved orientation dynamics of E.coli bacteria, as a function of applied shear close to walls.Two recent experimental techniques are combined with Brownian dynamics simulations and a thorough theoretical analysis.In particular, with increasing flow, we identify four regimes separated by critical shear rates: (I ) the wellknown circular swimming; (II ) direct upstream swimming without circling and without oscillations; (III ) a novel oscillatory motion, biased towards the direction of positive vorticity; (IV ) coexistence of oscillatory swimming to the positive and negative vorticity directions, with dynamical switching between these states.By monitoring the bacteria with 3D Lagrangian tracking we examine these regimes as a function of the shear rate.In a second assay the bacterial flagella are stained fluorescently to explicitly survey cellular orientation dynamics and the oscillation frequencies.Matching these experiments, we model the bacterial rheotaxis by accounting for the cells' chiral nature, hydrodynamic and steric interactions with surfaces, elongation, fore-aft asymmetry and activity.Starting from these individual swimmersurface-flow interactions we build up our understanding to the observed motility.We assess the relative importance of these contributions, and hence explain the full dynamics.These findings provide a broad understanding of microbial swimming in confined flows and allow to raise suggestions for optimising flow geometries as for example antibacterial channel design.

Experimental observations
We observe the dynamics of E. coli bacteria at surfaces under flow [Fig.1(a)].Two independent experimental realisations are used.First, we employ a novel 3D tracking technique [41] that provides full 3D trajectories of swimming bacteria over large distances, revealing their longtime Lagrangian dynamics.The bacteria used in these experiments are smooth swimmers, E. coli strain CR20, a mutant that almost never tumbles and moves with a typical swimming speed of v s = 26 ± 4µm/s.The experimental device is a rectangular channel made in PDMS and a constant flow is applied with a syringe pump.The channel height is H = 100µm, the width W = 600µm and its length is of several millimetres.Hence, the shear rate at the bottom wall is defined as γ = 4V max /H, where V max is the maximum flow velocity at the channel centreline.Bacterial trajectories are only selected when they are located more than 100 µm from the lateral side walls and less than 5 µm from the bottom surface, so that the wall shear rate is constant and 3D trajectories are nearly identical to the x-z projections [see Materials & Methods (MM) § 1 for details].
Typical 3D trajectories for shear rates γ = 1 − 50s −1 are displayed in Fig. 1(b), in the laboratory frame.With increasing shear, we observe a range of different dynamics.Interestingly, at small shear rates the well-known circular motion [26][27][28] starts to evolve towards cycloid motion with a bias "to the right".Here we define the term "to the right" as the direction of the vorticity vector, Ω f = − γ ẑ [Fig. 1 laboratory frame trajectories bend into the direction of the flow.These trajectories are mostly oriented towards the right, as reported previously [32], but for the first time we observe that swimming towards the left can also occur.Note that different types of trajectories may coexist, likely due to variations in bacterial shape, the distance from the wall and other sources of noise inherent to living bacteria.Surprisingly, an oscillatory motion appears in these trajectories at frequencies very different from the flagellar and body rotation.These undulations are visible in the trajectories at the highest shear rate and can be identified clearly by looking at v z (t), the velocity component transverse to the flow direction [Fig.1(c); top panel].However, since the 3D tracking technique does not provide direct access to bacterial orientation, we also perform a second and complementary set of experiments.Here we use a genetically modified strain of bacteria, from the AB1157 wild-type (AD1) [42], with a fluorescently labelled body and flagella so that the cell orientation is directly visualised.This wild-type strain can tumble, but we only select trajectories without tumbles, which can be easily identified from the images.The channel dimensions are H = 20µm and W = 200µm, and again bacterial dynamics are captured only within a maximal distance of 5 µm from the bottom surface.In this strong confinement high shear rates can be obtained using relatively small flow velocities, which facilitates straightforward manual tracking, but at the cost of a more variable shear rate in y compared to the 3D tracking.These fluorescence experi-ments unambiguously demonstrate the existence of oscillatory motion around a stable position [Fig.1(d)], shown here for an example swimming to the right.Moreover, they provide an immediate measure of the orientation angle dynamics ψ(t) [Fig.1(c); bottom panel].
To quantify this oscillatory rheotaxis, for the 3D tracking and fluorescence assays, we extract the oscillation frequencies from Fourier transformation of v z (t) and ψ(t) respectively [see MM § 1c].In both experiments the measured frequencies indicate a cross-over [Fig.1(e)].At small shear rates we find a constant frequency, corresponding to the circular swimming, and after a certain shear ( γ ≈ 10s −1 ) we observe an increase of the frequency corresponding to the oscillatory trajectories.Note, oscillatory rheotaxis should not be confused with the wobbling dynamics due to flagellar rotation [43], which have much higher frequencies and are distinctly different.
In the next sections we will develop a comprehensive model that explains these complex dynamics and predicts the corresponding oscillation frequencies.

Theoretical building blocks
In order to understand the rich behaviour of our experimental findings, we first identify and summarise the individual mechanisms that affect bacterial orientations.We distinguish between wall effects, flow effects, and the coupling of these.In the next sections we then combine these building blocks and describe their non-trivial inter-play.
We model a bacterium consisting of an elongated body and a left-handed flagellar bundle, subject to shear flow at a surface [Fig.2].We explicitly model both the inplane angle ψ ∈ {−π, π} and the pitch (i.e.dipping) angle θ ∈ {−π/2, π/2} [Fig.1(a)].Note, the bacterial conformation in principle also depends on the flagellar helix phase angle, which can lead to phase-dependent wobbling motion [43,44], but owing to its fast flagellar rotation this angle is averaged over.The orientation of a swimmer at the surface then evolves as where the reorientation rates Ω ψ and Ω θ stem from three main contributions, Ω = Ω W + Ω F + Ω V , that account for the presence of the wall (Ω W ), local shear flow (Ω F ), and surface-flow coupled effects (Ω V ).a. Wall effects.First, in the absence of flow, hydrodynamic swimmer-wall interactions [19,45] and steric interactions [20] enable bacteria to swim at a stable orientation approximately parallel to the wall [43,[46][47][48] [Fig.2(a)].We model this surface alignment as 1 is a geometric factor describing the elongation of the bacterium with effective aspect ratio Γ.The prefactor ν W is an effective angular rate capturing both the hydrodynamic and steric contributions, and the equilibrium pitch angle θ 0 < 0 represents the fact that bacteria on average assume a small angle pointing towards the wall [43].For simplicity, we set θ 0 = 0 but we verified that non-zero values do not alter our results qualitatively.Note, we still explicitly model dynamics in θ.
The second wall effect stems from the counter-rotation of the bacterial head and flagellar bundle.Near solid surfaces this leads to a hydrodynamic torque leading to circular motion in the clockwise direction [28,46] [Fig.2(b)].The associated reorientation rate in the ψ direction is approximated by [45], which simplifies to a constant rotation Ω W ψ ≈ ν C (1 + G) for small θ. b.Flow effects.Second, we discuss the contributions due to shear flows.Elongated objects such as rods and fibres, or dead bacteria [49], perform Jeffery orbits [50] such that the orientation vector performs a periodic motion about the vorticity (z) direction [Fig.2(d)], given by Ω In the presence of walls the orbit amplitudes decay because of the surface alignment [see previous paragraph] but their reorientation rate (frequency) is not affected significantly, as simulated in detail for passive ellipsoidal particles [51].
The second flow effect stems from the chirality of the bacterial flagella, making cells reorient towards the vorticity direction [52,53].Together with activity this enables stream-line crossing, which in the bulk leads to a net migration of bacteria "to the right" [40].We compute this effect using resistive force theory (RFT) applied to a helical flagellar bundle under shear flow, extending the calculations in Ref. [40] for all body cell orientations [see MM § 2 and Fig. 2(c)].This yields the chirality-induced reorientation rates with a prefactor νH 1 that solely depends on the geometry of the bacterium.
c. Weathervane effect due to wall-flow coupling.Third, we introduce a term that has been identified as an important contribution for sperm rheotaxis [30,31].The swimmer body experiences an effective anchoring to the surface when pointing towards it, because its hydrodynamic friction with the wall is larger than that of the flagellar bundle [54], an effect explained by lubrication theory [31].Consequently, the flagella are advected with the flow, like a weathervane.Then, the bacterium orients upstream [30,31,55], which we model using the reorientation rates for both α = {θ, ψ}.The hyperbolic tangent, with a constant θ V depending on the cell geometry, accounts for the fact that the asymmetry in friction reduces when the swimmer faces away from the surface, θ > 0, where the weathervane effect disappears [Fig.2(e)].This notion was not included in the single-angle descriptions used for sperm [30,31].

Combining the individual reorientation mechanisms
Having described the individual effects of the wall and the flow on bacterial reorientation, we can now combine these terms to begin to understand more complex dynamics.First of all, by joining the contributions from surface alignment and head-tail rotations, we recover the well-known circular swimming [28,46].However, when we also add the weathervane effect (3) the cells break out of the circular kinetics and swim upstream, which corresponds to a stable fixed point in their orientation space [Fig.2(f)].This Adler transition has also been observed for sperm cells [31].
Second, combining the effects of Jeffery orbits and chirality (2), we recover bulk rheotaxis [40].Recast into the language of dynamical systems, the symmetry breaking leading to preferred motion 'to the right' can be classified as a stable 'spiral' fixed point in ψ − θ phase space [Fig.2(g)].
Third, merging the Jeffery orbits in the bulk and the weathervane effect (3) for cells near a surface, we find that Jeffery's periodic motion about the vorticity directions (± ẑ) now shifts to oscillations about a vector pointing more and more upstream.This already hints towards the observed oscillatory rheotaxis, but the corresponding fixed points are not stable [Fig. 2 experimental trajectories accurately, therefore, we must include all terms together and also add fluctuations, as described in the next section.

Brownian dynamics simulations
Combining all the aforementioned contributions, we solve the orientation dynamics by integrating Eqs.(1) for a range of constant shear rates, together with rotational noise (D r = 0.057s −1 [56]), as detailed in MM § 3.All our parameter values have been estimated carefully from previous experiments and numerical results, as dis-cussed in MM § 4, and the results are qualitatively robust for changes in these parameters.A simulated trajectory starts with a random ψ and a slightly negative pitch angle, θ = −0.1π,and finishes when it reaches a given escape angle θ e [56][57][58].Subsequently, the spatial dynamics are found by computing the velocity parallel to the surface, at a constant swimming speed v s plus the downstream advection with velocity v f = γy x based on the shear rate and the distance from the wall, y.Hence, Figure 3 shows typical trajectories and the orientation dynamics in ψ-θ space for different shear rates γ and initial conditions.We identify four regimes (I-IV ) separated by critical shear rates: At weak flows (regime I ) the bacteria move in circular trajectories, with a drift to the right [Fig.3(a)].Above a critical shear rate, found in the simulations at γsim c1 ≈ 3s −1 , they no longer move in circles but swim stable to the right and slightly upstream (regime II ) [Fig.3(b)].This Adler transition [31] stems from the competition between the constant head-tail rotations and the weathervane effect that increases with flow.Owing to noise, coexistence between circling and stable swimming may exist close to γc1 , and oscillations may also appear already, as discussed below.
Above a second critical shear rate, γsim c2 ≈ 15s −1 (regime III ), an oscillatory motion directed to the right emerges [Fig.3(c)].Similar to the first transition, the oscillations arise because the flow contributions now outweigh the surface terms that do not increase with shear.Particularly the Jeffery and weathervane effects govern the oscillation dynamics, as discussed in the theoretical predictions section.A simplified pictorial summary of this oscillation process is provided in Figure 5.However, the equilibrium angles about which the cells oscillate, ψ * ∼ π 2 and θ * ∼ 0, still depend strongly on the other terms, as derived below.Especially the surface alignment is necessary for stability, so in general the dynamics remain a complex interplay between all contributions and fluctuations.
Above a third critical shear rate, γsim c3 ≈ 30s −1 (regime IV ), oscillatory swimming to the left arises [Figs.3(d)], in coexistence with the aforementioned oscillations to the right.In phase space, this is defined by the emergence of a stable spiral fixed point, at ψ * ∼ − π 2 on the left.Moreover, bacteria may switch dynamically between the left and right (orange and green trajectories).However, this mode of rheotaxis is rare as the flagellar chirality term (2) gives a bias to the right that also grows with shear.
Throughout these regimes, the orientation distribu-tions have a complex dependence on the shear rate [Fig.4(a)].In the absence of flow, the orientations are uniformly distributed, as expected [dark blue distribution].In regime I the circular swimming is biased to the right, giving a peak in the distribution at ψ * ∼ π 2 [blue].In regime II the swimmers move more and more upstream, so the peak shifts to ψ * 0 [cyan] due to the weathervane effect, as also observed for sperm cells [31].
In regimes II-III the cells shift from upstream to the right again, ψ * ∼ π 2 [green], in agreement with previous studies [32][33][34].This is explained by the weakening of the weathervane effect, because the surface anchoring is reduced by the Jeffery term that tries to rotate the bacterium away from the surface.Consequently, the optimal shear rate for upstream orientation is found at γsim u ≈ 6.8s −1 , where the in-plane orientation is ψ sim u ≈ 39.6 degrees [cyan].Finally, in regime IV swimming to the left emerges at In the absence of tumbling, the fraction of bacteria oriented to the left is ∼ 4% at large shear rates [red], but with tumbles this increases substantially as dynamical switching is enhanced [Supplementary Fig. S2].

Analytical predictions
The observed and simulated transitions can also be met with theoretical predictions, as detailed in MM § 5. We consider the case in the absence of noise, and analyse the dynamics in (ψ, θ) orientation space.The equilibrium orientations, ψ * and θ * , can be found from the fixed points of Eq. 1.We obtain the exact values numerically, and also estimate them analytically by linearising Eq. 1 about (ψ, θ) = (±π/2, 0) and solving for the two roots.
The equilibrium orientations found with this analysis are depicted in Fig. 4 Using this framework we also obtain the first critical shear rate, and the second critical shear rate, γth c2 ≈ 13.6s −1 .The third critical shear rate does not follow from linearisation but is found numerically, γth c3 ≈ 29.7s −1 .These are combined to form the complete phase diagram [Fig.4(b); vertical grey lines].Moreover, the optimal shear rate for upstream swimming is found to be γth u ≈ 5.95s −1 and the corresponding upstream orientation, ψ th u ≈ 26.7 degrees.These four predictions agree very well with the numerical values obtained from our simulations.
Finally, we also derive the oscillation frequency.Interestingly, this solution [Fig.1(e); yellow line] increases from zero after the second critical shear rate.For high shear rates the frequency can further be approximated as which increases linearly with the applied shear rate.This solution offers a good agreement with our simulations and experiments, as discussed next.

DISCUSSION
Our model allows to predict the full time-resolved orientation dynamics of E. coli close to surfaces as a function of the applied shear rate.All types of trajectories predicted by our model have also been observed experimentally [Fig.1(b)].First, at lower shear rates we see the transition from circular motion to upstream swimming [light blue trajectories].This is when the upstream biasing weathervane effect [30,31] takes over from the torque due to head-tail rotations.Second, at intermediate shear rates we see a transition from smooth swimming to oscillations [orange trajectories].This is when the Jeffery and weathervane effects couple to drive oscillations, and like in bulk rheotaxis [40] the chirality of the helix sets a bias to the right.Third, at the highest shear rates we also see the switching to left-oriented motion [red trajectories].Here the left direction becomes stable with respect to fluctuations, although the chirality still drives a main preference to the right.Of course, in these observations visual differences can arise from fluctuations, variations in swimming speed and distance with respect to the wall.The critical shear rates predicted from both numerical and analytical findings are in reasonable agreement with those observed experimentally.In addition, the experimentally observed angular dynamics are very well captured.In particular, the oscillation frequencies obtained from Fourier transformation of the experimental trajectories [Fig.1(e); green hexagons and magenta stars] match the simulated frequencies [blue triangles] and the analytical prediction [yellow line] quantitatively.
Beyond our theory using equilibrium analysis without noise, we expect that fluctuations will contribute to three main effects: First, they sustain oscillations despite the wall-alignment damping, as observed in experiments [Fig.1] and simulations with noise [Fig.3].Second, they also allow for oscillations to emerge below the critical shear γc2 , as seen in Fig. 3(b).Third, they facilitate dynamical switching between left and right-orientated rheotaxis [Fig.3(d)], which can be envisaged as jumps in orientation space.In our experiments we have used non-tumbling cells to study oscillatory rheotaxis in a controlled manner, and bacterial tumble events will additionally contribute to these oscillations and left-right switches.Accordingly, in simulations with tumble events we see more swimming to the left at higher shear [Supplementary Fig. S2].Moreover, for wild-type strains the average population dynamics at surfaces is also expected to depend quite sensibly on the run-time distribution.
In conclusion, we demonstrate that bacterial surface rheotaxis can be categorised in four regimes, separated by shear-regulated transitions.We observe these regimes using a Langrangian 3D cell tracking technique that allows us to follow bacteria in a flow over long times, and with independent measurements by fluorescently staining the cell flagella to monitor the cell orientation explicitly.A comprehensive model delineates these dynamics by combining previously postulated contributions with newly derived rheotactic terms near a surface.Simulating this model yields the cellular orientation distributions and their oscillation frequencies with increasing shear rates, and a theoretical analysis of these equations allows to predict the corresponding critical shear rates.We find that both the bulk rheotaxis term [Eq.2] and the flow-wall coupling [Eq.3] play significant roles, through a previously under-appreciated dynamical interplay of the bacterial in-plane and pitch angles.Even if the bulk rheotaxis prefactor is small, the bias it generates is additive over time and also affects the orientation distribution of bacteria entering the surface in favour of swimming to the right.Importantly, this bias raises the suggestion that upstream swimming in conventional cylindrical pipes could be deterred with a right-handed surface patterning that spirals inside the duct.Then right-oriented cells would hit a barrier when swimming upstream, and only a small amount of left-oriented cells could pass if not advected downstream already.Moreover, oscillations at the surface increase the probability to detach, thus tuning γc2 could modify the average residence time on the wall and thus the ability for cells to contaminate upstream areas or initiate biofilms.Together, these results shed new light on bacterial transport and allow for the development of strategies for controlling surface rheotaxis.

Experimental details a. 3D tracking experiments
The bacteria are smooth swimmers E. coli (CR20), a mutant strain that almost never tumble.Suspension are prepared using the following protocol: bacteria are inoculated in 5mL of culture medium (M9G: 11.3 g/L M9 salt, 4 g/L glucose, 1 g/L casamino acids, 0.1mM CaCl 2 , 2mM MgSO 4 ) with antibiotics and grown over night.In this way, bacteria with a fluorescently stained body are obtained.Then the bacteria are transferred in Motility Buffer (MB: 0.1mM EDTA, 0.001mM l-methionine, 10mM sodium lactate, 6.2mM K 2 HPO 4 , 3.9mM KH 2 PO 4 ) and supplemented with L-serine and polyvinyl pyrrolidone (PVP).The addition of L-serine increases the bacteria mobility and PVP is classically used to prevent bacteria from sticking to the surfaces.The interactions that come into play using this system are thus solely steric and hydrodynamic.After incubating for an hour in the medium to obtain a maximal activity, the solution was mixed with Percol (1:1) to avoid bacteria sedimentation.Under these conditions, the average swimming speed is vs = 26 ± 4µm/s.For the experiments the suspension is diluted strongly such as to be able to observe single bacteria trajectories without interactions between bacteria.
The experimental cell is a rectangular channel made in PDMS using soft lithography techniques.The channel height is h = 100µm, the width w = 600µm and its length is of several millimeters.Using a syringe pump (dosing unit: Low Pressure Syringe Pump neMESYS 290N and base: Module BASE 120N) we flow the suspension inside the channel at different flow rates (1 1,88 4,5 9 18 50 nL.s−1 ), corresponding to wall shear rates of 1-50 s −1 .To have access to the 3D trajectories of single bacteria under flow we use a 3D Lagrangian tracker [41] which is based on real-time image processing, determining the displacement of a xy mechanical stage to keep the chosen object at a fixed position in the observation frame.The z displacement is based on the refocusing of the fluorescent object, keeping the moving object in focus with a precision of a few microns in z.The acquisition frequency is 30 Hz.The Lagrangian tracker is composed of an inverted microscope (Zeiss-Observer, Z1) with a high magnification objective (100X/0.9DIC Zeiss EC Epiplan-Neofluar), a xy mechanically controllable stage with z piezo-mover from Applied Scientific Instrumentation (ms-2000-flat-top-xyz) and a digital camera ANDOR iXon 897 EM-CCD.Trajectories are only considered when far away from the lateral walls (distances larger than 100 µm) and as long as they are within 5 µm from the surface.A typical error on this distance, resulting from the uncertainty on the z-detection as well as the uncertainty on the position of the bottom surface is around 3 µm.

b. Fluorescence experiments
For flagella visualization, we use a genetically modified strain from the AB1157 wild-type (AD1) published in Ref. [42].This strain contains a FliC mutation to bind to the dye from Alexa Fluor.Single colonies of frozen stocks are incubated overnight (16 h) in 5mL of liquid Luria Broth at 30 C, shaken for aeration at 200 rpm.The bacteria are washed and resuspended in Bergs motility buffer (BMB: 6.2 mM K 2 HPO 4 , 3.8 mM KH 2 PO 4 , 67 mM NaCl, and 0.1 mM EDTA).For flagella staining, 0.5mL of the bacterial suspension in BMB at 2 × 10 9 bact/mL are mixed with 5µL of Alexa Fluor 546 C5-maleimide suspended at 5mg/mL in DMSO.The sample is kept in the dark, shaking at 100rpm for 1h.Bacteria are then three times washed in BMB and finally suspended at 10 8 bact/mL in BMB supplemented with polyvinylpyrolidone (PVP 350 kDa: 0.005%) to prevent sticking to the walls of the microchannel.The solution is then seeded with passive particles to be used for flow velocity determination (latex beads from Beckman Coulter d = 2µm, density ρ = 1.027g/mL at a volume fraction φ = 10 −7 ).
The microfluidic PDMS channel is H = 20µm deep, W = 200µm wide and several millimeters long.We capture the bacterial dynamics of bacteria within 5µm from the surface, using an inverted microscope (Zeiss-Observer, Z1) with a high magnification objective (100 × /0.9 DIC Zeiss EC Epiplan-Neofluar) and a digital camera ANDOR iXon 897 EMCCD at 30fps.As bacteria are transported downstream, they are kept in the frame of observation by manually displacing the microscope's stage, which position is registered.During post-processing we extract the bacterial positions and orientations from the images.

c. Data analysis
To determine the frequency of the bacterial oscillations, we Fourier transform the bacterial trajectories obtained from experiments for different shear rates.(1) In the case of the experiments using bacteria with fluorescently labelled flagella, the in-plane angle ψ(t) of the cell orientation is determined by fitting an ellipse to the acquired camera image and distinguish between head and tail by the velocity director.(2) In the case of the 3D tracking experiments, the orientation cannot be determined in the same manner, but the lateral velocity vz(t) is used to search for oscillatory motion.Hence, either ψ(t) or vz(t) are Fourier transformed for trajectories of sufficiently long duration to resolve the lowest and highest frequencies accurately.The frequency of each trajectory is determined by selecting the highest peak in the resulting Fourier spectrum.This is repeated for all trajectories to form an ensemble of frequencies, from which we evaluate the mean frequency f ( γ) and its standard deviation.

Chirality-induced rheotaxis
Marcos et al. used Resistive Force Theory (RFT) to calculate the rheotactic behaviour of helical bacteria in shear flows in the bulk [40,53].Based on their work and using their Mathematica notebook, that includes the resistive force theory calculations for a helix subjected to shear flow, we are able to identify the full angular dependence of the rheotactic torque [Eq.( 2)].
In RFT a helical flagellum segment is approximated by a stiff slender rod with anisotropic friction coefficients ξ ⊥ and ξ || with 1 < ξ ⊥ /ξ || < 2. The viscous force per unit length opposing the motion of a rod is written as where the local rod velocity v l is a sum of its translational and rotational velocity v l = v + Ω × r(s; ψ, θ), and u || = (u • t) t, u ⊥ = u − u || ; here r(s; ψ, θ) is a space-curve of a helix parametrised by s and oriented along the swimmer direction, given by the angles ψ and θ, and the tangent is t = (dr/ds)/|dr/ds|.After integrating the force and torque on the helix at angles ψ and θ over the full helix length and averaging over the helix phase angle, one can in principle solve for the unknown helix velocity v and angular velocity Ω.While in a good approximation the helix will rotate in flow similar as a rigid rod-like particle [40], the velocity v determines chirality-induced migration velocity.
The analytic expressions for v obtained with Mathematica are rather lengthy and cannot be reduced or simplified by the program.However, we can plot the velocity components vx, vy and vz depending on its orientation angles ψ and θ for a given helix shape.Fortunately, by trial and error, we could extract the angular dependencies of the velocities, giving which linearly increase with the shear rate γ, and where the prefactor k 1 only depends on the helix geometry and is k 1 > 0 for a left-handed helix (as it is the case for the normal form of E. coli bacteria), and < 0 otherwise.The swimmer is oriented along direction e = (− cos θ cos ψ, sin θ, − cos θ sin ψ), and a rheotactic torque can be expressed as Ω H = −k 2 e × v where the prefactor k 2 depends on the shape of the cell body [40].The components Ω H x , Ω H y and Ω H z are given by ) where νH = 2k 1 k 2 .The components of this torque in the ψ and θ directions are written down in Eq. (2).

Simulations of surface rheotaxis
The bacterial surface rheotaxis is simulated by numerical integration of the orientation dynamics, encapsulated by the covariant Langevin equation [59] written out in terms of the angles (ψ, θ) that live on the curved surface |p| = 1, where Dr = 0.057µm 2 /s is the rotational diffusion coefficient [56], the noise correlations are defined as η i = 0 and η i (t)η j (t ) = δ ij δ(t − t ) and the deterministic terms are written out explicitly in equations (M8-M9) below.
Hence, N = 10 4 trajectories are simulated for 10 values of the applied shear rate, γ = 10 2.5(i−1)/9 , where i = 1, 2, . . ., 9, 10.From these trajectories (ψ, θ) the distribution of the in-plane angle, PDF(ψ), follows immediately.To determine the frequency of the bacterial oscillations, a trajectory must be sufficiently long to resolve the smaller frequencies.At high shear the average trajectory (residence) time is smaller than at low shear, so we discard trajectories shorter than 10s, which leaves at least ∼ 100 trajectories for any shear rate.The frequencies of the remaining trajectories are then obtained individually by Fourier transforming the in-plane angle ψ(t), and selecting the frequency of the highest peak in the resulting Fourier spectrum.Using this ensemble, we evaluate the mean frequency f ( γ) and its standard deviation.

Estimation of model parameters
In the following we present the parameters we used to produce Figs. 3 and 4 above.
Swimmer aspect ratio Γ: While cell bodies of E. coli bacteria have typical aspect ratios of ≈ 3, including the flagella bundle increases the effective aspect ratio Γ and we choose Γ = 5 for convenience.Note that Γ does not enter the model directly, but rather 1, which does not change significantly with Γ. Swimming speed vs: Because we use non-tumbling swimmers in our experiments we choose a constant swimming speed vs = 20µm/s.
Hydrodynamic/steric reorientation frequency at wall ν W : Steric reorientation rates have been reported to be of the order ν steric W ∼ 1 − 10s −1 for flagellated Caulobacter bacteria [20].Reorientation rates away from the walls due to hydrodynamic interactions can be approximated by far-field expressions [45].with a prefactor ν Hi W = 3p/(128πηh 3 ), where p = 0.8pN µm is the dipole strength of E. coli bacteria [56], η = 10 −3 P a s the viscosity of water, and h the distance of the swimmer from the surface.If far-field hydrodynamics would still hold close to the wall (h ≈ 1 − 2µm), one would find ν HI W ≈ 0.75 − 6s −1 , which is smaller than the steric contribution but also acts when the swimmer moves away from the surface, so it could increase the wall residence time [57].Also note that the 1/h 3 dependence likely gives an overestimate when a swimmer is very close to the wall, h < 1µm, as the multipole approximation breaks down.Taking this information together, we use ν W = 3s −1 to capture the combined effects of steric and hydrodynamic interactions.
Downstream advection: To calculate the downstream advection velocity due to the linear shear flow, we use the distance from the surface hs = 1µm, so the velocity is v f = γhs x.
Equilibrium pitch angle θ 0 : Recent results have shown that the equilibrium pitch angle θ 0 is not exactly parallel to the wall but sightly points into the surface [43].We have included this in our model by considering the surface alignment term with the equilibrium angle dependence sin(2(θ − θ 0 )), but this did not change our results much.Therefore we omit it for clarity, setting θ 0 = 0.However, we still allow explicitly for dynamics in θ from the other contributions.
Circling frequency near a wall ν C : The typical circling frequencies of an E. coli bacterium close to a boundary is on the order of ∼ 1s [28,46].Since the frequency Ω W ψ ≈ 2ν C for G ∼ 1, we choose νc = 0.5s −1 , which gives typical circles of radius R = v 0 /Ω W ψ ∼ 20µm.Note that there is quite a variety in these frequencies between different individual bacteria [46,47], which will lead to bacteria having different individual critical shear rates.
Chirality-induced bulk reorientation rate νH : The rheotactic drift for bacteria in bulk has been quantified by Marcos et al. [40,53], as described in §II above.We expect similar rheotactic strength for our bacteria, which is satisfied approximately for νH = 0.02.
Anchoring reorientation rate νV : Due to a similar size of the head, we expect that the order of magnitude for a bacterium is comparable to the values found for sperm cells [31], and we chose νV = 0.75.Note, the magnitude of this effect is reduced strongly when the swimmer is not in close proximity to the walls, since it relies on enhanced friction obtained from the lubrication regime [31,54].When the swimmer is oriented away from the surface (θ > 0) we expect this effect to vanish quickly, quantified by a small value θ V = 0.04 used in the tanh-function [see Eq. ( 6)].
Escape angle θe: In order to determine when a swimmer leaves a surface, it has to reach a certain escape angle θe which we chose to be θe = π/6, following references [56][57][58].Note that θe does not influence the dynamics in the model per se, but rather defines how long a bacterium stays at a surface.

Rotational diffusion:
The orientation of the bacteria is affected by fluctuations as they swim.We use the rotational diffusion coefficient Dr = 0.057µm 2 /s [56].
Tumbling: We do not include tumbling in our simulations presented in the main text because we use smooth swimmers in our experiments, but in Supplementary Fig. S2 we show orientation distributions for simulations that include tumbles.We simulate these tumbling events by temporarily increasing the swimmer's rotational diffusion coefficient [58], to D T = ϕ 2 /(2τ T ), where the average tumble angle ϕ = π/3 = 60 degrees [60], the tumbling time is τ T = 0.1s, and the duration between tumbles is exponentially distributed with average run time τ R = 1s.

Model fixed points and frequencies a. Summary of equations
Combining the deterministic contributions of our rheotactic model, we have ) ) b. Adler transition from circling to straight motion The first transition, from circling to straight motion, has previously been described in the literature for sperm cells [31].It can be characterised as the point at which the upstream-directed torque from weathervane effect becomes more important than the constant torque from the bacterial circling on surfaces.This can be captured in the limit of small pitch angles, θ → 0, where the one-dimensional equation for the in-plane angle (M8) simplifies to This can immediately be solved for the equilibrium angle ψ 0 where Ω ψ = 0.The solution is a little long to write down, but is nothing more than an arctangent.Further progress can be made by noting that νH νV and also cos ψ sin ψ, near ψ ∼ π/2, at shear rates close to the transition where the bacteria swim to the right.Consequently, the resulting equilibrium angle is given by This function has no real solutions for shear rates smaller than a critical value.Indeed, the rotating bacteria do not have a stable equilibrium orientation, but for large enough shear they break out of their circles and maintain a constant bearing.Therefore, we found the critical shear rate of Adler transition,

c. Approximation of the equilibrium orientations
In order to estimate the equilibrium rheotactic orientations at higher shear rates above the Adler transition, the one-dimensional approach breaks down because the pitch angle θ becomes significant.This shortcoming is also observed from the 1D solution (M11) that only decreases with increasing shear but does not capture the later increase, which gives rise to an optimum shear rate for upstream swimming.
Therefore, we aim to solve for both ψ 0 and θ 0 such that Ω ψ = Ω θ = 0.Because it is known that the bacteria swim to the right and left at high shear rates, we linearise equations (M8, M9) about these directions and also consider small pitch angles parallel to the surface: where α, β 1 and where the top sign (+) corresponds to swimming to the right and the bottom sign (−) corresponds to swimming to the left.To first order in α and β, that yields the linear expression where the shear-dependent coefficients are This matrix equation can be inverted directly, giving the equilibrium in-plane and pitch angles, These results are shown as the dotted lines in Fig. 4(a).
d. Optimal shear rate for upstream swimming Continuing from the above theory, it is also possible to extract an estimate for the optimal shear rate for upstream swimming.This occurs when the right equilibrium in-plane angle (given by Eqn.M16 with the top of the ± signs, and the green lines in Fig. 4b) is closest to the upsteam orientation (ψ → 0), thus at the minimum with respect to the shear rate.Hence, we seek to solve for where we wrote D = d 0 + d 1 γ, and similar for the other functions.This readily gives the desired optimum, the best shear rate for upstream swimming, γth u ≈ 5.95s −1 .Inserting this value into Eqn.M16 then also gives the most upstream orientation, ψ th u ≈ 26.7 degrees.

e. Oscillation frequency
We start with a linear stability analysis of the equilibrium orientation angles, (ψ, θ) = ψ 0 + ψ , θ 0 + θ , (M18) where ψ , θ 1. Expanding the equations of motion to first order in ψ and θ again yields The real part of the eigenvalues characterises the stability of the equilibrium orientation.For our model parameters it is always negative for all shear rates, indicating a stable equilibrium because of the surface alignment (ν W term).The imaginary part, however, characterises the presence of oscillations.For small shear rates the imaginary part is zero, but above a certain shear rate oscillations emerge.This occurs when (A − D) 2 = 4BC, at the critical shear rate Below this shear rate value, the equilibrium orientation is a "startype" stable fixed point, whereas above γO it is a "spiral-type" stable fixed point with damped oscillations.The oscillation frequency is given directly by the imaginary part of the eigenvalues (Eq.M20), shown as the green line in Fig. 4(c).For high shear rates, this tends to the linear function for the oscillation frequency If the weathervane and helix coefficients are small, this simplifies to the pure Jeffery frequency

FIG. 1 .
FIG. 1. Experimental observations of oscillatory rheotaxis.(a) Set-up geometry.(b) Various types of surface trajectories obtained from 3D tracking at shear rates γ = 1 − 50s −1 (colours), shown in the lab frame and arranged according to increasing shear.Circles indicate the initial positions.(c-e) Oscillatory rheotaxis.(c) Typical temporal evolution of the transverse velocity vz(t) from a 3D tracking experiment at γ = 49s −1 , and the in-plane angle ψ(t) from a fluorescence experiment at γ = 33s −1 .(d) Time lapse of an oscillating bacterium with fluorescently stained flagella, using 10 fps snapshots overlaid to highlight its trajectory, taken in the Lagrangian reference frame of the average downstream bacterial velocity.(e) Oscillation frequency versus shear rate, obtained from Fourier transformation of vz(t) in 3D tracking experiments (green hexagons), of ψ(t) in fluorescence experiments (magenta stars), and of ψ(t) in simulations (blue triangles).Overlaid are theoretical estimates (Eq.M20; dashed yellow line) and the circling frequency, Ω W ψ /2π, (dotted blue line).

FIG. 2 .
FIG. 2. Summary of reorientation mechanisms included in the model.Wall effects: (a) Steric and hydrodynamics interactions align swimmers with surfaces.(b) Clock-wise torque from the counter-rotation of the cell body and flagella.Flow effects: (c) Left-handed helical flagellar bundle in shear reorients swimmers to the right.(d) Jeffery orbits of elongated bacteria.Flow-wall coupling: (e) Weathervane effect reorients swimmers to the upstream direction.The corresponding orientation dynamics for (a)-(e) in ψ − θ phase space are shown in Supplementary Fig. S1.Combinations of the different effects give (f) Swimming in the upstream direction [a,b,e].(g) Bulk reorientation, biased to the right due to flagellar chirality [c,d].(h) Oscillatory swimming, oriented slightly upstream due to the weathervane effect [d,e].Green (red) stars are stable (unstable) orientation fixed points, and the blue diamond is a saddle point.The parameters used are given in the caption of Fig. 3, with shear rate γ = 10s −1 .

FIG. 4 .
FIG.4.Bacterial orientation as a function of applied shear.Parameters used are the same as in Fig.3.(a) Distribution of the in-plane angle ψ, obtained by simulating N = 10 4 trajectories over long times until steady state is reached, at each shear rate γ = 10 2.5(i−1)/9 with i ∈[1,10].(b) Equilibrium in-plane angle ψ * , obtained numerically (solid lines), analytically (dashed lines) and in simulations (points), with critical shear rates (grey vertical lines).

FIG. 5 .
FIG.5.Sketch of the oscillatory rheotaxis mechanism.Here the bacterium is initially oriented towards the right and slightly downstream, and red arrows show the projection of the cell onto the surface.Then, the oscillations can be envisaged as a 4-step process: (a) The vorticity pushes the body down into to surface and lifts the flagella up.(b) Then the flow advects the flagella faster than the body, rotating the bacterium about the y axis to the upstream direction.The weathervane effect enhances this rotation as the cell pivots about the anchoring point.(c) Now the vorticity pushes the flagella into to wall and lifts the body up.(d) Subsequently the body is advected faster, rotating the swimmer back to the downstream direction.This cycle is repeated, leading to oscillatory trajectories.Note that this is a simplified picture and all surface and flow effects [Fig.2]contribute to the dynamics at any one time.