The ecology and evolution of horizontal gene transfer in bacteria