Main

Sensory detection tasks have become a staple for probing cortical circuitry during behaviour, but the role of the primary sensory cortex in visual1,2,3, auditory4,5,6, gustatory7,8 and somatosensory behaviours9,10,11,12,13,14,15,16,17 remains unclear. Whether a brain structure is necessary for a behaviour is typically assessed by inactivation or ablation. Ablation experiments may underestimate behavioural deficits, owing to the long recovery periods used (more than one week), during which compensatory relearning or rewiring can occur. Transient optogenetic or pharmacological manipulations often yield stronger deficits and are currently preferred, being thought to reveal an area’s normal function before compensation. However, the sudden loss of a silenced area may disrupt downstream areas that are vital for behaviour, a phenomenon known as diaschisis. Recent studies in the motor system have underscored how the off-target effects of transient inactivation can lead to false conclusions18. To address these disparate outcomes, we compare transient and chronic manipulations of the barrel cortex subdivision of the primary somatosensory cortex (S1) during a simple detection task.

Water-restricted mice were trained in the dark to perform a GO/NOGO sensory detection task with their C2 whisker (Fig. 1a). Mice self-initiated trials by holding down a lever. On GO trials, a pole moved within reach of the whisker when protracted. Mice had to release the lever when they detected the pole to obtain a water reward (hit). On NOGO trials, the pole moved away from the mouse. Incorrect responses to NOGO trials (false alarms) were punished with a timeout. Misses and correct rejects were neither rewarded nor punished.

Fig. 1: Transient inactivation of barrel cortex impairs whisker-mediated detection.
figure 1

a, Head-fixed detection task. A high-speed camera imaged whiskers. Pole movement (GO or NOGO) and laser (ON or OFF) were randomized across trials. b, Coronal section of Emx1–GFP mouse brain. White dotted lines, barrel cortex boundaries; green, GFP; magenta, NeuN. Scale bar, 1 mm. c, Cortical array recordings during detection task and photoinactivation. Example rasters (top) and peri-stimulus time histograms (middle) for a single unit when no response was made (miss or correct reject) during an example session. d, Same neuron for trials with lever response (hit or false alarm). The laser turns off when the mouse responds, ending the trial. Trials sorted by response time, which varied (arrows in schematic at bottom). e, Effect of laser on neuronal spiking (n = 62 putative excitatory neurons, 8 sessions, 3 mice; mean ± s.d. 7.02 ± 6.81 and 0.16 ± 0.94 Hz for laser OFF versus ON, respectively). f, Average spiking activity aligned to first whisker contact of trial during an example session (n = 10 neurons). Contact times are defined as the local maxima, rather than onset, of curvature change (Extended Data Fig. 3; see Methods). Firing rates were normalized to mean rate during 100 ms before contact during laser-OFF trials. Thin lines, individual cells; thick lines, means of OFF (black) and ON (orange). gi, Behavioural performance for laser OFF versus ON trials. g, Per cent correct trials. h, Hit rate. i, False alarm rate. j, Response latency for hit trials. Emx1–Halo (n = 10 mice, red), negative control (n = 7 cre-negative, stop–Halo mice, black). Data shown as mean ± s.e.m. **P < 0.01, ***P < 0.001.

Conventionally, cortex is optogenetically silenced by activating inhibitory cells with channelrhodopsin (ChR), but this may inadvertently stimulate long-range inhibitory connections. We therefore developed an approach to directly silence excitatory cells by stably expressing halorhodopsin (Halo) in cortical excitatory neurons. Emx1-IRES-cre mice express Cre recombinase in excitatory cortical neurons while excluding subcortical structures (Fig. 1b). Halorhodopsin can be targeted to these neurons by crossing Emx1-IRES-cre with stop-Halo reporter mice (Emx1–Halo). Optogenetic silencing (by shining a laser onto these neurons during behaviour) was highly efficacious, blocking 95 ± 4% (mean ± s.e.m.) of spikes in putative excitatory cells (Fig. 1c–e, Extended Data Fig. 1j, k) including during whisker contacts, which normally strongly activate barrel cortex (Fig. 1f). Optogenetics efficiently silenced spontaneous and sensory-evoked activity in neurons across all cortical layers within a 1-mm radius, encompassing nearly all of the barrel columns that represent the large facial whiskers (Extended Data Fig. 1a–i).

