Skip to content

How to read a record from bam and write it to fastq #311

Answered by zaeleus
wrb2012 asked this question in Q&A
Discussion options

You must be logged in to vote

There are three main fields in a FASTQ record: name, sequence, and quality scores. These correspond to the same fields in a BAM record.

It's straightforward to process single segment reads. Take each BAM record and write four lines: the read name prefixed with a @, the sequence, a +, and the quality scores offset by +33. If the read is reverse complemented, this must be taken into account when writing the sequence bases and quality scores. A possible solution to this example can be seen at noodles-bam/examples/bam_fastq.rs.

To process multi-segmented reads, the steps are similar, but mates must first be gathered together. This can be done by either buffering records and matching them or r…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wrb2012
Comment options

Answer selected by wrb2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants