A few tiny flies have set up home in my kitchen. Some eggs must have arrived with a batch of bananas, and now it seems they've settled in and are reproducing. I'm not too worried: there's not enough of these fruit flies to call it an infestation, and I'm actually quite fond of these diminutive insects.

In A-level biology, they were like our pets. In practical classes, we learned about genetics by breeding together different strains of fruit flies. Some with long wings; some with short wings. Fruit flies with white eyes and fruit flies with red eyes. Some had brown bodies while others were yellow. There were different ratios of features in each generation.

Fruit flies are famous because of their contribution to genetics. Right at the beginning of the 20th century, an American biologist called Thomas Hunt Morgan grew frustrated with trying to understand how frog embryos developed, and he turned to studying inheritance instead, using the humble fruit fly. He produced mutant flies and recorded the patterns of mutations in generation after generation of offspring. Decades before the structure of DNA was elucidated by Watson and Crick, Morgan's work proved that chromosomes were involved in heredity. His breakthrough earned him a Nobel prize in 1933, and the future of the fruit fly in the genetics lab was secured.

In the 1970s, geneticists began to sequence genes, laboriously at first, then with increasing speed as more of the process was automated. I've filmed in DNA sequencing labs on several occasions and the producers have always been dismayed at how visually dull the process is: the labs are full of white boxes sitting on benches, and the magic of sequencing goes on inside them, hidden away and unaided by human hand.

When its genes were sequenced, the fruit fly revealed a truly astounding secret. A particular group of mutant flies had always intrigued geneticists. In these flies, segments of abdomen were swapped for thoracic segments, or the fly possessed two sets of wings, or had a leg growing out of its head where you'd normally expect an antenna. Geneticists homed in on the mutations in DNA which were producing these bizarre, mutant flies – and they discovered genes which controlled the pattern of segments in the normal fly embryo. Whereas most genes seem to be scattered about fairly randomly in the genome, these Hox genes were lined up on a single chromosome, in the same order as the order of the body segments in the fly.

But the real surprise of Hox genes is that they don't just control pattern generation in the fruit fly embryo. They're in the genomes of every animal with a segmented body. This means that Hox genes are very ancient – the last common ancestor of vertebrates and invertebrates lived around 800m years ago. Fruit flies are very, very distant evolutionary cousins, but the basic pattern of your body was also dictated by Hox genes, when you were an embryo.

Earlier this year, I was lucky enough to meet one of the scientists – the Swiss developmental biologist, Denis Duboule – who, back in the 1980s, found Hox genes neatly lined up in vertebrate genomes, just as they are in fruit flies.

His office sits on a corner of a modest tower block, part of Geneva University. The view through the panoramic windows takes in Geneva, framed by a large snow-capped bluff in one direction. The landscape of low-rise buildings (kept low by popular constraint) is interrupted by the brash excrescence of the glass-facaded television tower.

Duboule had spent decades studying Hox genes, and the way they generated the pattern of segments in an animal: from head to tail, with more genes being switched on in each successive segment. Duboule had recently moved on from studying fruit flies and mice to looking at Hox genes in snakes. He removed a female python from a glass tank in the corner of the office. She was beautiful: sleek and long – perhaps 70cm. She had many more vertebrae than I did – but, astoundingly, the same number of Hox genes as me: 39. Duboule and his colleagues had peered inside the snake genome and discovered the tweaks to genetic signals which made this possible.

"The signal for the end of the body is delayed," explained Duboule, "so she makes segment after segment – some 250 of them – before eventually, the Hox genes say "stop" and then all that is left to do is make a tail."

Duboule was looking at that television tower again. To his eyes, it was like a snake standing on its head. The Hox genes were the architects that had designed it, segment by segment, storey by storey. But there's still a huge amount of work to do, in order to understand how the programmes written in animals' genomes lead to the formation of beautiful, complex, intricately patterned bodies.

Thomas Hunt Morgan, who turned from embryology to studying inheritance, would surely have been delighted to know that his model organism of choice, the fruit fly, would have such a huge impact on the field of genetics. And not only that: the fruit fly would help to solve the riddle that had so frustrated him, illuminating the links between genes and embryology.

Just as I finish writing this article – no word of a lie – there's a little, yellow-bodied fruit fly walking around on the desk in front of my keyboard. I'm peering closely at him, thinking about those Hox genes which patterned both our bodies, and our 800-million-year-old ancestor. He's quite a sweet little cousin.

Perhaps this is an infestation after all.

• This article was amended on 18 August 2013 as the original headline – Fruit flies: our ancestors of 800m years – was inaccurate