Extract unmapped reads OR reads covering chromosome 6 from a bam file?
0
0
Entering edit mode
21 months ago
bioinf_sci ▴ 20

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 • 1.1k views
ADD COMMENT
1
Entering edit mode

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?

ADD REPLY
2
Entering edit mode

You are correct, I need OR

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1825 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6