Converting Bam To Fastq
5
10
Entering edit mode
14.6 years ago
Zach Stednick ▴ 660

Any suggestions on good programs or scripts to convert a BAM file back to a fastq? I have found some scripts but wanted to ask for advice before I go too far down the wrong path.

next-gen-sequencing fastq • 41k views
ADD COMMENT
1
Entering edit mode

Do you know the rules for identifying mate pairs? I used bowtie to align some paired end reads into a sam format file and was able to use various picard methods to process it. I made a file with duplicates removed and SamToFastq throws an exception:

Exception in thread "main" net.sf.picard.PicardException: Illegal mate state: HWUSI-EAS614_1:1:12:4379:1523:0:2:1
at net.sf.picard.sam.SamToFastq.assertPairedMates(SamToFastq.java:231)
at net.sf.picard.sam.SamToFastq.doPaired(SamToFastq.java:140)
at net.sf.picard.sam.SamToFastq.doWork(SamToFastq.java:95)
at net.sf.picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:150)
at net.sf.picard.sam.SamToFastq.main(SamToFastq.java:87)

I assume because the read ID is not HWUSI-EAS614_1:1:12:4379:1523/2

Have you any had any problems like this?

Thanks

Mike

ADD REPLY
2
Entering edit mode

I have not. Maybe you should ask this as an independent question to have more people view and potentially offer assistance.

ADD REPLY
0
Entering edit mode

Mike, Did you find a way around it? Im facing the same problem.

Thanks, Teja

ADD REPLY
0
Entering edit mode

Teja, please ask your problem as a separate question for detailed response.

ADD REPLY
17
Entering edit mode
14.6 years ago

Use SamToFastq

UPDATE 2023: use samtools collate piped into samtools fastq

ADD COMMENT
1
Entering edit mode

You can use Picard

java -jar picard.jar SamToFastq \
     I=input.bam \
     FASTQ=output.fastq

http://broadinstitute.github.io/picard/command-line-overview.html#SamToFastq

ADD REPLY
0
Entering edit mode

I moved this comment here as it's adds to Pierre's answer and is not a unique answer of its own.

ADD REPLY
0
Entering edit mode

hu ? I wonder why someone flagged this as negative ???!! :-/

ADD REPLY
7
Entering edit mode
13.0 years ago

There is a bam2fastx utility bundled with tophat:

bam2fastx [--fasta|-a|--fastq|-q] <in.bam>
ADD COMMENT
1
Entering edit mode

Works really really well for me:

bam2fastx --fastq -M -o S1_mapped.fastq -N S1.sort.grp.md.bam

Here it adds the /1 and /2 suffix for paired reads and doesn't complain if mate is missing (some of my reads are single ended and don't have a mate). Bam2Fastq would complain about missing mates and wouldn't export single ended reads unless extra precautions were taken.

ADD REPLY
5
Entering edit mode
14.4 years ago

There is also one in the Hydra package. It's called bamToFastq.

ADD COMMENT
4
Entering edit mode
13.6 years ago
Doctoroots ▴ 800

Here is another tool that saves the transition into sam format and converts bam directly into fastq: bam2fastq

ADD COMMENT
1
Entering edit mode

By the way, the URL changed to https://gsl.hudsonalpha.org/information/software/bam2fastq, but the software is deprecated in favour of Picard.

ADD REPLY
2
Entering edit mode
8.1 years ago
Ron ★ 1.2k

Bedtools - for converting bam to fastq http://bedtools.readthedocs.io/en/latest/content/tools/bamtofastq.html

ADD COMMENT

Login before adding your answer.

Traffic: 1648 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