samtools extract unmapped reads
1
0
Entering edit mode
4.7 years ago
wrab425 ▴ 50

I have been given the following command to extract unmapped reads from a bam file

samtools view -b -f 141 ${SAMPLE_ID}.ecoli.bwamem.bam > ${SAMPLE_ID}.unmapped_ecoli_2.bam
  1. I am unsure what the -f flag and 141 means
  2. Is it necessary to sort the bam file before running this command?
  3. I have consulted the samtools view manual and it is not clear why this command should extract unmapped reads.

Thanks

alignment samtools • 3.6k views
ADD COMMENT
0
Entering edit mode
4.7 years ago
ATpoint 86k

See this link that explains flags: http://broadinstitute.github.io/picard/explain-flags.html

For all unmapped reads do:

samtools view -f 4 -o ${SAMPLE_ID}.unmapped_ecoli_2.bam ${SAMPLE_ID}.ecoli.bwamem.bam

-f means keep and -F means do not keep so in the above command you keep only unmapped reads. Extraction of reads where both the read and the mate are unmapped would be -f 13 given it is paired-end.

You can then modify based on your needs with the linked tool that gives you the flags you want based on the read properties.

ADD COMMENT
0
Entering edit mode

Thanks ATpoint, that was very helpful. I am just getting rid of contaminating reads that map to ecoli before mapping to my host genome so I do not think that I need to sort. Is that correct? I think your command is doing the same thing as mine and that if I use the o flag with a bam file then I do not need a b flag and the > sign. Is that correct?

ADD REPLY
0
Entering edit mode

Yes, this all sounds correct.

ADD REPLY

Login before adding your answer.

Traffic: 1564 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