Ever feel tickled as a dog approached you -- tail wagging, friendly face -- only to realize he was after that half-sandwich you had stashed in your bag? It turns out that food may also have been the original lure as dogs first became domesticated.

A detailed analysis of the dog genome has linked widespread dog domestication with the emergence of agriculture. Dogs were likely attracted to humans -- and our food -- as opposed to humans bringing dogs to settlements.

NEWS: Prehistoric Dog Lived, Died Among Humans

The genetic clues, outlined in the latest issue of the journal Nature, reveal how dogs adapted to a starch-rich diet, possibly around 12,000 years ago.

"Our findings show that it was crucial to early dogs to be able to thrive on a diet rich in starch," lead author Erik Axelsson told Discovery News. "That indicates that dog domestication may be linked to the development of agriculture. It is possible that dogs may have been domesticated independently at locations where agriculture developed early, such as the Fertile Crescent and China."

Axelsson, who works in Uppsala University's Science for Life Laboratory, and his team made the determination after comparing DNA from 60 dogs representing 14 diverse breeds with DNA from 12 wolves of worldwide distribution.

PHOTOS: Amazing Animal Friendships

While wolves have no genomic signature associated with starch consumption, dogs possess at least 10 genes that mutated to provide functional support for improved starch digestion. Wolves can digest starch, but the mutations allow dogs to do this much more efficiently.

"It is possible that waste dumps near early human settlements supplied early dogs with a substantial fraction of their nutritional needs," Axelsson explained. "If so, they would have been eating leftovers of the food we were eating. That food might have included roots, cereals and food made from cereals, such as bread and porridge, in addition to some meat and bone marrow from discarded bones."

A detailed analysis of the dog genome has linked widespread dog domestication with the emergence of agriculture.Getty Images

Solidifying the link between humans and dogs, our species also looks to have evolved adaptations for a starchy diet at about the same time.

Dog DNA additionally reveals an early shift in brain function, likely tied to behavioral changes associated with living around humans. Since all dogs descend from one species, the grey wolf, (with some breeding with other closely related canines) it's possible that natural selection favored certain types of wolves.

"Being an efficient scavenger included being less shy so as to not waste energy on running away frequently," Axelsson said.

NEWS: Wolves Know Based on Looks Where Something’s Hiding

Natural selection therefore already started the process of separating wild wolves from their settlement-scavenging counterparts before direct human domestication of dogs began.

The precise moment when dogs first evolved from wolves remains in question, however.

Susan Crockford, a researcher at Pacific Identifications Inc. and author of the book "Rhythms of Life," believes that dogs were domesticated by at least 33,000 years ago, but these canines did not generate descendants that survived past the Ice Age.

She told Discovery News that the "right wolf/human conditions suitable for getting domestication started were present at least 33,000 years ago. However, such conditions would have had to be present continuously -- stable -- for many wolf generations, perhaps 20 over about 40 years for the domestication process to generate a true dog."

The 33,000-year date remains controversial, with some researchers saying that supposed dog remains dated to that time might just reflect natural variation in wolf morphology. Bones buried in Israel and dated to around 12,000 years ago "are generally considered reliable as dog remains," Axelsson said.

NEWS: Cats, Dogs Are Good For You

He added that research on the dog genome could benefit human health in the future.

"Dogs and humans share the same environment," he explained. "We eat similar food and we get similar diseases. This, together with our finding that humans and dogs have adapted to a similar environment, makes the dog an excellent model for understanding the genetic causes of human diseases."