Perhaps try BEDOPS
sort-bed to convert your BAM data to UCSC BED?
$ bam2bed < foo.bam | sort-bed - | cut -f1-6 > foo.bed
Then make a custom track from it, using the
squish display modes. If you zoom out far enough, you can get a rough picture of read density.
Addendum: If you want to count reads within windows, take a look at this usage case which bins BAM reads ("tags") within a sliding 20 bp window. The result is a compressed BED file that contains binned score values that (when extracted from Starch to BED) can also be brought into a UCSC Genome Browser instance. Because it will contain binned scores, this rendition is probably going to be closer to the histogram visualization you are after, than a simple display of individual tags.
Explanation of binning script
I'll walk through the process of using the BEDOPS-based binning script to generate a histogram of binned reads on a UCSC Genome Browser.
(1) Get the
hg19 version of the
chromInfo table from the UCSC Genome Browser
Visit the UCSC Table Browser. With the
All Tables group selected, for example, select the
hg19 database and the
chromInfo table. Output all fields to a text file. (This step can also be performed with
mysql commands, if this needs automating.)
(2) Edit this text file (e.g. run
awk on it to put in the start coordinate) and pipe it to
sort-bed to turn it into a sorted BED file. Here's a ready-to-use example for
hg19 that I just made: https://dl.dropbox.com/u/31495717/chrList.bed Again, this can be automated.
(3) Bin the read data. For example, the following makes a 75 bp-windowed read count spaced in 20 bp bins, written to a Starch-formatted archive called
$ binReads.sh myReads.bam $PWD/result.starch 75 20 chrList.bed
The Starch file is just a very highly-compressed BED file. We made this format so that we could make the best use of our lab's storage capabilities. You can edit the
binReads.sh script to remove the
starch - call if you don't want the BED data to be compressed, which lets you skip step 4. Otherwise, we go on to the next step:
(4) Extract the binned result to a BED file:
$ unstarch result.starch > result.bedGraph
(5) Edit the
result.bedGraph file to add the track type. All you need to do is insert
track type=bedGraph on its own line at the top of the file, although you can add various parameters to customize the display and look, etc.
(6) Place the modified
result.bedGraph on a public-facing web site and copy the URL — or otherwise load a local copy — into a UCSC Genome Browser instance via the Custom Track page (
manage custom track). The Genome Browser will recognize it as a bedGraph file and render it accordingly.
That's all there is to it. All these steps can be automated, once you have the process down.