This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Having trouble with samtools cat

I'm trying to use samtools cat to merge a bunch of smaller bam files. I need them unsorted so I can't use samtools merge. I used samtools view -h 1_R1.bam > header.bam to get the header file it requires. Then I ran samtools cat -h header.bam -o catR1.bam -b 1_R1.bam -b 2_R1.bam. However, it doesn't seem to like my header file because it gives me an error

Failed to open file @SQ SN:R=9:L2_5_GA::chrI:539055-539154() LN:99 samtools cat: failed to open file '@SQ SN:R=9:L2_5_GA::chrI:539055-539154() LN:99': No such file or directory

Which is the first line in the header file. The first few lines of my header file look like this

@SQ SN:R=9:L2_5_GA::chrI:539055-539154() LN:99
@SQ SN:R=47:Helitron_1_GA::chrI:537338-537433() LN:95
@SQ SN:R=47:Helitron_1_GA::chrI:537344-537428() LN:84
@SQ SN:R=52:REX1_1_GA::chrI:536673-536882() LN:209
@SQ SN:R=47:Helitron_1_GA::chrI:534938-534978() LN:40
@SQ SN:R=122:L2_1_GA::chrI:534773-534936() LN:163
@SQ SN:R=2229:L2_1_GA::chrI:534633-534768() LN:135
@SQ SN:R=47:Helitron_1_GA::chrI:534562-534625() LN:63
@SQ SN:R=11:SINE_FR2::chrI:533571-533726() LN:155
@SQ SN:R=85:Unknown::chrI:533414-533572() LN:158

I'm not quite sure what's going on here

samtools bam sam

Are you sure that there is -b option?

2 answers

Samtools cat does indeed have a -b option: it's for giving it a text file containing a list of the BAM filenames to be processed.

You're giving it the BAM filenames directly on the command line, so should just give it the filenames — not via an option:

samtools cat -h header.bam -o catR1.bam 1_R1.bam 2_R1.bam

That's the major problem; as h.mon suggests, you could simplify your header stuff too. (And as you're doing it at present, that's header.sam rather than header.bam.)

You want samtools view -H, as `samtools view -h' prints the header and all alignment records. From the help:

  -H       print SAM header only (no alignments)
  -h       include header in SAM output

However, you dont need to pass the header to samtools cat, because by default it will use the header from the first file 1_R1.bam.

Log in to answer this question.