refactor sam header creation in alignment result

I'm planning to make some changes that want access to the read group
information in the generated sam header, so I pulled the relevant code
out into a function and added some more specific tests about sam header
generation.
trailing whitespace

DO NOT WANT