jokergoo / circlize

Circular visualization in R
http://jokergoo.github.io/circlize_book/book/
Other
959 stars 141 forks source link

Mapping contigs of assembly from database to circular genome and plotting #395

Closed jonaskohh closed 2 months ago

jonaskohh commented 2 months ago

hello. I have a circular bacterial genome and I would like to map the contigs of an available genome assembly from a database to my circular genome. I have a txt file of the contigs that is mapped to my chromosome with start and end points. The below is my current code and I would like to achieve something like this in the picture (marked with a big red X, with the orange rectangle).

############################## Circos plot ############################## library(circlize)

Clear any existing Circos plots

circos.clear()

Define the chromosome name and size

genome_size <- 6051261 col_text <- "grey40"

Initialize the circular plot with the genome size

circos.par(gap.degree=0) circos.initialize(factors = "Chromosome", xlim = c(0, genome_size))

############### Add a track to display the chromosome name circos.track( ylim = c(0, 1), panel.fun = function(x, y) { chr = CELL_META$sector.index xlim = CELL_META$xlim ylim = CELL_META$ylim circos.text( mean(xlim), mean(ylim), chr, cex = 0.5, col = col_text, facing = "bending.inside", niceFacing = TRUE ) }, bg.col = "grey90", bg.border = FALSE, track.height = 0.06 )

Define breakpoints for the genome

brk <- seq(0, genome_size, by = 0.5 * 10^6) circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) { circos.axis(h = "top", major.at = brk, labels = round(brk / 10^6, 1), labels.cex = 0.8, col = col_text, labels.col = col_text, lwd = 0.7, labels.facing = "clockwise") }, bg.border = FALSE)

############# Add a genomic track for coverage circos.genomicTrack( data = median_coverage, panel.fun = function(region, value, ...) { circos.genomicLines(region, value, type = "l", col = "grey50", lwd = 0.6) circos.segments(x0 = 0, x1 = genome_size, y0 = 100, y1 = 100, lwd = 0.6, lty = "11", col = "grey90") circos.segments(x0 = 0, x1 = genome_size, y0 = 1100, y1 = 1100, lwd = 0.6, lty = "11", col = "grey90") }, track.height = 0.15, bg.border = FALSE )

Determine the actual range of coverage values

lowest_coverage <- 100 highest_coverage <- 1000

Set appropriate y-axis tick positions based on your coverage range

y_axis_ticks <- seq(lowest_coverage, highest_coverage, by = 300) circos.yaxis(at = y_axis_ticks, labels.cex = 0.7, lwd = 0, tick.length = 0, labels.col = col_text, col = "#FFFFFF")

Add minor axis lines

minor_brk <- seq(min(brk), max(brk), length.out = length(brk) * 5) for (tick in minor_brk) { circos.lines(rep(tick, 2), c(100, 1000), lwd = 0.4, col = "grey80") }

Add minor horizontal lines at y-axis labels

for (tick in y_axis_ticks) { circos.lines(c(0, genome_size), rep(tick, 2), lwd = 0.4, col = "grey80") }

I appreciate your help!! 03