Scattering theory, U(1) anomaly and index theorems for compact and non-compact manifolds