Question: bam file merge
1
gravatar for genomics Newbie
20 months ago by
genomics Newbie20 wrote:

Hello. I have numerous bam files which I need to merge into a single bam file. How do I know whether I need to first index and sort the bam files?

bam merge • 746 views
ADD COMMENTlink modified 20 months ago by h.mon29k • written 20 months ago by genomics Newbie20

In http://www.htslib.org/doc/samtools-1.2.html, it says,

-h is specified the @SQ headers of input files will be merged into the specified header, otherwise they will be merged into a composite header created from the input headers. If in the process of merging @SQ lines for coordinate sorted input files, a conflict arises as to the order (for example input1.bam has @SQ for a,b,c and input2.bam has b,a,c) then the resulting output file will need to be re-sorted back into coordinate order.

ADD REPLYlink modified 20 months ago • written 20 months ago by tiago2112871.1k

Dear genomics Newbie, Hi

Please have a look at To sort or not to Sort?.

I guess you can first use "samtools merge" and then "samtools sort -o".

ADD REPLYlink modified 20 months ago • written 20 months ago by Farbod3.3k
3
gravatar for h.mon
20 months ago by
h.mon29k
Brazil
h.mon29k wrote:

You should sort your files, as samtools merge expects sorted bam files, either by position (default) or by name (samtools merge -n). You can check if you bam are already sorted by looking at the SO flag:

samtools view -H file.bam | grep "SO:"

@HD VN:1.0 SO:coordinate

ADD COMMENTlink written 20 months ago by h.mon29k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 656 users visited in the last hour