Image copyright SPL Image caption Dog breeds evolved to fill certain roles

The largest family tree of dogs ever assembled shows how canines evolved into more than 150 modern breeds.

Dogs were first selected and bred for their ability to perform tasks such as herding goats or cattle, say scientists.

Later, they were selected for physical features such as their size or colour.

The study also unearths evidence that some dogs are descended from an ancient breed that travelled with the ancestors of Native Americans into the Americas.

Archaeological evidence points to the so-called "New World dog", which apparently crossed with human settlers over a land bridge from Asia.

It had previously been thought that all signs of this ancient breed had been erased as dogs bred in Europe spread around the world.

"We think there is still some signature of New World dog hiding in the genome of some of these American breeds," said co-researcher Heidi Parker of the National Institutes of Health, US.

Modern hairless breeds such as the Peruvian hairless dog and the Mexican hairless dog are likely descended from this ancient dog.

Image copyright Penny Inman Image caption The Mexican hairless dog appears to be ancient in origin

In the study, Dr Parker and colleague Dr Elaine Ostrander studied the genetics of 161 modern dog breeds, and their wild relatives, the wolf and the golden jackal.

They identified 23 clusters (clades) of dog breeds that are all similar to each other.

You can now tell where different dog breeds came from - and the diseases they are prone to, they say.

More stories you might like to read:

DNA clue to how dogs became our friends

'Puppy talk' - why do we use it?

For example, gun dogs all seem to have developed in one place and time - Victorian England.

"All of the spaniels, the pointers, the setters and the retrievers are actually pretty closely-related and they group into one over-arching clade [cluster] of sporting breeds," said Dr Parker.

However, other dogs that appear to be similar - such as herding dogs - are actually quite diverse, suggesting they were bred to fill certain roles many times in history in different places over the course of thousands of years.

The research, published in Cell Reports, has practical applications for animal health.

Scientists believe it will help them find out more about the diseases dogs suffer from, such as epilepsy, diabetes and cancer.

"We now know where various disease mutations or disease alleles come from," said Dr Ostrander.

The dog has the longest history of domestication of any animal.

It is also the only domesticated animal present in human societies on every continent in ancient times.

Follow Helen on Twitter.