How to plot genomic regions using KaryoplotR
1
1
Entering edit mode
3.8 years ago
gabi ▴ 30

Hi everyone,

I am trying to plot genomic regions using KaryoplotR. I have been following the tutorial page, I converted my data frame into Granges object, however the tool does not work with my data. My data frame is simply a list of genomic location ['chr', 'start', 'end']

The following script doesn't give any warning or error message and only plots the chromosomes but not the genomic regions:

library(karyoploteR)
library(GenomicRanges)
library(data.table)

setwd("/path/to/dataframe") 


df <- fread("for_ideogram.csv", header = T)

gr <- makeGRangesFromDataFrame(df, start.field="start",  end.field= "end")

kp <- plotKaryotype(genome = "hg19", chromosomes="autosomal", plot.type = 1)

kpPlotRegions(kp, data=gr)

Does anyone know how to get this to work?

Thanks

R karyoplotR • 1.7k views
ADD COMMENT
0
Entering edit mode
setwd("/path/to/dataframe")

Is pointing to directory with your data correct? Not the name of the dataframe as written.

ADD REPLY
0
Entering edit mode

Thanks for formatting the code part (I have no idea how to do it). Yes it is just the path.

ADD REPLY
0
Entering edit mode

Thanks for your answer

ADD REPLY
3
Entering edit mode
3.8 years ago
bernatgel ★ 3.4k

Hi @gabi,

When karyoploteR creates the ideogram but nothing gets added to it with the other plotting functions, in many cases it is due to different chromosome names.

Are your gr chromosome names in UCSC style ("chr1", "chr2", ...) or in Ensembl/NCBI style ("1", "2", ...)? The default bioconductor chromosome names are UCSC style and these are the ones used by karyoploteR.

Please check if adding seqlevelsStyle(gr) <- "UCSC" before plotting solves the problem.

library(karyoploteR)
library(GenomicRanges)
library(data.table)

setwd("/path/to/dataframe") 


df <- fread("for_ideogram.csv", header = T)

gr <- makeGRangesFromDataFrame(df, start.field="start",  end.field= "end")
seqlevelsStyle(gr) <- "UCSC"

kp <- plotKaryotype(genome = "hg19", chromosomes="autosomal", plot.type = 1)
kpPlotRegions(kp, data=gr)

and I don't know the structure of your csv file, but if the first 3 columns contain the chr, the start and the end positions (like a bed file and with any names) you can use toGRanges simplify you code to this (toGRanges will change the chromosome names to the ones used by "hg19" in this case):

library(karyoploteR)

gr <- toGRanges("path/to/dataframe/for_ideogram.csv", genome="hg19") 

kp <- plotKaryotype(genome = "hg19", chromosomes="autosomal", plot.type = 1)
kpPlotRegions(kp, data=gr)

If this does not work, I'd need to see the first couple of lines for you csv file to understand what's going on.

ADD COMMENT
1
Entering edit mode

Hi Bernat,

My gr chromosomes were indeed Ensembl style. Adding

seqlevelsStyle(gr) <- "UCSC"

does solve the problem and I'm getting beautiful plots now :)

Thank you @bernatgel for the extensive and clear response!

ADD REPLY

Login before adding your answer.

Traffic: 3156 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