Inactivation of barrel cortex significantly reduced overall performance (P = 3.6 × 10−4; n = 10 mice; Fig. 1g, Extended Data Fig. 2a), but performance remained significantly above chance (50%; P = 1.1 × 10−8, one-sample t-test). Despite the fact that mice made fewer responses to both GO and NOGO trials (Fig. 1h, i), response time was unaffected by the laser (Fig. 1j), demonstrating that the mice could still manoeuvre the lever. Control mice lacking Cre were behaviourally unaffected by the laser (n = 7 stop–Halo mice; Fig. 1g–j). Conventional photoinhibition by activating parvalbumin (PV)-positive inhibitory cells (n = 5 PV–ChR mice) yielded similar results to Emx1–Halo (Extended Data Fig. 2a). Thus, transient silencing of barrel cortex impaired detection.

Touch is an active process, during which subjects adjust their movements as they contact objects in their environment19,20,21. Even small changes in whisking could alter perception19. Although activation of barrel cortex can trigger whisker movements16,22, the effects of inactivation are less well understood12,23. We tracked whisking using high-speed videography (Fig. 2a, b). During NOGO trials, in which no contacts were possible, barrel cortex inactivation slightly but significantly decreased protraction velocity, whisker angle and peak amplitude (Fig. 2c–f, P = 6.5 × 10−3, 1.4 × 10−3 and 2.5 × 10−2, for d, e and f, respectively). Similarly, during GO trials, when the pole was present inactivation of barrel cortex decreased peak protraction velocity (Fig. 2g). We found no significant changes in whisking setpoint or frequency. We also assessed changes in whisker curvature, a proxy for contact force24 (Extended Data Fig. 3). Small changes in whisker movement had a large effect on whisker contacts, resulting in a reduction in force (Fig. 2h) and an increase in the number of trials without contacts (Fig. 2i). Thus, silencing of the sensory cortex reduced the vigour of whisker movement.

Fig. 2: Transient optogenetic inactivation of barrel cortex alters whisking kinematics and sensory threshold.
figure 2

a, b, High-speed video frame depicting traced C2 whisker during NOGO trial (a, pole moves away) and GO trial (b, pole within whisker reach). Whisker position was measured as its angle (θ) relative to the face. The whisker bends upon contacting the pole, changing whisker curvature. c, Average whisker angle for NOGO and GO trials for an example session. A 200-ms window (blue shaded area), from when the pole was within reach and before the response, was analysed. Green, average response time. df, Whisking kinematics for each mouse during NOGO trials. d, Peak angular velocity of whisker protraction; e, maximum whisker angle; f, mean peak whisking amplitude. gi, For GO trials: g, peak angular protraction velocity; h, average maximum change in curvature (ΔΚ); i, per cent of trials without any contacts. j, Logistic regression of response probability given maximum change in curvature for an example session. Tick marks indicate responses (0 for no response; 1 for lever response) on individual trials. Detection threshold was defined as the value at which response probability is 0.5. k, Detection threshold for maximum ΔΚ of each mouse. Thick orange line, means. l, Slope (sensitivity). m, Logistic regression of response probability against number of contacts per trial for an example session. n, o, Detection threshold (n) for number of contacts and slope (o). *P < 0.05, **P < 0.01, ***P < 0.001, n = 10 mice.

We investigated whether behavioural impairment was simply due to altered whisking or whether there was an accompanying sensory deficit: whether, for any given stimulus strength, transient inactivation of the sensory cortex decreased the probability of response. Cortical silencing significantly increased detection threshold (0.5 response probability) for curvature (Fig. 2j, k; P = 9.7 × 10−4) and number of contacts (Fig. 2m, n; P = 3.3 × 10−3), but not sensitivity (Fig. 2l, o). We observed similar motor and sensory deficits in PV–ChR mice (Extended Data Fig. 2b, c). Thus, transient optogenetic manipulations impair behaviour by both increasing sensory threshold and decreasing whisker movement.

Increased sensory threshold is distinct from an absolute inability to detect stimuli. The observed threshold shift could reflect incomplete inactivation, as a few renegade spikes may suffice for detection25. However, residual spiking during optogenetic silencing did not correlate with behavioural outcome (Extended Data Fig. 1l, m). To ensure complete inactivation, we removed contralateral barrel cortex by aspiration (n = 11) (Fig. 3a, b, Extended Data Fig. 4). Consistent with optogenetic results, behaviour was impaired one day after lesioning contralateral barrel cortex (Fig. 3c, red), but not in sham-operated controls (n = 4, black) or when ipsilateral barrel cortex was lesioned (n = 4, blue). Again, impairment was only partial, and behaviour remained significantly above chance levels (P < 10−6, one-sample t-test).

