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

kpAddCytobandLabels with custom genome and cytoband file fails #147

Open pkerbs opened 8 months ago

pkerbs commented 8 months ago

Hi, I am trying to plot Cytoband labels on the ideogram. It works if I use the default hg19 genome, but not when I use my own genome region and cytoband files. This is my code:

cyto_bed <- read.delim("cytobands_chm13v2.bed", header=T)
cyto_bed <- makeGRangesFromDataFrame(cyto_bed, keep.extra.columns = T)

genome <- read.delim("chm13v2.bed", header=T)
genome <- makeGRangesFromDataFrame(genome, keep.extra.columns = T)

kp <- plotKaryotype(plot.type = 1,
                      chromosomes = "chr1",
                      genome = genome,
                      cytobands = cyto_bed
                      )

kpAddCytobandLabels(kp, force.all=F, cex=0.6, srt=90, col="orange")

This is an excerpt from chm13v2.bed:

chrom   chromStart  chromEnd
chr1    0   248387328
chr2    0   242696752
chr3    0   201105948
chr4    0   193574945

This is an excerpt from cytobands_chm13v2.bed:

chrom   chromStart  chromEnd    name    gieStain    strand
chr1    0   1735965 p36.33  gneg    .
chr1    1735965 4816989 p36.32  gpos25  .
chr1    4816989 6629068 p36.31  gneg    .
chr1    6629068 8634052 p36.23  gpos25  .

Unfortunately, I get this error message:

Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'start': subscript contains invalid names

Can you please have a look what I'm doing wrong? Will it be possible to just set the genome parameter in the plotKaryotype function to the new assembly, so I dont have to provide genome range and cytoband file?

Thanks in advance, Paul

kerbspaul commented 6 months ago

Hi, can anyone please help out?

pkerbs commented 5 months ago

For anyone who is facing the same issue: The problem seems to be that I only want to plot "chr1" but I provide 'genome' and 'cytoband ' GRanges objects containing all chromosomes. The parameter chromosomes of the plotKaryotype() function seems not to work with my custom references that I provide to the function (probably some specific formatting is needed that I'm missing).

Anyways, I figured that when I subset the GRanges objects to only "chr1" it works.

kp <- plotKaryotype(plot.type = 1,
                      chromosomes = "chr1",
                      genome = genome[genome@seqnames=="chr1",],
                      cytobands = cytobands[cytobands@seqnames=="chr1",]
                      )

Best, Paul

fawaz-dabbaghieh commented 4 months ago

Thanks, Paul for the hint, I just wanted to share that your method didn't fully work for me, but this worked

kp <- plotKaryotype(genome = custom.genome[seqnames(custom.genome)=='chr10'], cytobands = custom.cytobands[seqnames(custom.cytobands)=='chr10'], chromosome='chr10')

Where custom.genome and custom.cytobands are GRanges made using toGRanges() function similar to the karyoploteR tutorial. Then I call kpAddCytobandLabels to add the labels, sometimes not all labels are added, one can force all labels using the argument force.all=TRUE

I hope this can help someone