We propose molecular models for homologous DNA recombination events that are guided by either double-stranded RNA (dsRNA) or single-stranded RNA (ssRNA) templates. The models are applied to explain DNA rearrangements in some groups of ciliates, such as Stylonychia or Oxytricha, where extensive gene rearrangement occurs during differentiation of a somatic macronucleus from a germline micronucleus. We describe a model for RNA template guided DNA recombination, such that the template serves as a catalyst that remains unchanged after DNA recombination. This recombination can be seen as topological braiding of the DNA, with the template-guided alignment proceeding through DNA branch migration. We show that a virtual knot diagram can provide a physical representation of the DNA at the time of recombination. Schematically, the braiding process can be represented as a crossing in the virtual knot diagram. The homologous recombination corresponds to removal of the crossings in the knot diagram (called smoothing). We show that if all recombinations are performed at the same time (i.e., simultaneous smoothings of the crossings) then one of the resulting DNA molecules will always contain all of the gene segments in their correct, linear order, which produces the mature DNA sequence.