-
How to read a record from bam and write it to fastq? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 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 requiring the input to be sorted by name. The read can then be written to multiple outputs or interleaved in one. |
Beta Was this translation helpful? Give feedback.
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 atnoodles-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…