Fig. 3: Behavioural performance recovers rapidly after barrel cortex lesions.
figure 3

a, Coronal section of L4-labelled mouse brain (white dashed lines, barrel cortex boundaries; blue, DAPI; green, eYFP) in unlesioned hemisphere. b, Lesioned hemisphere shows complete removal of barrel cortex. c, Behavioural performance before and after S1 lesions (sham n = 5, ipsilateral n = 4, contralateral n = 11, contralateral with striatal lesion n = 8). d, Behavioural performance of contralateral S1 lesioned mice recovers abruptly between first and second sessions after lesioning. e, f, Whisking kinematics during NOGO trials (e) and GO trials of mice (f) are altered on first post-lesion session but return to normal by second post-lesion session (n = 10 contralaterally lesioned mice). g, Post-lesion trimming confirms that task remained whisker-dependent. Dashed line indicates chance performance. h, Example logistic regression of response probability given whisker curvature. Sensory detection threshold for whisker curvature increases on first session post-lesion (pink) and returns to pre-lesion levels (black) by second session (red). i, Average detection thresholds for whisker curvature and number of contacts before lesion and for second session after lesion (n = 10). j, Mice with three days of rest after lesion still had impaired performance on the first post-lesion session but subsequently recovered (n = 8). k, Behavioural performance for three-day rest group remains whisker-dependent. ***P < 0.001.

Unexpectedly, by the second session after lesioning, behaviour had recovered fully to pre-lesion levels (Fig. 3c). Mice recovered whether lesions encompassed only barrel cortex or additionally included the secondary somatosensory cortex (Extended Data Fig. 4). There was no evidence of gradual relearning within sessions; rather, performance abruptly recovered between the first and second post-lesion sessions (Fig. 3d), suggesting that recovery was unlikely to result from previously uninvolved circuits learning the task anew. Furthermore, subsequent lesioning of ipsilateral barrel cortex did not perturb performance, as these bilaterally lesioned mice performed similarly to sham and ipsilateral-only lesioned mice (Extended Data Fig. 5). Notably, additional damage to the dorsolateral striatum prevented behavioural recovery (Fig. 3c, n = 8, orange; Extended Data Fig. 6), suggesting that the striatum has an important role in detection behaviour.

Consistent with optogenetic results, whisker movement and contacts were decreased during the first session after lesioning (Fig. 3e, f, pre versus 1). However, whisking kinematics for the recovered, second session never exceeded pre-lesion levels (Fig. 3e, f; pre versus 2), indicating that mice did not compensate for impaired sensation with greater contact force or frequency. Similarly, sensory thresholds pre-lesion and on the second post-lesion session did not differ significantly in contact force or number (Fig. 3h, i). Thus, after only a temporary impairment, both motor and sensory abilities returned to pre-lesion levels along with behavioural performance.

Recent studies have suggested that homeostasis may spontaneously restore activity in connected structures within 24–48 h, similar to the time frame seen here18,26. To test whether behavioural recovery was spontaneous or required re-exposure to the task, we gave another group of mice three days between lesion and retesting (n = 8). This group showed similar impairment on the first post-lesion session but also recovered (Fig. 3j), albeit more gradually, indicating that task re-exposure—rather than simply the passage of time—triggers recovery. Removing the C2 whisker reduced the performance of both groups (1 day rest and 3 days rest) to chance, confirming that lesions did not induce mice to switch from whisker-mediated touch to other sensory modalities (Fig. 3g, k).

Thus, three different manipulations of barrel cortex—Emx1–Halo, PV–ChR and lesions—transiently disrupt the execution of active detection behaviour. Recent studies have shown that the motor cortex might not be required for the execution of skilled movements, but is required for motor learning27. To determine whether the sensory cortex is required for learning of the detection task, we lesioned contralateral S1 of naive mice. Subjects were habituated and trained on lever manoeuvring. Learning rate was assessed, starting with the introduction to the pole (Fig. 4a, learning assessment, red). Initially, sessions consisted of 90% GO trials until mouse weight stabilized (3.6 ± 1.5 sessions), after which mice still performed at chance (Extended Data Fig. 7a–c). Lesioned and unlesioned mice learned at similar rates (Fig. 4b, c). Non-learners were equally present in both groups (Fig. 4d; 6/17 unlesioned, 5/14 lesioned, P = 1, Fisher’s exact test), and failure to learn was not correlated with lesion size (Fig. 4e). In fact, among learners, mice with larger lesions learned faster than those with smaller lesions (Fig. 4e, linear regression, P = 0.02). Again, performance remained whisker-dependent (Fig. 4f, g). Thus, barrel cortex is not essential for learning the detection behaviour.

