The interplay between the bacterial capsule and mobile genetic elements determines direction and intensity of gene flux in Klebsiella pneumoniae.