This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Generating pileup from .bam file

What is a tool with which I can generate pileups form .bam file for every positions on reference (I want to find out all bases for every position ('A', 'C', 'T', 'G') and indels (separately insertion and deletion))?

I have used pysam, but wasn't able to get indels.

genome pileup indels

3 answers

After the research of tools, I have found this tool to fit my usecase: pysamstats.

It gives me what I need: for every pileup position, I can get the number of A, C, G, T, insertions and deletions.

import pysam
import pysamstats

bamfile = pysam.AlignmentFile(bam_file_path)  
for record in pysamstats.stat_variation(bamfile, chrom=chrom, fafile=ref_path):
    print(record['pos'])
    print(record['A'])
    print(record['C'])
    print(record['G'])
    print(record['T'])
    print(record['insertions'])
    print(record['deletions'])

Thanks for your answers.

Hmmm have you looked at samtools mpileup? http://samtools.sourceforge.net/mpileup.shtml

You can also look at gatk Pileup which is similar to samtool's mpileup.

Log in to answer this question.