This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Question: Samtools Select SAM Flag for unpaired uniquely reads

Hi

I have a two alignments of unpaired reads, and I am trying to find out how many reads aligned uniquely from each sample. I keep reading that I should use the command

samtools view -f 0  

But when I look at the out put there is still other SAM FLAGS in the list.

any help would be appreciated but please keep it simple I'm a molecular biologist that's only just started Bioinformatics.

samtools

2 answers

Figures it out

samtools view -F 256 BamFile.bam was what i needed

You may want to add -F 4 to remove unmapped reads, and -h to keep the headers so that SAM/BAM viewers can read that file. The command I use (removes also reverse complements) is :

samtools view -h -F 4 -F 16 -F 256 alignments.sam | grep -E "@|NM" | grep -v "XS:" > uniq_noRev.sam

However this command screws up a bit, because the lines with "XS" are removed, while their corresponding headers remain on top of the file.

as i said i'm new so i'm not surprised my question doesn't make sense.

i'm trying to find the read that don't align to another place on the genome i am aligning to. I'm doing this by selecting using the SAM flag (https://broadinstitute.github.io/picard/explain-flags.html) and i believe i have worked it out, so that i only want the reads that have a SAM flag of 0 and 16.

But when i try to us the samtools view (on a BAM file) to select for only 0 and 16 using

samtools view -f 16 Alignment.bam

but i see other SAM flags like 272 and 256 in the output text, and i cant figure out why they are included.

Log in to answer this question.