This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Piping samtools commands

Hi,

I'm wondering how one would go about streaming the followings samtools commands without the intermediate bam and sam files.

samtools view -F 4 -b in.bam > filtered.bam
samtools sort filtered.bam filtered_sorted
samtools view filtered_sorted.bam > filtered_sorted.sam
awk -F "\t" '{print $3}' filtered_sorted.sam > rnames.txt

I'd appreciate any help!

samtools

1 answer

samtools view -b -F 4 in.bam | samtools sort -o - TMP | samtools view - | awk '{ print $3}' > rnames.txt

rm TMP

Thank you! But was there something wrong with the prior answer you had?

If you really care only about the final output, you could simply do:

samtools view -F 4 in.bam | cut -f3 | sort > rnames.txt

Log in to answer this question.