16 February 2011

Generating a WIG file containing the coverage data of a BAM file

The following (experimental) C-code generates a 'Wiggle Track Format' (WIG) file containing the coverage/depth data extracted from a BAM file.

It uses the C API of samtools to loop over the mapped short reads of the BAM file, and for each short-read, it scans the CIGAR description and increase the number of hits seen on the chromosome at a given position.

It takes as an optional UCSC knownGene.txt file to restrict the output to the known translated regions.

The C code



Test


This Makefile generates a random pair of FASTQ files for the human chr22, maps them with BWA , creates a BAM and generates the WIG file:

Result

The resulting WIG file was uploaded as a custom track in the UCSC genome browser:


That's it,

Pierre

No comments: