The origin and evolution of nitrogen fixation genes