This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to annotate a bam file?

Hi,

I'm looking for a method/tool for annotating a bam file.

After running the mapping with STAR, I have filtered my bam file for specific reads, I am interested in. I would now like to assign a gene (nearest gene) or any other genomic structure, if possible to each of the reads.

Best case scenario, I would like to get as an output a table of the reads and the annotation as a table.

Is there something like that out there?

thanks

bam annotations

output a table of the reads

You can complement @ATPoint's solution by pulling reads out with samtools view region.

1 answer

You can transform the BAM to BED with bamtobed from bedtools and then use bedtools closest to get the closest match for that newly generated BED file, given that the annotation file you have is in a compatible format, e.g. GTF or BED itself.

thanks, does closest also works with a gtf file?

Not sure, many bedtools commanfs do, check the manual. Alternatively load things into R and use the intersection/nearest functions from GenomicRanges.

Log in to answer this question.