Przemol / seqplots

:chart_with_upwards_trend:SeqPlots - An interactive tool for visualizing NGS signals and sequence motif densities along genomic features using average plots and heatmaps.
http://przemol.github.io/seqplots
86 stars 25 forks source link

What is the best way to convert bam files into bigwig or bedgraph to use in seqplots? #5

Closed ramonvidal closed 9 years ago

ramonvidal commented 9 years ago

Dear Author, What is the best way? I dont want to create a binned file (I want the maximum resolution). Which tool do you usually use for converting bam files to one of the required in seqplots? Thanks

Przemol commented 9 years ago

From Bioconductor packages I recommend using GenomicAlignments package to import BAM file to R and rtracklayer package for exporting the reads coverage to BigWig format. This will give you single base resolution track.

The following R code will do the trick:

library(GenomicAlignments)
library(rtracklayer)

bamfile <- system.file("extdata", "ex1.bam", package="Rsamtools", mustWork=TRUE)
show(bamfile)

alignment <- readGAlignments(bamfile)
reads_coverage <- coverage(alignment)

export.bw(reads_coverage, con = "output_BigWig.bw")

Alternatively, you can use command line utilities, for example bedtools genomecov with -ibam option followed by wigToBigWig program