Ecology and population structure