This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract unmapped reads OR reads covering chromosome 6 from a bam file?

Is there a one-liner approach to extracting reads from a .bam file that are unmapped OR aligned to chromosome 6?

Edit: ChatGPT give this response to the question: samtools view -f 4 -b input.bam 6 > chr6_and_unmapped.bam

Edit: Changed AND to OR

fastq bam samtools picard

That would seem to be the answer to the question you posed. You are sure you do not want reads that aligned to Chr 6 OR unmapped reads?

I'm doing HLA typing and need reads that aligned to chromosome 6 or that were unmapped.

need reads that aligned to chromosome 6 and that were unmapped.

If a read was aligned to a chromosome how would it be unmapped at the same time?

I mean or as opposed to and. I need reads that are mapped to chromosome 6. I also need unmapped reads.

I see. So get the reads that were unmapped in one operation and the get the ones mapped to Chr6 in other to keep things simple.

That's right, but after some time looking into it I don't think it can be done as a one liner, with samtools at least.

You may be able to use tee program to split the input into two streams and operate on both (doing two operations in parallel) but it may be better to keep things simple.

I'll look into that, thanks! I'm leaning towards two separate samtools commands, as you've suggested.

Is that a logical OR? Unless I am not missing something obvious, I don't see how a read can both map to chromosome 6 and be unmapped at the same time?

0 answers

No answers yet.

Log in to answer this question.