IT is a ferocious beast that has long wreaked misery across Scotland, emerging as night falls to feast on human blood: the dreaded midge.

But scientists may now be one step closer to finding out why this tiny biting creature prefers the taste of some of us over others – and in doing so could have uncovered a natural repellent.

A new BBC Scotland documentary, The Secret Life of Midges, which airs on Monday will lay bare the intriguing physiology of what makes the midge tick.

It is presented by Dr James Logan, a specialist in parasites and entomology at the London School of Hygiene and Tropical Medicine, who describes himself as "genuinely fascinated by midges".

Earlier this summer, he enlisted the help of brave campers, shinty players and Highland villagers to run a gauntlet of midges and see who the pesky bloodsuckers did – and didn't – flock to.

The big midge experiment was run on four occasions with a total of 23 subjects in varying conditions.

In each group, there was always at least one participant who attracted fewer midges – typically around a fifth less.

Past research undertaken by Dr Logan indicated that fruity smelling compounds found in sweat, known as ketones, could be a factor.

The Scottish-born academic is now certain this is the key to unlocking the secret of a repellent.

"We have proven in the lab that the reason is to do with smell," he said. "By isolating the chemicals as part of our body odour, we have been able to identify what it is about people who don't get bitten: they smell different and produce these extra chemicals that are repellent to midges."

Dr Logan has also discovered that this is a genetic trait passed on between generations.

"It is same level of heritability as things like IQ, height and eye colour," he said. "The next phase of the study will be to identify the genes that control how attractive you are [to midges]. What we are looking at specifically is which gene is responsible for making you unattractive.

"If we can find that gene, we could possibly be able to develop a pill that makes us naturally repellent to midges and other insects."

Dr Logan believes that such a product could be available within the next "three to four years".

"We are in the position now where we have got the repellent chemicals and are producing products based on those which should be available for people to use," he said.

Weighing just one 8000th of a gram, midges have a mighty reputation for such a miniscule insect.

They breed in vast numbers across 25 per cent of Scotland's land mass. As many as half a million midges can hatch from a two square metre patch of suitably wet, peaty soil.

The programme will also reveal the surprising influence that midges have had on the work of Argyll-based landscape artist John Lowrie Morrison.

Mr Morrison – known as Jolomo – said that he had previously resorted to smoking cigars while painting outdoors in a bid to ward them off.

When this failed, he was driven indoors – a change in working practice which the artist credits with enhancing his work as an expressive painter.

Mr Morrison admitted that he is even rather fond of midges. "I wouldn't like to see midges being destroyed off the planet just for the sake of our comfort," he said. "They are beautiful wee things."

The Secret Life of Midges, BBC One Scotland, Monday, at 9pm