An outbreak of the hospital superbug MRSA has been brought to an end by UK doctors cracking the bacterium's genetic code.
It led to them finding one member of staff at Rosie Hospital, in Cambridge, who may have unwittingly carried and spread the infection.
They say it is the first time rapid genetic testing has been used to track and then stop an outbreak.
One expert said this would soon become "standard practice" in hospitals.
Doctors were concerned after MRSA was detected in 12 babies during routing screening.
However, current tests could not tell if it was one single outbreak being spread around the unit or if they were separate cases being brought into the hospital. About one in 100 people carry MRSA on their skin without any health problems.
To find out, researchers at the University of Cambridge and the Sanger Institute embarked on more sophisticated version of a paternity test.
They compared the entire genetic code of MRSA bugs from each baby to build a family tree. It showed they were all closely related and part of the same outbreak.
After two months without a case and deep cleaning the ward, another case appeared. Analysing the DNA showed that it was again part of the outbreak and attention turned to a carrier.
Tests on 154 members of staff showed that one was also carrying MRSA, which may have been spread to babies in the unit. They were treated to remove the infection.
"We believe this brought the outbreak to a close," said Dr Julian Parkhill, from the Sanger Institute.
"This is really exciting for us because it gave the hospital the opportunity to intervene.
"We think this is the first case where whole genome sequencing has actually led to a clinical intervention and brought the outbreak to a close."
The study was published in the medical journal Lancet Infectious Diseases.
The cost of working out the entire genetic code of a bacterium has plummeted from millions of pounds to about £50.
The time it takes has also fallen dramatically from months to hours.
Dr Parkhill said it could get even cheaper: "People are talking about the thousand dollar human genome.
"If you can do the human genome for a thousand dollars you can do a bacterial genome for one dollar."
Commenting on the research Prof Ross Fitzgerald, from the Roslin Institute at the University of Edinburgh, told the BBC: "The study clearly highlights the power of whole genome sequencing for resolving the source and the spread of an epidemic of hospital acquired infection such as MRSA.
"It will ultimately, within a small number of years, be standard practice for any hospital outbreak.
"I fully expect this to be rolled out as a standard approach in UK hospitals in the very near future."
Prof Sharon Peacock, from the University of Cambridge, said she wanted to develop a simple system that could be used easily by hospitals.
She said she envisioned a "black box" where the genetic sequence goes in and a simple report that can be used by hospital staff comes out.
"It could, for example, determine the species of the bacterium; it could determine antibiotic susceptibility, and it could provide information about what genes are present that are often associated with poor outcomes in patients."
Sir Mark Walport, director of the Wellcome Trust, said: "This is a dramatic demonstration that medical genomics is no longer a technology of the future - it is a technology of the here and now."