Question: How to plot genomic regions using KaryoplotR
1
gravatar for gabi
4 months ago by
gabi30
gabi30 wrote:

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

karyoplotr R • 231 views
ADD COMMENTlink modified 4 months ago • written 4 months ago by gabi30
setwd("/path/to/dataframe")

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

ADD REPLYlink modified 4 months ago • written 4 months ago by genomax91k

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

ADD REPLYlink modified 4 months ago • written 4 months ago by gabi30

Thanks for your answer

ADD REPLYlink modified 4 months ago • written 4 months ago by gabi30
3
gravatar for bernatgel
4 months ago by
bernatgel2.7k
Barcelona, Spain
bernatgel2.7k wrote:

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 COMMENTlink written 4 months ago by bernatgel2.7k
1

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 REPLYlink written 4 months ago by gabi30
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: 1809 users visited in the last hour