Fig. 4: Barrel cortex is not required for learning whisker-dependent sensory detection task.
figure 4

a, Timeline for learning assay. b, Cumulative histogram of number of sessions to reach learning criterion (>74% correct for two consecutive sessions). The speed of learning was similar between unlesioned (n = 17) and lesioned (n = 14) mice. c, Among mice that learned the task, the number of sessions to criteria did not differ between unlesioned (n = 11) and lesioned (n = 9) mice. d, The fraction of mice that did not learn within the assessment period was similar between groups (unlesioned n = 6, lesioned n = 5 mice). e, Inability to learn was not due to larger lesion size. NL, non-learners. f, g, Unlesioned (f) and lesioned mice (g) that did learn could no longer perform the task when the C2 whisker was trimmed. ***P < 0.001.

Task acquisition involves motor (lever press or lift), perceptual (pole detection) and contingency learning (lever→reward, contact→lever→reward). Notably, mice acquired the task whether they were lesioned before handling and lever training (Fig. 4a, open triangle, n = 4) or just before introduction of the pole (closed triangle, n = 5). Mice spent similar amounts of time in pre-training whether lesioned before pre-training or unlesioned (P = 0.13). Thus, barrel cortex appears not to be required for motor, perceptual and contingency learning of this task.

Our results demonstrate the potential for structures other than the sensory cortex to direct learned behaviours that require arbitrary coordination of multiple movements (lever press, whisking and licking) around a sensory event. This raises concerns about the interpretation of cortical physiology studies that use detection behaviours, as well as tasks requiring discrimination of elementary features encoded at the periphery (body location, retinotopic location, taste and sound frequency), which subjects may circumvent with detection strategies. It underscores the need to identify the behavioural conditions for which sensory cortex is indispensable, which might involve more complex discrimination, egocentric or allocentric context10,28, or working memory29.

In conclusion, impairment after transient inactivation does not absolutely indicate necessity. This raises the question of  what the functional relevance of barrel cortex is to active detection. One possibility is that the barrel cortex and other structures are redundant for active detection30. Multiple subcortical structures receive barrel cortex input and, via other routes, whisker-related sensory signals. The trigeminal brainstem complex projects directly to the superior colliculus and cerebellum, and indirectly to the dorsolateral striatum via the secondary somatosensory thalamus30,31,32. Indeed, damage to striatum prevented recovery. Further studies are needed to assess the roles of other subcortical areas.

A second possibility is that manipulation of any cortical area may temporarily disrupt connected structures that are primarily involved in the task. In this scenario, the sudden loss of barrel cortex activity, rather than the sensory information it conveys, can be disruptive. The incomplete behavioural impairments we observed, as well as the sudden recovery after lesioning, raise the possibility of a disruptive effect, rather than redundancy. Subcortical systems are major targets of deep layer cortical pyramidal cells, which have high baseline firing rates, and removing their tonic activity may disrupt the responses of corticofugal targets to sensory inputs. In the birdsong motor system, lesions transiently disrupt activity in downstream areas and the production of song, both of which recover overnight18. In the birdsong study, it was unclear whether recovery was spontaneous or required some attempts, even if unsuccessful, at singing. A major advantage of our study is that we could control the time of re-exposure to the task after lesioning. Early task-specific experience accelerated recovery, and this may have important implications for early rehabilitation after stroke or head trauma. Whether recovery is always experience-dependent or whether sensory and motor systems differ are intriguing questions for further study.

Methods

Transgenic mice

