rplotcirclizecircos

Errors adding genomic feature track in circlize


I'm trying to generate a circos plot with a simple genomic notation from BED files. However, when I use circos.genomeRect this results in an error, or in a track that does not plot rectangles, but semicircles as I show below.

Consider the following reproducible example:

library("circlize")
library("tidyverse")

circos.par(start.degree = 90,
           cell.padding = c(0, 0, 0, 0),
           #points.overflow.warning=FALSE,
           track.height = 0.10   
)

# Initialize genome (bed file with genome sizes)
genome <- tibble(chr=c("chr1","chr2"), start = c(1,1), end = c(6000000, 3000000))
circos.genomicInitialize(genome, plotType = c("axis"), major.by = 1000000)

# Add track with annotation
feature <- tibble(chr = c("chr1", "chr1"), start = c(2500, 4500000), end = c(4150000, 6350000))
circos.genomicTrack(feature, ylim=c(0,1),
                    panel.fun = function(region, value, ...) {
                      circos.genomicRect(region, value, ytop.column = 1, ybottom = 0, col="blue")
                    })
circos.clear()

This returns an error:

Error in if (sum(l) && circos.par("points.overflow.warning")) { : missing value where TRUE/FALSE needed

In addition: Warning message: In is.na(x) | is.na(y) : Error in if (sum(l) && circos.par("points.overflow.warning")) { : missing value where TRUE/FALSE needed

At this point, if points.overflow.warning=FALSE is set in circos.par above, the error disappears, but some other error must be occurring, that this does not plot rectangles:

enter image description here

Am I missing something? what is wrong with this simple example? Thank you

EDIT

I just noticed that the feature dataframe I plot has one coordinate wrong, since it extends longer than the actual size of the chromosome. However, if this is fixed, eg: feature <- tibble(chr = c("chr1", "chr1"), start = c(2500, 4500000), end = c(4150000, 5350000)), a new error appears!!

Warning message: In is.na(x) | is.na(y) : longer object length is not a multiple of shorter object length


Solution

  • It seems to work with data.frames instead of tibbles:

    library("circlize")
    
    circos.par(start.degree = 90,
               cell.padding = c(0, 0, 0, 0),
               #points.overflow.warning=FALSE,
               track.height = 0.10   
    )
    
    # Initialize genome (bed file with genome sizes)
    genome <- data.frame(chr=c("chr1","chr2"), start = c(1,1), end = c(6000000, 3000000))
    circos.genomicInitialize(genome, plotType = c("axis"), major.by = 1000000)
    
    # Add track with annotation
    feature <- data.frame(chr = c("chr1", "chr1"), start = c(2500, 4500000), end = c(4150000, 5350000))
    
    
    circos.genomicTrack(feature, ylim=c(0,1),
                        panel.fun = function(region, value, ...) {
                          circos.genomicRect(region, value, col="blue")
                        })
    

    circos.clear()
    

    Created on 2020-08-11 by the reprex package (v0.3.0)