This is a basic question so maybe someone can make the best of it and explain some basic details so that newbies can benefit from it.
I have been using samtools commands from other people that I think know what their doing.
The commands I have been giving are view piped to mpileup
samtools view -u someones.bam chrY:2709520-57443438 | samtools mpileup -B -Q reference.fa - > outfile.txt
I tried to run the mpileup command without view and it's just as fast.
Why would I want to pipe view to mpileup?
2 answers
I assume you can specify "chrY:2709520-57443438" as a region parameter in mpileup and it should do the same work for you (I have never tried it). For example: samtools mpileup -r STR will only generate pileup in region STR , default - all sites.
May be the guy from whom you borrowed the code didn't know this OR may be mpileup didn't have region(-r) functionality at that time.
I know this doesn't answer your question directly but this is all I could come up with. Also using -u command will produce uncompressed bam or SAM format stream.
The format that you have allows one to add more filters to the sam view before passing it to mpileup. That usually is a very common operation when investigating data by some property.
Log in to answer this question.