Biostar Beta. Not for public use.
Question: Converting Bam To Fastq
10
Entering edit mode

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.

ADD COMMENTlink 9.9 years ago Zach Stednick • 650 • updated 3.1 years ago Biostar 20
Entering edit mode
1

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 REPLYlink 9.6 years ago
Mike Muratet
• 40
• updated 17 months ago
RamRS
21k
Entering edit mode
2

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

ADD REPLYlink 9.6 years ago
Zach Stednick
• 650
Entering edit mode
0

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

Thanks, Teja

ADD REPLYlink 8.4 years ago
Teja
• 0
Entering edit mode
0

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

ADD REPLYlink 8.4 years ago
Khader Shameer
18k
17
Entering edit mode

use SamToFastq : http://picard.sourceforge.net/command-line-overview.shtml#SamToFastq

ADD COMMENTlink 9.9 years ago Pierre Lindenbaum 120k • updated 7.8 years ago Istvan Albert 80k
Entering edit mode
0

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

ADD REPLYlink 9.6 years ago
Pierre Lindenbaum
120k
7
Entering edit mode

There is a bam2fastx utility bundled with tophat:

bam2fastx [--fasta|-a|--fastq|-q] <in.bam>
ADD COMMENTlink 8.3 years ago Casey Bergman 18k • updated 17 months ago RamRS 21k
Entering edit mode
1

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 REPLYlink 5.1 years ago
Adrian Pelin
♦ 2.3k
• updated 17 months ago
RamRS
21k
5
Entering edit mode

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

ADD COMMENTlink 9.6 years ago Aaronquinlan 11k
4
Entering edit mode

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

ADD COMMENTlink 8.8 years ago Doctoroots • 780
Entering edit mode
1

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

ADD REPLYlink 3.4 years ago
Charles Plessy
♦ 2.7k
2
Entering edit mode

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

ADD COMMENTlink 3.4 years ago Ron • 950
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 COMMENTlink 3.8 years ago bshifaw • 50 • updated 17 months ago RamRS 21k
Entering edit mode
0

FYI, if you're directly copying this answer, you should use camel case: SamToFastq for the program name. Thanks for the answer!

ADD REPLYlink 3.2 years ago
toddknutson
• 50

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.0