All mouse procedures complied with the NIH Guide for the Care and Use of Laboratory Animals and were approved by the Institutional Animal Care and Use Committee at Columbia University. Emx1–Halo mice (n = 10) were generated by crossing Emx1-IRES-Cre33 knock-in mice (Jackson Laboratories, stock #005628) to Rosa-lox-stop-lox (RSL)-eNpHR3.0/eYFP mice (stop-Halo Ai39, JAX, stock# 006364), which express halorhodopsin after excision of a stop cassette by Cre recombinase. Cre expression was assessed by crossing Emx1–Cre mice to RSL-H2B–GFP mice (provided by J. Huang). Negative control mice were Cre-negative and could not express the halorhodopsin transgene (n = 7 stop-Halo mice). PV–ChR mice (n = 5) were generated by crossing parvalbumin-Cre mice34 to RSL-channelrhodopsin2/eYFP mice (Ai32, Jackson Laboratories, stock# 024109). For visualizing barrels in S1, Nr5a1–Cre mice (JAX, stock# 006364) were crossed to RSL-Halo–eYFP (Nr5a1–eYFP). All mouse lines were maintained on a C57BL/6 background. Optogenetic experiments used mice that were heterozygous for the desired transgene. The experimenters were not blind to genotype during testing and analysis.

Intrinsic signal optical imaging to locate C2 barrel

Mice were anaesthetized with isoflurane, and the skull over the left barrel cortex (centred ~1.5 mm posterior to bregma and 3.5 mm lateral to the midline) was thinned and sealed with Vetbond (3M) over a 4–5-mm area, or a glass window (3-mm coverslip, Warner Instruments) was implanted. Images were acquired with a CCD camera (Q-Imaging, Retiga 2000R) mounted on a stereomicroscope and software custom-written in LabVIEW. The vasculature on the brain surface was imaged with 510/40 band-pass filtered illumination (Chroma, D510/40), and functional imaging done with illumination with a 590-nm long-pass filter (Thorlabs, OG590). The C2 whisker was stimulated with 8 pulses of 4 directions at 5 Hz with a multi-directional piezo stimulator. The location of the maximum reflectance change was mapped relative to the surface vasculature. Two or three surrounding whiskers were also imaged to confirm proper identification of the C2 barrel location.

Behavioural setup

The behavioural setup was controlled by a microcontroller (Arduino), and data collected using custom-written routines. Subjects self-initiated trials by holding down a lever with their left forepaw for at least 100 ms. A pole (~2.15-mm-diameter wooden applicator stick) started from a position 3–4 cm below the mouse. After trial initiation, a stepper motor (Pololu Robotics and Electronics) rotated the pole to just in front of the whiskers (GO trials) or away from the whisker field entirely (NOGO trials). GO and NOGO trials were randomized. Rotation in either direction ensured that the sound and vibration generated by the motor was similar between trial types. The sound of the motor also served as a trial onset and offset cue. For GO trials, the pole was positioned 9–11 mm laterally and roughly aligned to the tip of the nose in the anterior–posterior dimension, such that mice were required to actively whisk forward to make contact. If the lever was lifted within the response window of 1.2 s during GO trials (hit), the response was rewarded with a drop of water and a reward tone. False alarm responses during NOGO trials were punished with a timeout period of 3–8 s accompanied by white noise sound, during which the mouse could not initiate a new trial. There was no reward for a correct reject and no punishment for a miss. The response latency was defined as the time from when the pole was first within reach of the mouse’s whisker (typically 480 ms from trial onset, identified from high-speed video for each session analysed) to the mouse’s lever lift response.

Mouse training

Test of task performance

Adult mice (P116 ± 60 days, mean and s.d., 34% male) were implanted with a custom-designed 22-gauge stainless steel laser-cut (Laser Alliance) headplate with dental acrylic. After ~1 week of recovery, subjects in optogenetics experiments were water-restricted and then trained in stages. Progression through each stage depended on the individual mouse’s weight stabilization (indication of health). (1) Freely moving mice were habituated to the behavioural apparatus, where water reward was given for holding down a lever (2–3 days). (2) Mice were head-fixed and continued lever training: water was awarded for holding down lever for 500 ms to initiate trial, followed by releasing the lever for >100 ms (2–4 days). (3) Mice were trained in a dark chamber where no visual cues could be used. Mice were trained with 90% GO trials with a pole, and received water for responding by lifting a lever on GO trials, or a 3–5 s timeout if response was on a NOGO trial (2–8 days). We found that adding this gradual training stage with 90% GO trials facilitated learning. (4) Mice were trained at 60% GO trials until learning criterion (defined as >74% correct performance for 2 consecutive days) was reached.

Once subjects learned the detection task with all whiskers intact, the location of the C2 barrel was functionally mapped using intrinsic signal optical imaging. All whiskers except C2 on the mouse’s right side were trimmed. Mice were retrained with a single C2 whisker until >74% performance was reached with 50% GO trials. In most cases, behavioural performance dropped after the initial whisker trimming but recovered over 1–7 days. Trimming was maintained twice a week. Lesions or sham operations were made after the performance of the mice stabilized above the performance criterion. Experimenters were not blind to whether mice were lesioned. Any animals that could still perform well (>60% correct) in the absence of all whiskers were excluded from analysis.

Test of task learning

Experimenters were blind to whether mice were lesioned or sham. For learning experiments, mice were trained as above but with more standardized training periods. Mice recovered from surgery and were habituated to handling by the trainer for 1–2 days. Mice were water-restricted and habituated through a series of pre-training stages. Progression through each step depended on the individual mouse’s weight stabilization (indication of health), or whether rest days (weekends) interrupted training, rather than an explicit behavioural criterion. (1) Freely moving mice were habituated in the light to the behavioural apparatus, where water reward was given for holding down a lever (1–2 days). (2) Mice were head-fixed and continued to hold down the lever to drink (4 ± 2 days, mean and s.d.). (3) Mice were rewarded for holding down the lever and subsequently lifting for >100 ms (4 ± 2 days). All whiskers excluding C2 were trimmed twice a week for the remainder of the learning experiment. We quantified learning time for the following stages: mice were first introduced to the pole with 90% GO trials (~4 days, Extended Data Fig. 7). This stage and successive ones were performed in a light-tight box where no visual cues could be used. Mice were given <48 sessions to reach learning criterion of 74% correct for 2 consecutive sessions. To factor in the different number of GO and NOGO trials, we calculated per cent correct performance as 100 × (Nhit/NGO + NCR/Nnogo)/2 in which the N variables are the numbers of hit, go, correct reject and NOGO trials, respectively.

A total of 29 mice were lesioned before learning. Of these, several mice were excluded from analysis, including 6 mice that performed >60% correct after full whisker trimming; 3 mice that were found to have lesions that did not include the C2 barrel; and 6 mice that had lesions that extended below the cortex, including white matter and striatum.

Quantification of whisker movements and contacts

Whisking was monitored with a high-speed camera (Photonfocus AG, MV1-D1312-100-G2) at 250 fps and 640 × 480 pixels/frame under infrared illumination. Whiskers were automatically traced offline and whisker position (angle) and curvature were obtained using Whisk35,36. Trials in which tracing failed >10% of frames were omitted from analysis.

For each session, mice were given a 5-min warm-up before analysis began, except for quantification of within-session performance (Fig. 3d) for which the entire session was included for analysis. Whisking analysis was restricted to a 200-ms window starting from the first frame in which whisker contact with the pole was possible. This window was chosen to best isolate the whisking associated with the sampling of the object and before the response, after which, whisking tended to increase in association with licking for water reward (Fig. 2g). For whisking amplitude and phase, the azimuthal whisking angle was band-pass filtered (four-pole Butterworth, 4–50 Hz) followed by a Hilbert transform37,38. Instantaneous frequency was calculated from the phase. The setpoint was measured as the midpoint between the whisking envelope defined by the maximum and minimum whisker angles for each whisk cycle.

Whisker contacts were defined using whisker angle and curvature parameters for each session. We first determined the range of angle-curvature values during free whisking in air (NOGO trials). The baseline curvature for each trial (mean change in curvature during 200-ms period before each trial onset) was subtracted to obtain the change in curvature (ΔΚ). Linear regression of the whisker angle and change in curvature was used to find the line of best fit (Extended Data Fig. 3). Upper and lower contact thresholds were set by finding the offset of the lines that encompassed the angle-curvature parameter space for all NOGO trials (1–5 s.d.). Putative contacts were defined as points at which local maxima or minima of ΔΚ were above or below the defined contact thresholds.

Optogenetic modulation of cortical activity

For optogenetic experiments during detection behaviour, the laser was on for 33–50% of trials, which were randomly interleaved with laser-off trials. For laser-on trials, an optical shutter opened at the onset of the trial, before movement of the pole. The pole moved within reach of the whisker field 200–400 ms after the onset of the laser, ensuring photoinactivation before contacts were possible. The laser remained on until after the mouse responded, or for the duration of the trial if no response was made, for a maximum of 1.5 s. Spiking activity during photoinhibition could be efficiently silenced for at least 2 s; all trials were 1.2–1.5 s in duration with a 1-s inter-trial-interval (Extended Data Fig. 1). Exposure to laser was limited to minimize photodamage to tissue. With the protocol described, no physiological or physical damage was detectable. A 593- or 594-nm laser (OEM or Coherent) was used with Emx1–Halo mice. For PV–ChR mice, an optical chopper (Thorlabs, MC2000B) modulated the 4 mW output of a 473-nm laser (OEM) to produce pulses at 40 Hz. Lasers were coupled to a 200-μm diameter, 0.39 NA optic fibre (Thorlabs) via a fibreport, and the diamond-knife cut fibre tip was placed above the optical window and positioned over C2 using the vasculature-referenced intrinsic signal map.

Electrophysiology

For recordings without behaviour, Emx1–Halo mice (n = 4) were habituated to head-fixation. Juxtasomal recordings were made using pipettes filled with artificial cerebral spinal fluid and an Axoclamp 900A amplifier. Airpuff stimuli for each test condition were delivered by opening an air valve for 50 ms during trials ranging from 0.5 to 2 s, and an inter-trial interval of 1.5–3 s for 30–50 trials. Laser-on trials were randomly interleaved for 50% of the trials. Glass pipettes were inserted perpendicular to the cortical surface (~30° from vertical), and the optic fibre was positioned vertically near the pipette entry point, above a thinned skull. To test the effect of photoinhibition at various distances, the optic fibre was positioned 0, 0.5, 1, 1.5 and 2 mm from the original recording site along a thinned and transparent skull (n = 21, 11, 10, 12 and 16, respectively). Regular spiking (RS, putative excitatory) versus fast-spiking (FS, putative inhibitory) cells were categorized based on their spike waveforms as previously described39. Cortical depth was defined as the microdrive depth relative to the pial surface.

For recordings during the behavioural task, a linear silicon array (Cambridge NeuroTech H3), consisting of 64 sites spanning 1,275 μm, was used. Each site was 11 × 15 μm and coated with PEDOT to obtain an impedance of 50–150 kΩ. Signals were band-pass filtered 1–7,500 Hz and sampled at 30 kHz (OpenEphys). Between sessions, the array was withdrawn and the craniotomy sealed with silicone. Spikes were clustered and inspected using Kilosort40 and Phy41.

Cortical lesions

Mice were deeply anaesthetized under isoflurane. A 1–4-mm craniotomy was made and the underlying cortical tissue was aspirated with a sterile blunt-tipped syringe needle connected to a vacuum. Lesions were made by aspirating all cortical layers to encompass, at a minimum, the C2 barrel and the immediately adjacent barrels, and at a maximum, the majority of S1 representing the large whiskers (macrovibrissae) and secondary somatosensory cortex (Extended Data Figs. 4, 5). Sham-operated mice were anaesthetized under the same conditions, and the skull was thinned with a dental drill. Lesioned and sham-operated mice were allowed to recover for 1 or 3 days after surgery before testing. After behavioural testing was complete, mice were perfused and brains extracted for histological analysis. Brains were sectioned tangentially or coronally (100 μm thick) with a vibratome. Lesion diameter was quantified in ImageJ by outlining the lesioned area for each section, quantifying the mean Feret diameter and averaging across all sections. Volume was measured by summing each section’s lesion area multiplied by 100 (the section thickness).

In some cases, lesions extended beyond S1 and into subcortical tissue including the striatum. To objectively score striatal damage, the extent of cortical and subcortical damage was scored by five raters experienced at looking at coronal sections of mouse brains and blind to the behavioural data.

Data analysis

Analyses were done with custom-written scripts in MATLAB. For all figures, statistical significance is denoted as *P < 0.05, **P < 0.01, ***P < 0.001. Differences were not significant (P > 0.05) unless otherwise indicated. Non-normally distributed data (D’Agostino–Pearson test) were reported using medians and interquartile ranges, and normally distributed data with means and s.e.m. Two-sided paired t-tests were used unless otherwise indicated. Based on the mean and s.d. of normal performance levels of trained mice, power analysis indicated that detecting a drop in performance to chance levels with a significance criterion of 0.05 required a minimum sample size of three, which we exceeded in all cases.

Reporting summary

Further information on experimental design is available in the Nature Research Reporting Summary linked to this paper.

Code availability

All computer codes are available from the corresponding author upon reasonable request.