Some magical abilities are determined by genes rather than by practice and knowledge.
For example, Parseltongue is granted simply by having the right genes, not by learning it. (Harry Potter knew Parseltongue because of his connection to Voldemort, and he lost the ability after Voldemort's connection to him was destroyed.)
Knowing Parseltongue isn’t quite the same as learning Spanish. Firstly, you don’t so much learn it, as just innately know it. The language is incredibly rare, as Harry is told countless times. The only place it isn’t rare, is within the bloodline of Salazar Slytherin himself – and as such, is usually hereditary.
The author herself as said that magical abilities are based on genetics.
Rowling: "Muggle-borns will have a witch or wizard somewhere on their family tree, in some cases many, many generations back. The gene resurfaces in some unexpected places."
Could a Muggle get a gene transplant at a young age and as the gene expressed itself as the child grew up, the person would become magical?
Note: The quotes above come from Reddit.