It was a selfish choice but since a dozen of people who where immune died for a cure (audio files) in vain it could be deemed the right choice. There was no guarantee Ellie could have helped in creating a cure, I would say the chance that she would die in vain was rather big. Besides we wouldn't have a the last of us part 2 so by definition this was the right choice.
Please excuse my (probally) poor grammar