A deep dive into the toilets of the past has given us new insight into the relationship between humans and the worms that love us.

By extracting DNA from a range of sources, including "archaeologically-defined latrines" used by the Vikings up to 2,500 years ago, researchers have reconstructed the genome of one of the oldest known human parasites.

The findings reveal that the whipworm (Trichuris trichiura) has been living with, and adapting to, humans for at least 55,000 years.

The new information on the biology and behavior of these sneaky little parasites will, the researchers said, help devise methods to prevent its spread.

"In people who are malnourished or have impaired immune systems, whipworm can lead to serious illness," says zoologist Christian Kapel of the University of Copenhagen.

"Our mapping of the whipworm and its genetic development makes it easier to design more effective anti-worm drugs that can be used to prevent the spread of this parasite in the world's poorest regions."

Although the worm is rare now in industrialized parts of the world, it's estimated to infect up to 795 million people globally, according to the CDC, particularly in regions with poor sanitation.

Its eggs are passed in human feces; these can be transmitted by the fecal-oral route, when the contaminated fecal matter gets into soil or water that is then ingested by another host.

Once safely in the intestinal tract of a new host, the egg hatches, and female worms will lay eggs continuously at a rate of up to 20,000 per day once she reaches maturity. They can live up to a year, thus, producing vast numbers of offspring – which are then expelled in feces to continue the cycle.

"The eggs lie in the ground and develop for roughly three months. Once matured, eggs can survive in the wild for even longer, as they wait to be consumed by a new host in whose digestive tract they will then hatch," Kapel explains.

"Their entire life cycle is adapted to survive in soil for as long as possible,"

It is this durability in the soil that allowed the team to sequence ancient DNA found in ancient fossilized human poop. The eggs have a shell of hard chitin, preserving the DNA contained therein, adapted to survive for a long time in the soil environment.

It was eggs, therefore, not the desiccated bodies of mature worms, that the researchers were able to sequence, obtained from the sites of Viking settlements in Viborg and Copenhagen, as well as sites in Latvia and the Netherlands.

A total of 17 different ancient samples were studied under the microscope to isolate the eggs, which were then sieved out of the surrounding poop fossil matrix, and subjected to genetic analysis.

The team also examined contemporary samples from humans around the world, as well as monkeys, to compare against the ancient genomes.

"Unsurprisingly, we can see that the whipworm appears to have spread from Africa to the rest of the world along with humans about 55,000 years ago, following the so-called 'out of Africa' hypothesis on human migration," Kapel says.

The results suggest that the parasite has adapted in ways to work with, rather than against, the human body in order to remain unnoticed, living out its life cycle, and spreading to as many hosts as possible.

It's also possible that, in some cases at least, a mild case of whipworm infection might have a beneficial effect on a healthy host. Studies have shown, for example, that the pig whipworm increases the diversity of healthy gut bacteria, and decreases bacteria associated with poor health in pigs.

But, for a severe infection, the consequences are rather more unpleasant, including dysentery, anemia, and rectal prolapse, and in children can inhibit healthy growth. This new research, the researchers say, may help provide new tools for preventing this.

"During the Viking Age and well into the Middle Ages, one didn't have very sanitary conditions or well-separated cooking and toilet facilities," Kapel says.

"This allowed the whipworm far better opportunities to spread. Today, it is very rare in the industrialized part of the world. Unfortunately, favorable conditions for spreading still exist in less developed regions of the world."

The research has been published in Nature Communications.