bernatgel / karyoploteR

karyoploteR - An R/Bioconductor package to plot arbitrary data along the genome
https://bernatgel.github.io/karyoploter_tutorial/
298 stars 42 forks source link

How to adjust cytoband information to be present only at the location of copy number calls? #55

Closed lakhujanivijay closed 4 years ago

lakhujanivijay commented 4 years ago

Hi

I am trying to plot copy number information over the karyotype plot; a snapshot of which looks something like this

k

I just want to have the cytoband in the regions where there is either a pink or a green bar. For example, you can notice that there is no cytoband information at the regions where there is a pink rectangle at chr15 in the image. I know we can forcefully add all cytobands but this is not what I want as it become clumsy.

This is how I am plotting.

# Plotting the ideogram
kp <- plotKaryotype(genome = "hg19", main="Copy Number data",plot.type=2, plot.params = pp)

# Adding the cytoband information
kpAddCytobandLabels(kp)

Could you please help?

bernatgel commented 4 years ago

Hi @lakhujanivijay, did you find how to do this? Do you still want help with that?

lakhujanivijay commented 4 years ago

Hi @bernatgel

I am still looking for an answer for that. Looking forward to head from you.

bernatgel commented 4 years ago

Hi @lakhujanivijay

You cannot do what you want directly with kpAddCytobandNames (maybe I'll add this option in the future), but you can do it with kpText on the "ideogram" data.panel.

For the example I'll create a set of random regions in the genome representing your copy number changes. After that, we can get the cytoband information with getCytobands and then filter them using overlapsAny to discard the cytobands not overlapping any copy number change.

library(karyoploteR)

cn.regs <- sort(createRandomRegions(nregions = 100))

cyto <- getCytobands(genome="hg19")
#remove the unneded cytobands
cyto <- cyto[overlapsAny(cyto, cn.regs)]

And then you can plot them using kpText. You can plot them on the ideogram itself

kp <- plotKaryotype(chromosomes = c("chr15", "chr16", "chr17"))
kpPlotRegions(kp, cn.regs)
kpText(kp, data=cyto, y=0.5, labels = cyto$name, data.panel = "ideogram", cex=0.8)

selected cytobands

or get a bit more fancy and plot the rotated 45 degrees and below the ideogram with something like this

kp <- plotKaryotype(chromosomes = c("chr15", "chr16", "chr17"))
kpPlotRegions(kp, cn.regs)
kpText(kp, data=cyto, y=0, labels = cyto$name, data.panel = "ideogram", cex=0.8, srt=45, pos=1)

selected cytobands out of ideogram

Does this work for you?

lakhujanivijay commented 4 years ago

Thanks @bernatgel

That should resolve my problem. I am currently travelling but I am excited to try that out as soon as I land. Thanks so much :+1:

bernatgel commented 4 years ago

No problem :) If you have any other problem just ask