If your babies are in danger of being usurped by grisly body-snatchers, there’s only one thing for it—ply them with booze as soon as possible.

Last year, Todd Schlenke from Emory University in Atlanta showed that the fruit fly Drosophila melanogaster uses alcohol as medicinefruit fly Drosophila melanogaster uses alcohol as medicinefruit fly Drosophila melanogaster uses alcohol as medicine. Like many insects, these flies are targeted by parasitic wasps that lay eggs in their bodies. To stop the newly hatched wasps from devouring them alive, the fly larvae consume alcohol at toxic levels. This kills many of the wasp grubs and causes crippling deformities in the survivors. But the flies, which live in a naturally boozy world fermenting fruit, have evolved to handle their drink. They suffer few side effects from their unusual medicine.

But the flies don’t just use alcohol as a treatment. Schlenke’s team has now shown that they can use it as a sort of vaccine. At the mere sight of a parasitic wasp, females will lay their eggs on alcohol-soaked food, giving the hatchlings an immediate source of anti-wasp protection.

Schlenke’s student Balint Kacsoh offered female flies two plates of food—one that was 6 percent alcohol, and another that was alcohol-free. The females chose the boozy plate 40 percent of the time if they were left alone, but 90 percent of the time if there were female Leptopilina heterotoma wasps in the cage too. And 6 percent alcohol? That’ll do, but the females opt for stronger brews if those are available. They’ll lay eggs on food that’s 12-15 percent—the highest concentrations found in nature.

The females’ choices saved the lives of their baby maggots. Normally, 90 percent of the larvae make it to adulthood. With body-snatching wasps around, that proportion falls to a measly 10 percent. But it rises back to 50 percent if the larvae were born on alcoholic food, probably because they’re better at curing their infections and less likely to become infected in the first place.

The flies do not head towards alcohol at the sight of just any wasp. They can tell the difference between females, which could impregnate their young, and males, which cannot. If they are housed with males, they don’t switch to alcoholic food. And their penchant for alcoholic nurseries only kicks in if they see wasps that infect fly larvae, and not those that infect pupae. After all, larvae will typically move away from the place where they hatch. By the time they start to pupate, their mother’s choice of hatching site will have little bearing on whether they fall prey to wasps.

That’s quite spectacular. The fly carries a mental image of a dangerous wasp that’s specific enough to tell females from males, and to ignore irrelevant species while reacting to diverse range of dangerous ones. This all depends on vision. The team found that blind mutant insects never made the switch to alcoholic sites, but mutants that lacked a normal sense of smell still did so.

Most people would stop here, but Schlenke’s team snowballed ahead and pieced together what happens in the brains of the females. These experiments showed that the insects’ attitudes to alcohol are intimately connected with their vision and memory, with the same molecules connecting these seemingly disparate mental traits.

For example, when flies see a dangerous wasp, they experience falling levels of a protein called NPF, in a part of their brains involved in recognising patterns. But a loss of NPF also boosts a fly’s tolerance and preference for alcohol. This molecule links the sight of a threat to a defensive behaviour. If the team artificially loaded the flies’ brains with more NPF, they never made the switch to alcoholic nurseries. If the team depleted NPF entirely, the flies preferred to lay on alcoholic patches even if there were no wasps around.

Another protein called Adf1, which is involved in long-term memory, controls the flies’ ability to remember their wasp foes days after they first see them. Without Adf1, the flies will still make the switch to alcohol when they see wasps—it’s an instinct they’re born with—but their memories fade over time. But Adf1 also controls the gene that’s responsible for breaking down alcohol. It allows the insect to both remember dangers that they can beat through booze, and to tolerate that booze in the first place.

The tolerance is important. High levels of alcohol would kill off a lot of developing insects, but D.melanogaster can resist its negative effects enough to reap its benefits. When Schlenke’s team tested six closely related species of Drosophila flies, they found that only three can tolerate high alcohol concentrations. And only this trio uses alcohol to vaccinate their young against wasps. Throughout the history of these insects, the ability to resist alcohol and to use it as medicine have evolved hand-in-hand many times over.

Reference: Kacsoh, Lynch, Mortimer & Schlenke. 2013. Fruit Flies Medicate Offspring After Seeing Parasites. Science http://dx.doi.org/10.1126/science.1229625