It's a scenario worthy of any zombie movie: A virus infects a gypsy moth caterpillar and takes over its brain, putting it on a suicide mission. First, it's compelled to climb up high in the trees, where it dies in the midday sun. Then its body liquefies, and virus particles are spread downward with the first rain.

The behavior benefits the virus at the expense of the caterpillar.

Horror films borrowed the zombie concept from Haitian and African culture, where the term refers to a reanimated body that can be forced to do the bidding of a sorcerer. Nature shows the concept is not so far-fetched (though the victims aren't technically dead). The sorcerers can be viruses, fungi, or worms, and they don't need to use magic. They use evolution.

Among the most famous cases are those of "zombie ants," which get infected by a fungus that compels them to go where conditions are optimal to grow more fungus. And in corn earworm moths, a sexually transmitted virus can render the infected females not just more active in attracting males, but also irresistibly sexy.

In a new paper published Friday in Science, biologists showed how they pinpointed a gene that does the sorcerer's job in the gypsy moth virus, called baculovirus. The gene, egt, interferes with the moth's instinctive molting behavior, said Pennsylvania State University entomologist Kelli Hoover, the lead author.

Normally the caterpillars climb trees to molt, she said, and then come back down so they can hide in tree bark during the day.

But if infected with baculovirus, the caterpillars stay up in the trees, and instead of molting, they keep eating. "That way the virus is able to convert more of the caterpillar mass into virus," she said.

Then they die up high, maximizing the chance for the virus to spread through the forest canopy.

To find which viral gene was the real zombie-master, she used captive caterpillars in containers; their climbs to the container top were a proxy for ascension through trees.

Indeed, infection made them go to the top of their containers and die.

Then she created several strains of the virus with various genes eliminated, and found that when she knocked out this egt gene, the virus lost its ability to induce the zombie climb. She said hormones control the caterpillar's molting behavior and the gene appears to be interfering with the actions of that hormone.

"We've shown a gene inside the virus is causing the behavior in an animal," said David Hughes, another Penn State biologist who was part of the collaboration and had done previous work in zombie ants. Hughes says the idea reinforces a concept called "extended phenotype" introduced by British biologist Richard Dawkins in the 1980s to describe ways an animal's genes are connected to more than its own body.

Dawkins' famous book, The Selfish Gene, already popularized the idea that our genes evolved to make copies of themselves, not to work for us. They don't help us unless it benefits them - and we do their bidding like puppets, or zombies.

Examined as an example of extended phenotype, the behavior of zombie ants can be seen as an extension of a fungus that infects them. Evolution favors genes in the fungus that are good at making more copies of themselves, and they've found a way to do this by controlling ants.

Infected ants act in a very specific pattern, Hughes said. They wait until high noon, then climb to a certain height, clamp onto the underside of certain leaves, and die in an orientation that's ideal for the fungus, which grows out of their heads.

Another ant parasite, the brain worm, induces ants to clamp hard onto blades of grass, where they're consumed by sheep or other grazing animals, and where the worm has the best chance to proliferate.

Suicide is often the end result. A type of worm that infects crickets induces them to commit suicidal plunges into ponds or swimming pools, where the worms can find each other and mate.

Sometimes the invaders manipulate sexual behavior to their own ends, said entomologist John Burand of the University of Massachusetts, Amherst. He studies a sexually transmitted virus that infects corn earworm moths, transforming females into infertile but sexually irresistible zombies, which then spread infection to unsuspecting smitten males.

The females attract males through a pheromone, Burand said, and in experiments infected females were found to be sending out five times as much as uninfected ones. The experiments also showed that males chose infected females twice as often as their healthy counterparts.

In the normal mating scenario, the male leaves behind not only his sperm but a protein that causes the female to stop wafting out her scent, so she mates only once per night.

When she's infected, Burand said, the male chastity-inducing protein stops working, and instead of mating with one male per night, a female will mate with about 12. But since the virus renders her infertile, the only organism to benefit from her newfound promiscuity is the virus.

Burand says there are more familiar versions of this phenomenon in mammals, including humans. Think of a cold that makes you sneeze out cold particles so they can get to others. Or rabies making dogs become aggressive and transmit the infection through biting.

These insect cases are more dramatic, and they could have important practical applications, since gypsy moths and corn earworms are formidable pests. It's hard to get funding for such work, Burand said, because people fear the potential effects of spraying crops with viruses.

Still, it can't hurt to understand the natural enemies of our natural enemies. And all these cases show that while natural selection can be cruel, it's also amazingly creative. For insects, at least, it can lead to a tale that crosses Night of the Living Dead with Sex and the City.