The viruses themselves are the prototypical genes that move horizontally. The bacteria use their control mostly to resist these “new genes”, but sometimes they can’t keep out the horizontal genes of the virus, and then the bacteria spends non-trivial energy generating viral particles that can invade other bacteria, and so on.
The bacterial genes that jump from one vertical linage to another (that make bacteria phylogenetic tree building a bit wonky) are sometimes carried by viruses. Incidental bacterial genes get packaged in viral capsids by accident, then those viral particles get into a bacteria and somehow fail to exploit the host optimally and the host has many descendants anyway. You are right that this is somewhat random/accidental. Neither viruses nor bacteria seem to generally “intend” it in coherent ways.
Sometimes bacteria have a second little genome called a plasmid, and these often contain genes for the construction of a tube that injects neighboring bacteria with the little secondary genome (but not the main genome). These “conjugative plasmids” are engaged in non-random horizontal gene transmission. Conjugative plasmids tend to be more aligned than viral prophages (that lurk in the host genome for several generations) which are more aligned than pure lytic viruses.
The more horizontal things are worse for the bacteria’s genetic interests in very simple and concrete ways, related to the normal operation of the genes following their normal “selfish gene” lifecycles.
The viruses themselves are the prototypical genes that move horizontally. The bacteria use their control mostly to resist these “new genes”, but sometimes they can’t keep out the horizontal genes of the virus, and then the bacteria spends non-trivial energy generating viral particles that can invade other bacteria, and so on.
The bacterial genes that jump from one vertical linage to another (that make bacteria phylogenetic tree building a bit wonky) are sometimes carried by viruses. Incidental bacterial genes get packaged in viral capsids by accident, then those viral particles get into a bacteria and somehow fail to exploit the host optimally and the host has many descendants anyway. You are right that this is somewhat random/accidental. Neither viruses nor bacteria seem to generally “intend” it in coherent ways.
Sometimes bacteria have a second little genome called a plasmid, and these often contain genes for the construction of a tube that injects neighboring bacteria with the little secondary genome (but not the main genome). These “conjugative plasmids” are engaged in non-random horizontal gene transmission. Conjugative plasmids tend to be more aligned than viral prophages (that lurk in the host genome for several generations) which are more aligned than pure lytic viruses.
The more horizontal things are worse for the bacteria’s genetic interests in very simple and concrete ways, related to the normal operation of the genes following their normal “selfish gene” lifecycles.