text: user180: I produced a bam file by aligning reads to a small set of synthetic sequences using bwa-mem.
  I am heavily filtering reads that are not paired and of a certain orientation.
  Applying the filtering, I get a few thousands of reads:
  samtools view -h $myfilebam | \
  samtools view -h -F4 - | \
  samtools view -h -F8 - | \
  samtools view -h -F256 - | \
  samtools view -h -F512 - | \
  samtools view -h -F1024 - | \
  samtools view -h -F2048 - | \
  samtools view -h -f16 - | \
  samtools view -h -f32 -  | wc -l
  
  Gives me 89502 reads.
  If I then pipe this into samtools mpileup, I get no results:
  samtools view -h $myfilebam | \
  samtools view -h -F4 - | \
  samtools view -h -F8 - | \
  samtools view -h -F256 - | \
  samtools view -h -F512 - | \
  samtools view -h -F1024 - | \
  samtools view -h -F2048 - | \
  samtools view -h -f16 - | \
  samtools view -h -f32 -  | \
  samtools mpileup --excl-flags 0 -Q0 -B -d 999999 - | wc -l
  
  Returns 0.
  I tried different combinations of filtering, and when I do both -f 16 and -f 32 returns empty, but if I do either of those, then it works:
  samtools view -h $myfilebam | \
  samtools view -h -F4 - | \
  samtools view -h -F8 - | \
  samtools view -h -F256 - | \
  samtools view -h -F512 - | \
  samtools view -h -F1024 - | \
  samtools view -h -F2048 - | \
  samtools view -h -f16 - | \
  samtools mpileup --excl-flags 0 -Q0 -B -d 999999 - | wc -l
  
  Returns 1056.
  Any ideas why? My thinking was that it would work with --excl-flags 0.
  EDIT: substituting mpileup for depth does work, and prints out each position and the depth as expected.
  EDIT2: adding -q 0 to mpileup gives the same empty result.
  Thanks in advance
  
  user73: By using -h in the samtools view command, you're including all the header lines in your word count. If you happen to have about 89500 reference sequences, then the lengths of those would all appear in the header and inflate the -h word count, but not the mpileup count. Try piping it through an additional samtools view (i.e. without -h) and see if the counts change:
  ...
  samtools view -h -f32 -  | \
  samtools view | wc -l
  
  Also, samtools mpileup by default only considers high-quality bases and concordant reads. Try adding a -A to your mpileup line (which stops anomalous read pairs from being discarded):
  ...
  samtools mpileup -A -Q0 -B -d 999999 - | wc -l
  
  
original_text: 180: <p>I produced a bam file by aligning reads to a small set of synthetic sequences using bwa-mem.</p>
  
  <p>I am heavily filtering reads that are not paired and of a certain orientation.
  Applying the filtering, I get a few thousands of reads:</p>
  
  <pre><code>samtools view -h $myfilebam | \
  samtools view -h -F4 - | \
  samtools view -h -F8 - | \
  samtools view -h -F256 - | \
  samtools view -h -F512 - | \
  samtools view -h -F1024 - | \
  samtools view -h -F2048 - | \
  samtools view -h -f16 - | \
  samtools view -h -f32 -  | wc -l
  </code></pre>
  
  <p>Gives me <code>89502</code> reads.</p>
  
  <p>If I then pipe this into <code>samtools mpileup</code>, I get no results:</p>
  
  <pre><code>samtools view -h $myfilebam | \
  samtools view -h -F4 - | \
  samtools view -h -F8 - | \
  samtools view -h -F256 - | \
  samtools view -h -F512 - | \
  samtools view -h -F1024 - | \
  samtools view -h -F2048 - | \
  samtools view -h -f16 - | \
  samtools view -h -f32 -  | \
  samtools mpileup --excl-flags 0 -Q0 -B -d 999999 - | wc -l
  </code></pre>
  
  <p>Returns 0.</p>
  
  <p>I tried different combinations of filtering, and when I do both <code>-f 16</code> and <code>-f 32</code> returns empty, but if I do either of those, then it works:</p>
  
  <pre><code>samtools view -h $myfilebam | \
  samtools view -h -F4 - | \
  samtools view -h -F8 - | \
  samtools view -h -F256 - | \
  samtools view -h -F512 - | \
  samtools view -h -F1024 - | \
  samtools view -h -F2048 - | \
  samtools view -h -f16 - | \
  samtools mpileup --excl-flags 0 -Q0 -B -d 999999 - | wc -l
  </code></pre>
  
  <p>Returns <code>1056</code>.</p>
  
  <p>Any ideas why? My thinking was that it would work with <code>--excl-flags 0</code>.</p>
  
  <p>EDIT: substituting <code>mpileup</code> for <code>depth</code> does work, and prints out each position and the depth as expected.</p>
  
  <p>EDIT2: adding <code>-q 0</code> to <code>mpileup</code> gives the same empty result.</p>
  
  <p>Thanks in advance</p>
   73: <p>By using <code>-h</code> in the <code>samtools view</code> command, you're including all the header lines in your word count. If you happen to have about 89500 reference sequences, then the lengths of those would all appear in the header and inflate the <code>-h</code> word count, but not the mpileup count. Try piping it through an additional <code>samtools view</code> (i.e. without <code>-h</code>) and see if the counts change:</p>
  
  <pre><code>...
  samtools view -h -f32 -  | \
  samtools view | wc -l
  </code></pre>
  
  <p>Also, <code>samtools mpileup</code> by default only considers high-quality bases and concordant reads. Try adding a <code>-A</code> to your mpileup line (which stops anomalous read pairs from being discarded):</p>
  
  <pre><code>...
  samtools mpileup -A -Q0 -B -d 999999 - | wc -l
  </code></pre>
  