Mechanism of bidirectional thermotaxis in Escherichia coli