Thermal swing adsorption process with purification