How to convert BAM to FASTQ using Picard Tools ?
1
2
Entering edit mode
9.5 years ago
Deepak Tanwar ★ 4.2k

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 • 9.2k views
ADD COMMENT
3
Entering edit mode
9.5 years ago

There's something wrong with the bam. Please try

samtools view -c file.bam

to test the bam.

ADD COMMENT
1
Entering edit mode

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.
ADD REPLY
1
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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

Thank you so much Pierre.

ADD REPLY

Login before adding your answer.

Traffic: 1726 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6