I have a bam file (pool.bam) that represents PCR amplicons of many samples, pooled into one sequencing lane. For some regions, the same amplicon was generated and sequenced for more than one sample. There is a 3 base index at the beginning of the PCR primer that is used to tell the samples apart. To look at the specific position of interest in each sample, I'd like to parse out the samples in the bam file, and use mpileup to evaluate the SNV that was amplified. I tried converting to sam file (samtools view -o pool.sam pool.bam) and using grep for the individual primers used for each sample (more pool.com | grep TCACAAGAAACCCTGCT > grep.sam), which appeared to work well. But if I try to convert to bam and index it before using mpileup, I get an error: missing SAM header; parse error at line 1; truncated file.
What is a better way to do this?