Given a sorted BAM file, I need to plot the sequencing reads that cover every locus in a list of ~60-80 loci (with flanking regions).
Currently, I'm doing this manually using IGV (or any other BAM GUI viewers) by taking screen prints but this is not practical.
What would you recommend to generate such plots in a non-GUI mode? This is going to be part of a pipeline written in Python. I know IGV has some command line tools (called IGVtools) but they are for indexing and counting reads but nothing for viewing BAM file outside the GUI.
From Python directly, you could use this simple IGV wrapper from @brentp. Copied from the example usage of that script:
#example usage:>>> igv = IGV()>>> igv.genome('hg19')'OK'>>> igv.load('http://www.broadinstitute.org/igvdata/1KG/pilot2Bams/NA12878.SLX.bam')'OK'>>> igv.go('chr1:45,600-45,800')'OK'#save as svg, png, or jpg>>> igv.save('/tmp/r/region.svg')'OK'>>> igv.save('/tmp/r/region.png')'OK'# go to a gene name.>>> igv.go('muc5b')'OK'>>> igv.sort()'OK'>>> igv.save('muc5b.png')'OK'# get a list of commands that will work as an IGV batch script.>>> print "\n".join(igv.commands)
snapshotDirectory /tmp/igv
genome hg19
goto chr1:45,600-45,800
snapshotDirectory /tmp/r
snapshot region.svg
snapshot region.png
goto muc5b
sort base
snapshot muc5b.png
# Note, there will be some delay as the browser has to load the annotations# at each step.
With Perl (or any language) perhaps the simplest approach is to programmatically construct a text file to be used as a script for IGV (http://www.broadinstitute.org/software/igv/batch). The Python stuff above just makes this more convenient from within Python code.
Sorry, I'm not familiar at all with Phyton, just wondering how to read a file with say, 100 different positions at the genome and then input them into a loop to get the 100 different plots, ... If you know any Perl option to do this would be nice to know it, Many thanks in advance,
Sorry, I'm not familiar at all with Phyton, just wondering how to read a file with say, 100 different positions at the genome and then input them into a loop to get the 100 different plots, ... Also, If you know any Perl option to do this would be nice to know it, Many thanks in advanc
Download the IGV : You can automate it without manually opening the IGV:
If starting file is bed file, use "bedToIgv" from bedtools to generate the igv_batch.file for snapshots:
If you install and setup GBrowse2 you can programmatically generate images for each region (see here). I have used GBrowse2 before to do this with next generation sequencing, it's quite nice because the height of the image is not limited and you can add additional annotations such as coverage plots and gene annotations.
The images generated by GBrowse2 are pretty and very flexible.Thanks GWW. The only concern is about the difficulties of installing GBrowse2 which, IMO, can be cumbersome for many non-savvy end users.
This way you can quickly create small images with the reads from your bam file with many viewing options. like this [example] (click on one button on the right).
I don't really have a definitive answer, I asked in similar terms a while ago but I think it would be great to have a definitive answer to the question:
I must've missed your question when I searched for 'BAM viewer' in BioStar. Thanks avilella. Although this is a practical solution , tview output is not that pretty, don't you think? :)
I think this is a great question, I asked in similar terms a while ago and didn't get a definitive answer: Quick Visual Inspection Of Mapping Images For A List Of Regions