This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to convert BAM to FASTQ using Picard Tools ?

Hi,

I am trying to convert a BAM file to a FASTQ file. This is my first time analysis of BAM file. I want to use Picard tools for the analysis. After reading some posts on Biostars and Picard website, I was able to understand something. But, I am getting following error:

COMMAND

$ java -Xmx6g -jar ../picard-tools-1.126/picard.jar SamToFastq I=file.bam F=file.fastq

ERROR

[Thu May 21 14:46:55 CDT 2015] picard.sam.SamToFastq INPUT=../../data/F14FTSUSAT1066_HUMsfcX/bam/1AA_rawlib.bam FASTQ=1AA_rawlib.fastq    OUTPUT_PER_RG=false RE_REVERSE=true INTERLEAVE=false INCLUDE_NON_PF_READS=false
READ1_TRIM=0 READ2_TRIM=0 INCLUDE_NON_PRIMARY_ALIGNMENTS=false VERBOSITY=INFO QUIET=false VALIDATION_STRINGENCY=STRICT COMPRESSION_LEVEL=5 MAX_RECORDS_IN_RAM=500000 CREATE_INDEX=false CREATE_MD5_FILE=false
[Thu May 21 14:46:55 CDT 2015] Executing as deepak@tenor on Linux 3.10.0-229.1.2.el7.x86_64 amd64; OpenJDK 64-Bit Server VM 1.7.0_75-mockbuild_2015_03_26_13_15-b00; Picard version: 1.126(4691ee611ac205d4afe2a1b7a2ea975a6f997426_1417447214) IntelDeflater
[Thu May 21 14:46:57 CDT 2015] picard.sam.SamToFastq done. Elapsed time: 0.02 minutes.
Runtime.totalMemory()=2058354688
To get help, see http://broadinstitute.github.io/picard/index.html#GettingHelp
Exception in thread "main" htsjdk.samtools.FileTruncatedException: Premature end of file
        at htsjdk.samtools.util.BlockCompressedInputStream.readBlock(BlockCompressedInputStream.java:382)
        at htsjdk.samtools.util.BlockCompressedInputStream.available(BlockCompressedInputStream.java:127)
        at htsjdk.samtools.util.BlockCompressedInputStream.read(BlockCompressedInputStream.java:252)
        at java.io.DataInputStream.read(DataInputStream.java:149)
        at htsjdk.samtools.util.BinaryCodec.readBytesOrFewer(BinaryCodec.java:404)
        at htsjdk.samtools.util.BinaryCodec.readBytes(BinaryCodec.java:380)
        at htsjdk.samtools.util.BinaryCodec.readByteBuffer(BinaryCodec.java:490)
        at htsjdk.samtools.util.BinaryCodec.readInt(BinaryCodec.java:501)
        at htsjdk.samtools.BAMRecordCodec.decode(BAMRecordCodec.java:178)
        at htsjdk.samtools.BAMFileReader$BAMFileIterator.getNextRecord(BAMFileReader.java:660)
        at htsjdk.samtools.BAMFileReader$BAMFileIterator.advance(BAMFileReader.java:634)
        at htsjdk.samtools.BAMFileReader$BAMFileIterator.next(BAMFileReader.java:628)
        at htsjdk.samtools.BAMFileReader$BAMFileIterator.next(BAMFileReader.java:598)
        at htsjdk.samtools.SamReader$AssertingIterator.next(SamReader.java:514)
        at htsjdk.samtools.SamReader$AssertingIterator.next(SamReader.java:488)
        at picard.sam.SamToFastq.doWork(SamToFastq.java:153)
        at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:187)
        at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:89)
        at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:99)
picard bam fastq

1 answer

There's something wrong with the bam. Please try

samtools view -c file.bam

to test the bam.

Hi Pierre,

Yes.

/share/apps/samtools/samtools view -c file.bam
[bam_header_read] EOF marker is absent. The input is probably truncated.
[main_samview] truncated file.

so there was something wrong with the tool that generated file.bam, you'll have to generate it again.

Yes, you are right. Same command for other 2 bam files is working perfectly.

Thank you so much Pierre.

Log in to answer this question.