Tool: karyoploteR: uncircle your genomes
45
gravatar for bernatgel
18 months ago by
bernatgel1.4k
Barcelona, Spain
bernatgel1.4k wrote:

Hi all,

I'd like to present karyoploteR, an R/Bioconductor package we have developed to plot any data on any genome in non-circular layouts. The goal of this project was to develop a tool as flexible as Circos, but easier to user and representing genomes as straight lines instead of circles, and I think we are pretty close to that.

Links

Examples

Just a few examples of plots created with karyoploteR. More available in the Tutorials and Examples page.

enter image description here

Philosophy

The idea behind the package is to try to mimic as much as possible the R base graphics philosophy: create a basic (possibly empty) plot and add data iteratively using simple graphical primitives. The simple graphical primitives part is important. kpPoints, the karyoploteR function equivalent to points, knows nothing about your data, about any special consideration, about anything. It only plots a point where the user says. This has the benefit of making karyoploteR very flexible with regard to the original data. Oh, and the standard graphics parameters (col, border, pch, lwd, lty...) are all available and work as expected.

The inners

At the heart of karyoploteR there's a coordinates change fucntion mapping the genomic coordinates to the plotting coordinates. All plotting functions are implemented around it and end up calling the base R graphics functions (lines, points, rect...) with the transformed coordinates. This function is available to the end user, so it's possible (and not difficult) for the end user to implement additional plotting functions. However, most user will never need to see or care about this.

Show me some code

The main function a user needs to know is plotKaryotype, that will create a plot of the genome and return the karyoplot object needed by the other functions. Giving a set of chromosomes, it will restrict the plot to the selected chromosomes.

kp <- plotKaryotype()

Empty karyoplot

Then, using plotting functions such as kpPoints, kpLines, kpRect, kpSegments, kpText, kpAbline, kpPolygon, etc..., we can keep adding data to the plot.

library(karyoploteR)

x <- 1:23*10e6
y <- rnorm(23, 0.5, 0.1)

kp <- plotKaryotype(chromosomes="chr1")

kpPoints(kp, chr = "chr1", x=x, y=y)
kpText(kp, chr="chr1", x=x, y=y, labels=c(1:23), pos=3)
kpLines(kp, chr="chr1", x=x, y=y, col="#FFAADD")
kpArrows(kp, chr="chr1", x0=x, x1=x, y0=0, y1=y, col="#DDDDDD")

karyoplot with some data

There are additional plotting functions performing more involved computations prior to drawing: kpPlotDensity, that will compute the density of features on the genome and plot it and its sister kpPlotBAMDensity, to plot the density of reads in a BAM file; kpPlotMarkers, to position text labels on the genome (genes or any other feature) avoiding label overlapping; kpPlotLinks, to plot links between genomic regions to represent translocations or any other data type involving two genomic regions; or kpPlotRainfall, to create rainfall plots representing the distance between consecutive genomic features (usually somatic mutations) to show their regional clustering.

Not only human

It is possible to give a different genome name to plotKaryotype to create a karyoplot for the genome of another species. For some of them, karyoploteR will be able to even get the cytoband information and draw a karyoplot with banded ideograms. For others, it will only plot the chromosomes as gray rectangles, but for all of them the data plotting functionality will be available. In fact, it's even possible to provide it with a completely new genome (either real or made up) and work with it without any problem.

I hope you find it as useful as we do, and that karyoploteR may help you in your future genome drawing endeavours.

Oh, and if you have any idea of bug report, pull requests are always welcome!

Bernat

karyoploter tool next-gen R dataviz • 3.6k views
ADD COMMENTlink modified 7 months ago by Vijay Lakhujani3.4k • written 18 months ago by bernatgel1.4k

Can you please look into this question? How to name the genome in karyoploteR ?

https://support.bioconductor.org/p/102549/

ADD REPLYlink modified 13 months ago • written 13 months ago by kirannbishwa01890
1
gravatar for khhgng
18 months ago by
khhgng60
khhgng60 wrote:

Hi.

Wonderful package!

I have plotted some genes on respective chromosomes using karyoploteR. I was just wondering if I could retrieve the information on genes from certain regions within the chromosomes in the plot. Do I need to use any other function similar to cut tree for clusters ? If it is so, what would that function/package be.

Note: due to large number of genes, I haven't used labels.

ADD COMMENTlink modified 18 months ago • written 18 months ago by khhgng60
1

Hi @khhgng

karyoploteR is only a plotting package and can not help you with the selection and manipulation of your data. If you your genes a in a GRanges object, I would recommend you using the subsetByOverlaps function to select the genes in specific genomic regions.

Note: In the future, if you have a question to ask, you should create a new top level question instead of asking in the space where answers are supposed to be. That helps maintaining biostars tidy and organized :)

ADD REPLYlink written 18 months ago by bernatgel1.4k

Thank you @bernatgel

I'll take care of the question space next time. :)

