Women at risk of giving birth prematurely could be identified by looking at bugs living in their reproductive tract, a study suggests.
Subtle changes to vaginal bacteria were found to be strongly linked to pre-term birth after less than 37 weeks of pregnancy.
The findings show that a shift away from the usual healthy "mix" of bacteria tended to coincide with waters breaking early.
It also increased the risk of harm to both mother and baby, including a greater chance of sepsis - a potentially lethal "shock" response to infection - for newborns.
Lead scientist Dr David MacIntyre, from Imperial College London, said: "This study is one of the first to show that around almost a half of pregnant women may have an unbalanced vaginal microbiota before premature rupture, providing further evidence of the role of bacteria in some cases of premature births.
"Crucially, our findings identify two different groups of women with premature rupture - one group in which targeted antibiotics may be beneficial and the other in which this same treatment may actually be detrimental."
The team collected swab samples from 250 pregnant women with and without risk factors for giving birth prematurely.
Of this group, 27 delivered their babies early.
Other samples were taken from a different smaller group of 87 women seen at hospital after premature membrane rupture.
Previous research had shown that during pregnancy the bacteria that colonise the vagina become less diverse and are dominated by Lactobacillus species.
The study, published in the journal BMC Medicine, revealed that breaking waters early was associated with falling levels of Lactobacillus and increases in other types of bacteria.
While standard antibiotic treatment helped reduce infection in most women whose waters broke early, for some it proved harmful.
This could be due to the drugs wiping out "good bacteria" and letting more dangerous bugs take their place, the scientists believe.
Co-author Dr Richard Brown, also from Imperial College, said: "Our results suggest that a more personalised approach targeting only those women likely to benefit from antibiotics may prove more beneficial than the current 'one treatment fits all' approach."
Professor Siobhan Quenby, from the Royal College of Obstetricians and Gynaecologists, said: "More research is needed to determine the link between vaginal bacteria and preterm birth, and if so, changes may be made to the recommended treatment of preterm pre-labour rupture of membranes which is currently the same for all women.
"There is now the exciting possibility of a future where women are tested and given the best antibiotic for them as an individual."