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.
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.
Use SamToFastq
UPDATE 2023: use samtools collate
piped into samtools fastq
java -jar picard.jar SamToFastq \
I=input.bam \
FASTQ=output.fastq
http://broadinstitute.github.io/picard/command-line-overview.html#SamToFastq
There is a bam2fastx utility bundled with tophat:
bam2fastx [--fasta|-a|--fastq|-q] <in.bam>
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.
There is also one in the Hydra package. It's called bamToFastq.
Here is another tool that saves the transition into sam format and converts bam directly into fastq: bam2fastq
By the way, the URL changed to https://gsl.hudsonalpha.org/information/software/bam2fastq, but the software is deprecated in favour of Picard.
Bedtools - for converting bam to fastq http://bedtools.readthedocs.io/en/latest/content/tools/bamtofastq.html
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
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:
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
I have not. Maybe you should ask this as an independent question to have more people view and potentially offer assistance.
Mike, Did you find a way around it? Im facing the same problem.
Thanks, Teja
Teja, please ask your problem as a separate question for detailed response.