I need to extract fastq seq. from a BAM file for other experiments. But the fastq file should only contain unique fastq seq. [Here unique fastq means if there are multiple copies of a seq. in BAM file then in the fastq file I only want a single copy of that seq. ]
2 answers
The operation that you ask about is called deduplication.
But first, you'd need to extract the sequences which can be slightly more complicated for paired-end reads, you would need to collate then extract, see this post
https://lh3.github.io/2021/07/06/remapping-an-aligned-bam
Deduplication:
If you want to make sure that you get each read only once, even if it aligned to multiple places, and don't care if two separate reads have identical sequences, you can filter your bam file to remove secondary alignments. Each read will have exactly one primary alignment.
Log in to answer this question.