About 1 Million BC, the First Host of Celestials, enormous humanoid aliens who possess vast cosmic power, arrived on Earth to explore the planet and to perform genetic experiments on human beings. They were greeted by the Elder God Gaea, who escorted them to the valley where the tribe of Homo erectus lived. The Serpent Men approached the Celestials, but were driven away by the Celestial Arishem the Judge. Gathering up a handful of the humans, the Celestial Gammenon brought them back to the Celestials' ship.
The Celestial Ziran the Tester analyzed the humans, then began his experiments. He created the Deviants, a sub-species of man who were genetically unstable, so that the Celestials could determine mankind's adaptability.
Nezzar the Calculator then experimented and created the Eternals, who were evolutionary accelerated, given extended life spans, and given the ability to channel and manipulate limited quantities of cosmic energy. The Eternals were created to test mankind's durability and longevity.
To further test the versatility of human genes, the Celestial Oneg the Prober implanted a dormant DNA complex in other specimens of mainstream humanity which would one day result in benevolent mutations. Completing their experiments, the Celestials released their test subjects and left Earth. (Uncanny X-Men Annual #13, What If? Vol. 1 #23)
The Celestials would return several more times to check on their experiments.
Recent speculations hold that because the X-Factor gene is only one type of gene, mutant powers are not necessarily genetically encoded. Rather, they are all forms of energy-manipulation which lock into a particular type of ability upon manifestation.
Therefore, the environment and the thoughts or psychological state of the mutant at the time of manifestation may have a direct and formative impact on what type of power will be developed.
In addition, the sources of energy readily available at the time of manifestation become necessary to the mutant for activation in subsequent uses of the power.
The new Earth X LS seems to bear this point out. The X-Factor is what Earth X calls the "Celestial Seed," planted by the Celestials to allow mankind to evolve to higher and higher levels. Everyone one has it, but only mutants have the gene activated naturally. However, it seems that even when humans mutated via Plague X, their powers often conformed to their psychological state at the time, or matched their alter egos.