Cells and structure

I've only taken highschool biology and I'm actually a computer science major, but I've had an idea rolling around in my head recently and I think it might be better realized if I approach the problem from a biological standpoint. I'm sort of stuck at a particular problem that I can't seem to find a good answer to.

Crudely I would state the problem like this: How does a particular cell replicate to form a particular structure, such as a bone cell replicating to to form a rib, and not some other structure consisting of the same type of cells, such as a bone cell replicating to form a phemur?

I don't think it has anything to do with DNA or anything on the cellular level but if not directly I feel as if there should be some indirect way in which this happens from circumstances on the cellular level.

If somebody could point me in the right direction it would be greatly appreciated.

It has a lot to do with the location of cells relative to other cells. This turns on or off certain genes involved in cell differentiation.

All the hoo-hah about stem cells kind of skips over what they do:
depending on where a stem cell is located, and what external influences it experiences, it can become pretty much any type of cell. As a (for now) farfetched example: cure Parkinson's Disease by injecting stem cells into damaged areas of the medulla oblongata.