Add the ability to get reference length from sam file header.

Fixed merge bugs where slave_rank used instead of replica_rank.