jokergoo / circlize

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

circos.genomicRect border thickness #314

Open Lewis-W-S-Fisher opened 2 years ago

Lewis-W-S-Fisher commented 2 years ago

Hi

I've been trying to map the locations of some mutants within some bacterial genomes I've taken from a directed evolution experiment. I have managed to plot everything out using the circos.genomicRect function. The borders of the rectangles are so large that I can't see some of the mutations even in a high-resolution output. Is there any way to change the border thickness within the genomicRect function?

I've been trying to change them for a while now. I'm using circlize version 0.4.10 to produce the plots (image attached).


mut_all<-  mut_all[c("replicate", "position_start","position_end","frequency", "gene_name", "type", "transfer")]
colnames(mut_all)= c("chr", "start", "end", "value1", "gene", "type", "transfer")

png("test_mut_plot.png", res = 1200, height = 8, width = 8, units = "in") 
circos.clear()

ref<- matrix(c(rep(0, length(sample_factors) ), sample_max), ncol=2)
circos.par("track.height"=0.8, "gap.degree"= 5.2, cell.padding=c(0, 0, 0, 0), "start.degree" = -2.6)

circos.initialize(factors = sample_factors, xlim=ref)
col_text <- "grey40"

# circos.genomicLabels(mut_all[,c("chr", "start", "gene")], labels = mut_all$gene, cex=0.2, side="outside", labels_height=0.1, padding = 1, niceFacing = TRUE, connection_height = 0.1, line_lwd = 0.1)
circos.genomicLabels(mut_all, labels= mut_all$gene, cex=0.2, side="outside", labels_height=0.1, padding = 0.5, niceFacing = TRUE, connection_height = 0.1, line_lwd = 0.1, col = mut_all$type %>% str_replace_all(c("SNP" = "darkorchid2", "INS" = "chartreuse3", "DEL" = "darkorange1")), line_col = mut_all$type %>% str_replace_all(c("SNP" = "darkorchid2", "INS" = "chartreuse3", "DEL" = "darkorange1")))
#

This is the section where the rectangles are added to the track.

track_size_mut<- 0.03

circos.genomicTrack(data=subset(mut_all, transfer == "T14"), panel.fun=function(region, value, ...) {
circos.genomicRect(region, value, type="l", col=NA, border = value$type %>% str_replace_all(c("SNP" = "darkorchid2", "INS" = "chartreuse3", "DEL" = "darkorange1")))
}, track.height=track_size_mut, bg.border=F, bg.col= "gray95")
circos.text(max(CELL_META$xlim) + (0.2*(10^6)), mean(CELL_META$ylim), "T14", sector.index= "EDTA1", cex=0.6, col=col_text,facing="bending.inside", niceFacing=TRUE)

circos.genomicTrack(data= subset(mut_all, transfer == "T7"), panel.fun=function(region, value, ...) {
circos.genomicRect(region, value, type="l", col=NA, border = value$type %>% str_replace_all(c("SNP" = "darkorchid2", "INS" = "chartreuse3", "DEL" = "darkorange1")))
}, track.height=track_size_mut, bg.border=F, bg.col= "gray95")
circos.text(max(CELL_META$xlim) + (0.2*(10^6)), mean(CELL_META$ylim), "T7", sector.index= "EDTA1",cex=0.6, col=col_text,facing="bending.inside", niceFacing=TRUE)

circos.genomicTrack(data=subset(mut_all, transfer == "T1"), panel.fun=function(region, value, ...) {
# circos.genomicRect(region, value, type="l", col=NA, lwd = 0.1, border = value$type %>% str_replace_all(c("SNP" = "darkorchid2", "INS" = "chartreuse3", "DEL" = "darkorange1")))
circos.genomicRect(region, value, type="l", col=NA, border = value$type %>% str_replace_all(c("SNP" = "darkorchid2", "INS" = "chartreuse3", "DEL" = "darkorange1")))
}, track.height=track_size_mut, bg.border=F, bg.col= "gray95")
circos.text(max(CELL_META$xlim) + (0.2*(10^6)), mean(CELL_META$ylim), "T1", sector.index= "EDTA1", cex=0.6, col=col_text,facing="bending.inside", niceFacing=TRUE)
# genomes
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=1, col=col_text, 
facing="bending.inside", niceFacing=TRUE)
}, bg.col="slategray3", bg.border=F, track.height=0.06)

brk <- c(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.3)*10^6
circos.track(track.index = get.current.track.index(), panel.fun=function(x, y) {
circos.axis(h="bottom", major.at=brk, labels=round(brk/10^6, 1), labels.cex=0.4, 
col=col_text, labels.col=col_text, lwd=0.7, labels.facing="outside", direction = "inside")
circos.text(mean(CELL_META$xlim), -0.8, "Size (MB)", cex=0.6, col=col_text,facing="bending.inside", niceFacing=TRUE)
}, bg.border=F)

lgd = Legend(at = c("SNP","INS","DEL"), title = "Mutation Type", legend_gp = gpar(fill = c("darkorchid2","chartreuse3","darkorange1")))

lgd_list_vertical = packLegend(lgd)
draw(lgd_list_vertical, x = unit(4, "mm"), y = unit(4, "mm"), just = c("left", "bottom"))
# labelling the genome
# snp_nonsyn
#line_col="grey80",

dev.off()

Increment_EDTA_plot

Thanks in advance, Lewis

jokergoo commented 2 years ago

How about setting border = NA?

Maybe you can directly use circos.segments() since the rectangles are so short in the genome-scale and they look basically like vertical lines?

PS, the plot looks so nice!