This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Picard MergeSam error : Cannot use index file with textual SAM file

I tried to run a simple mergesam using picard on two bam files using the following command

java -jar /opt/picard/picard.jar MergeSamFiles I=file1.bam I=file2.bam O=merged_output.bam USE_THREADING=TRUE

This is giving me the following error

Exception in thread "main" java.lang.RuntimeException: **Cannot use index file with textual SAM file**
    at htsjdk.samtools.SamReaderFactory$SamReaderFactoryImpl.open(SamReaderFactory.java:317)
    at htsjdk.samtools.SamReaderFactory$SamReaderFactoryImpl.open(SamReaderFactory.java:145)
    at picard.sam.MergeSamFiles.doWork(MergeSamFiles.java:142)
    at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:208)
    at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:95)

What does it mean and how do I fix it ?

Thanks

picard mergesam

Figured it out. I only had a partial bam file. Once i downloaded it again, MergeSam ran perfectly. Easy solution to a very silly problem.

Thanks for your time Pierre.

if it answered your question, click on the green mark near my answer to close the post.

1 answer

can your please run the following command:

file file1.bam file2.bam

it should return:

gzip compressed data, extra field

if not (eg: ASCII text) your files are SAM but not BAM.

if not, I suggest your update your version of picard because there is no such method SamReaderFactoryImpl.openat line 317. https://github.com/samtools/htsjdk/blob/master/src/main/java/htsjdk/samtools/SamReaderFactory.java#L317

Thank you. I tried the command and I got this

file1.bam: gzip compressed data, extra field

file2.bam: data

Does this mean my file2 is a SAM file ?

mean my file2 is a SAM file

try head file2.bamor hexdump -c file2.bam | head to see if you can guess the format...

Log in to answer this question.