This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Merge two BAM files with different but overlapping reference sequences?

Situation:

refA.fasta   one reference sequence
refB.fasta   a different reference sequence
A.bam        one type of reads mapped against the first reference
B.bam        another type of reads mapped against the 2nd ref

Some time after these are constructed one discovers that the sequences in refA and refB overlap and can be merged to refC, with one or at most two cut and splice operations. For the sake of a specific example, let's say that refA is 10kb long, refB is 12kb long, and base 1 of refA is the same as base 1000 of refB, with refA in the opposite orientation (because it will be, half the time) and that there are no base changes in the shared region.

refC.fasta can be constructed with any number of tools.

How though, does one merge the bam files? It would seem to require the application of "invert" and "offset" operators to one of the bam files, and only then the use of the existing "merge". However neither "invert" nor "offset" seem to exist in samtools, notably, they are not in "view" which is where I would have put them.

Does some other piece of software have this option?

assembly

You would be better off by 1) first get the fastq from individual bams, say A.fastq and B.fastq 2) merge and align these fastq to the new reference refC.fasta

1 answer

The simplest solution, as Santosh Anand quite rightly pointed out, is to remap them to the same reference.

If you really don't want to do that, then I would recommend using CrossMap to convert the BAM file to the same coordinate system. If the conversion between the genomes is really as simple as you're saying then you could make the liftOver file by hand.

CrossMap looks like it should do the trick. Thanks.

If this answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.

Log in to answer this question.