text: user15643: I have sam and bam files for the chimeric reads, which come from two different parts of the genome (For example, the first half of the read from part of Chromosome 1 and the second half of the read from part of Chromosome 3). I have removed the low mapping quality reads (MAPQ <= 30) and reads with high mismatches. This might result in some unpaired reads which need to be removed before further analysis. May I ask whether there is any way to remove the unpaired reads in sam/bam files? Thanks!
  
  user6273: The -f option of samtools view is for flags and can be used to filter reads in bam/sam file matching certain criteria such as properly paired reads (0x2) :
  samtools view -f 0x2 -b in.bam > out.bam
  
  
original_text: 15643: <p>I have sam and bam files for the chimeric reads, which come from two different parts of the genome (For example, the first half of the read from part of Chromosome 1 and the second half of the read from part of Chromosome 3). I have removed the low mapping quality reads (MAPQ &lt;= 30) and reads with high mismatches. This might result in some unpaired reads which need to be removed before further analysis. May I ask whether there is any way to remove the unpaired reads in sam/bam files? Thanks!</p>
   6273: <p>The <code>-f</code> option of <code>samtools view</code> is for <a href="http://www.htslib.org/doc/1.11/samtools-flags.html" rel="nofollow noreferrer">flags</a> and can be used to filter reads in bam/sam file matching certain criteria such as properly paired reads (<code>0x2</code>) :</p>
  <pre><code>samtools view -f 0x2 -b in.bam &gt; out.bam
  </code></pre>
  