Customize IGV coverage track in R
5
2
Entering edit mode
10.4 years ago
lkmklsmn ▴ 980

Hi Biostars,

I want to recreate the IGV coverage track in R. I want to be able to customize and edit a coverage plot. All I need for this is per base coverage of a given gene. I have bam input file.

Thanks

RNA-Seq R IGV coverage • 7.9k views
ADD COMMENT
2
Entering edit mode
10.4 years ago
poisonAlien ★ 3.2k

Okay. Is this what you want? Check out Gviz Bioconductor package specifically section 4.9: Alignment track.

For ex:

library(Gviz) #load library
alTrack=AlignmentsTrack("foo_sorted.bam",isPaired=T) #Read bam file
plotTracks(alTrack,from=87072069,to=87073068,chromosome="chr4") #plot the required region; plots coverage, alignment section
plotTracks(alTrack,from=87072069,to=87073068,chromosome="chr4",type="coverage") #plot only coverage, no depth or alignment section

ADD COMMENT
0
Entering edit mode
10.4 years ago
Caddymob ★ 1.0k

GATK DepthOfCoverage or Bedtools genomecov are probably your best bet

ADD COMMENT
0
Entering edit mode

I used this:

coverageBed -abam test.bam -b test.bed -d -split -hist > coverageTest.txt

I can generate a coverage track from this in R but the coverage quantity does not agree with what I see on IGV. IGVs numbers are lower.

ADD REPLY
0
Entering edit mode
10.4 years ago
Varun Gupta ★ 1.3k

Try this

genomeCoverageBed -ibam test.bam -g my.genome -d > perbase_cov.txt

where my.genome is the genomic file.

Genome files must be tab-delimited and are structured as follows (this is an example for C. elegans):

chrI 15072421
chrII 15279323
...
chrX 17718854
chrM 13794

2nd column is the length of the chromosome.

Refer bedtools

Varun

ADD COMMENT
0
Entering edit mode
10.4 years ago

Since you have "RNA-seq" among your tags I guess this is what you want to plot. In this case I would use bedtools genomeCovergeBed as others have suggested, but with the -split option to correctly represent reads spanning different exons. From the docs:

bedtools genomecov will, by default, screen for overlaps against the entire span of a spliced/split BAM alignment or blocked BED12 feature. When dealing with RNA-seq reads, for example, one typically wants to only screen for overlaps for the portions of the reads that come from exons (and ignore the interstitial intron sequence). The -split command allows for such overlaps to be performed

ADD COMMENT
0
Entering edit mode
10.4 years ago
lkmklsmn ▴ 980

Thanks for the responses. I actually ended up using:

samtools depth file.bam > coverage.bam

This command gave me the exact numbers I was seeing in IGV on a per-nucleotide basis

ADD COMMENT
0
Entering edit mode

Maybe a little more explanation since I didnt really end up using R.

Here is my pseudocode form within R:

system("samtools depth file.bam > coverage.bam")
tab<-read.table("coverage.bam")
barplot(tab[,3])
ADD REPLY
0
Entering edit mode

Take care that samtools depth reports coverage capped to max 8000 I think. Also if you have RNA-Seq make sure reads spanning introns are not counted within the intron.

ADD REPLY

Login before adding your answer.

Traffic: 1524 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6