ADD REPLYlink written 18 months ago by khhgng60
1
gravatar for Vijay Lakhujani
7 months ago by
Vijay Lakhujani3.4k
India
Vijay Lakhujani3.4k wrote:

Hi

Very nice project.

I am wondering if i could draw a barplot on a custom genome depicting the reads mapped on particular features; say "genes". So, that will be a pretty simple data set as given below

GeneID   RawReadCount
14490.2     5
011470.2    24
14480.1     0
025190.2    12
007250.1    0
068190.1    11
078810.2    3

The plot looking similar to this; bars representing number of reads enter image description here

I think kpBars is the function I am looking for. Any help is much appreciated.

ADD COMMENTlink modified 7 months ago • written 7 months ago by Vijay Lakhujani3.4k

Not really a barplot but I think that the plot Coverage can be apply on custom genome.

https://bernatgel.github.io/karyoploter_tutorial//Tutorial/PlotCoverage/PlotCoverage.html

ADD REPLYlink written 7 months ago by Bastien Hervé2.7k

Can you just briefly tell me the steps; I will figure out the exact commands myself. What I have is

  • a genome file in fasta format (chr wise)
  • a corresponding GTF file
  • a read count file gene wise as shown above
ADD REPLYlink written 7 months ago by Vijay Lakhujani3.4k
1

This packages is all about positions encapsulated in GRanges. There is no reference sequence.

I would do something like this

Create a new custom genome, if you just have a single chromosome you just need its length, if you have many chromosome, take all the lengths

https://bernatgel.github.io/karyoploter_tutorial//Tutorial/CustomGenomes/CustomGenomes.html

Something like this

custom.genome <- toGRanges(data.frame(chr=c("A"), start=c(1), end=c(length)))
kp <- plotKaryotype(genome = custom.genome)

Create a GRanges with your counts to plot the coverage

https://bernatgel.github.io/karyoploter_tutorial//Tutorial/PlotCoverage/PlotCoverage.html

Example with 2 genes.

geneA -> 1 count

geneB -> 3 counts

Look at the position of geneA and geneB in your GTF file let say :

geneA -> chr1:100:200

geneB-> chr10:500:600

Fill your GRanges (named regions) with :

geneA -> chr1:100:200

geneB-> chr10:500:600

geneB-> chr10:500:600

geneB-> chr10:500:600

kpPlotCoverage(kp, data=regions)

Create markers

https://bernatgel.github.io/karyoploter_tutorial//Tutorial/PlotMarkers/PlotMarkers.html

Use your GTF to create all the markers you want

Same stuff, create a GRanges of the genes you want to display on your custom genome

ADD REPLYlink modified 7 months ago • written 7 months ago by Bastien HervĂ©2.7k

Hi Vijay,

As Bastien said, karyoploteR does not need the reference sequence or anything like that. It just needs the chromosome lengths, which facilitates working with custom and unfinished genomes.

I would do something along the lines of what Bastien suggested.

  1. Create a GRanges object with the lengths of your chromosomes as in the custom genomes tutorial page
  2. Read the GTF into R using rtracklayer import function and build a GenomicRanges object with the positions of your genes
  3. Get the read counts per gene either as an mcols of the genes GRanges or as an independent vector in the same order as the genes GRanges
  4. Plot your data. You can use kpBars to create the bars as you asked, use kpSegments + kpPoints to create kind of a needle plot or however you might want to plot them.

If you are interested in plotting, not the total number of counts per gene but the actual per base coverage you can take a look at the newly added kpArea function.

Hope that helps

ADD REPLYlink written 7 months ago by bernatgel1.4k

Note that the intervals in test file are not big due to which are bars are thinner. I used default chromosome size provided by package.

library(karyoploteR)
kp <- plotKaryotype(chromosomes="chr22")
test=read.csv("test", sep="\t", stringsAsFactors = F, strip.white = T)
> test
    Geneid   chr    Start      End Gene.counts
1     ACO2 chr22 41469124 41528989    3141.000
2      BCR chr22 23180364 23318037    2515.667
3   CELSR1 chr22 46360833 46537170    1123.667
4    EWSR1 chr22 29268008 29300525    2638.833
5  MICALL1 chr22 37906147 37942458    1747.833
6      MIF chr22 23894377 23895222    4219.333
7     MYH9 chr22 36281276 36388067   17474.167
8   PLXNB2 chr22 50274978 50307572    4547.500
9   RBFOX2 chr22 35738735 36028537    2507.833
10    SUN2 chr22 38734713 38755462    2184.000
11    TSPO chr22 43151934 43163242    1565.167
12    XBP1 chr22 28794559 28800572    4342.167

y1=(test$Gene.counts-min(test$Gene.counts))/(max(test$Gene.counts)-min(test$Gene.counts))
kpBars(kp, chr="chr22", x0=test$Start, x1=test$End, y1=y1, col=rainbow(dim(test)[1]))

Rplot
how to delete

ADD REPLYlink modified 7 months ago • written 7 months ago by cpad011210k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1108 users visited in the last hour