May be it would be easier to map the reads on a reference made of both parental genome, so they compete as template for the alignment. From there, selecting the best alignment is straightforward.
Now if you really have to start from the two bam files, here is a possible strategy:
- Remove all secondary/supplementary alignments but keep unaligned reads in each bam file in such a way that the number of reads in each bam file equal the number of reads sequenced.
- Sort the bam files by read name.
- Compare the mapping quality score (5th field of bam/sam entry) of each entry of one bam file with the corresponding entry on the other one (same line number, and same read name).
- Save the entries with highest quality score into a new sam/bam file.