One question seemed to hang in the air more than any other when scientists first turned the powerful techniques of modern genetics on the fragile and damaged remains of ancient humans: did we or didn't we? Have sex with them, that is.

The answer came after years of painstaking work, when material extracted from the leg of a Neanderthal and the fingerbone of a Denisovan, an apparent sister species, yielded readable DNA. It turned out that most of us have some of their genes. The Neanderthals contributed up to 4% of modern Eurasian genomes, while the Denisovans contributed roughly 4-6% of modern Melanesian genomes. That doesn't happen by holding hands.

And so the scene was set. Hundreds of thousands of years ago, early humans in Africa split into several groups, among them Homo sapiens, Neanderthals and their apparent sister species, the Denisovans. The Neanderthals headed for West Asia and Europe, the Denisovans to East Asia. Our ancestors left Africa much later, and arrived in Eurasia where the others had set up home. Cue amorous encounters, and surely a fair amount of less than amorous contact.

But the question of whether our ancestors mated with these other human-like groups was always just the starting point for a line of inquiry. With interbreeding now well-established the intriguing question is, what came of it? How did our ancestors' antics shape the people we are today?

A glimpse of the legacy of those ancient encounters is revealed in a study reported today in the US journal, Science. An international team of scientists, led by Stanford University, scoured the Neanderthal and Denisovan genomes for gene variants that are central to the immune system. These genes belong to a group known as the HLA class I genes, which govern the body's ability to recognise and destroy dangerous pathogens.

By comparing the HLA genes of modern human populations with those from Denisovans and Neanderthals, the scientists identified a handful that could be traced back to ancient sexual encounters between the groups. One variant, known as HLA-B*73, likely arose in modern humans after cross-breeding with Denisovans. The variant is most common in West Asian populations, the region where the mating probably happened.

The Neanderthals contributed a string of HLA gene variants, or alleles, to the modern Eurasian population's gene pool, the study found.

There was good reason for Neanderthal and Denisovan immune system genes to have spread through the populations of modern humans who encountered them. Both Neanderthals and Denisovans had established themselves long before modern humans arrived. Their immune systems had adapted to the threats of the local environment. When those genes crossed into modern humans, they conveyed an advantage. Natural selection took care of the rest.

But the scientists think there was a downside. Inheriting Denisovan or Neanderthal immunity genes will have helped modern humans to fight the diseases of the day, but beyond the age of reproductive maturity they might have a more harmful effect, turning our immune systems on ourselves.

Paul Norman, a co-author on the paper, put it like this: "There's enormous genetic variation in people's immune systems and that can control how different people fight different diseases. This could go some way to explaining why some people are better at fighting some infections than others, but we think it also goes some way to explaining why some people are susceptible to autoimmune diseases."

Autoimmune diseases are conditions that arise when the immune system turns its firepower on the body, usually when it mistakenly identifies the body's tissues as foreign, and so potentially dangerous.

"The vast majority of autoimmune diseases have been shown by genome-wide association studies to be associated with particular HLA alleles and we find a couple of those in Denisovans," Norman added. "So it looks to me like modern humans have acquired these alleles, but we weren't kind of prepared for them, we hadn't grown up with them, and in some circumstances, they can start to attack us as well as the viruses and other pathogens."

The group is now investigating a gene variant called HLA-B51, which came from cross-breeding with Neanderthals and has already been linked to Behcet's disease, a rare and chronic inflammatory condition.

How else might immune genes inherited from Neanderthals and Denisovans affect the health of modern humans? The question is intriguing and will differ from population to population. Here, at least, is a worthy successor to the question of "did we or didn't we?"