This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Problem With Mpileup

I tried to make a coverage per base figure by processing single_reference.sam file with following commands:; samtools view -bS $1.sam > $1.bam; samtools sort $1.bam > $1.sort.bam; samtools mpileup $1.sort.bam > $1.c; cat $1.c | awk '{FS=" "}{print $2" "$4}' > $1.pileup

However, I received the following notice after running the sh:; [samopen] SAM header is present: 1 sequences.; Usage: samtools sort [-on] [-m <maxMem>] <in.bam> <out.prefix>; [bamheaderread] bgzfcheckEOF: Invalid argument; [bamheaderread] invalid BAM binary header (this is not a BAM file).; sam2bam2pileup.sh: line 4: 24893 Segmentation fault samtools mpileup $1.sort.bam > $1.c

Thanks for your gracious help!

samtools mpileup sam bam

1 answer

Samtools sort doesn't write to standard output, rather it writes to a file for which you specify the name prefix as an argument (samtools will add the ".bam" extension itself):

samtools sort inputFile.bam outputFile

Log in to answer this question.