Ecology of infectious diseases with contact networks and percolation theory