How do scientists transfer the specific DNA in Optogenetics?
Well for one, just having a gene doesn't mean you can make it work as intended, and indiscriminately tweaking the genetic material can produce unwanted effects. For example, if I overexpress p53, a common tumor suppressor gene, the cell undergoes apoptosis (1). If I break/delete the same gene, the cell might undergo apoptosis or it might become cancerous. Human development is of course regulated by hundreds of genes at a time, however, so legs on a butterfly is far more complex than just a single gene.

A common approach for inserting genes into a host genome is the lentiviral transfection. Generating a lentiviral vector is detailed here. A similar strategy for transfection using HEK293 for viral production is described in the following paper. I have no knowledge of optogenetics but I tried my best to find a paper in the field that employs the method in practice. In case you have no access to the article, 

Viral Production


  HEK293T cells (ATCC, UK) were cultured in Iscove’s modified Dulbecco’s medium (Sigma-Aldrich, Germany) supplemented with 10% (v/v) FCS (Sigma-Aldrich) and penicillin–streptomycin–glutamine (Sigma-Aldrich) in 5 × 150 mm dishes. After 80% confluency was reached, cell were transfected in serum-free medium with the helper plasmids pRV1, pH21 and pDFΔ6 and pAAV1/2-hSyn-BLINK-IRES-eGFP or pAAV1/2-hSyn-IRES-eGFP at a molar ratio of 1:1 with CaCl2. On the next day, the medium was replaced with serum-containing medium, and 48 h after transfection cells were harvested, pelleted and resuspended in lysis solution (150 mM NaCl, 20 mM Tris, pH 8).....


Culture &amp; Transfection


  Hippocampal neuronal primary cultures were prepared from embryonic day 18–19 (E18– E19) rat hippocampi as previously described43. All the experiments were approved by the Institutional Animal Care and Use Committee of University of Milan and by the Italian Ministry of Health (#326/2015). Neurons were transfected at 7 days in vitro (DIV7) via the calcium-phosphate precipitation method with 4 μg of plasmid DNA for GFP for the experiments assessing the axonal and dendritic distribution of BLINK2 reported in Fig. 2c. Neurons were infected with AAV1/2-hSyn-BLINK2-IRES-eGFP at DIV10 and fixed at DIV12 for the immunocytochemistry assays.


There's more to the method, but in short they transfect the 293 cells with these plasmids that create a functioning virus enclosing their plasmid of interest, and then they harvest the virus and use that to further transfect their neural cells with the gene(s) of interest.