Skip to content

Instantly share code, notes, and snippets.

@jokergoo
Created October 17, 2019 08:20
Show Gist options
  • Save jokergoo/7eeac1f491652b3ea9d58fc017a7c0b4 to your computer and use it in GitHub Desktop.
Save jokergoo/7eeac1f491652b3ea9d58fc017a7c0b4 to your computer and use it in GitHub Desktop.
library(GenomicInteractions)
data(hic_example_data)
hic_example_data = as.data.frame(hic_example_data)
hic_example_data = hic_example_data[hic_example_data$seqnames1 == hic_example_data$seqnames2, ]
gr1 = hic_example_data[, c("seqnames1", "start1", "end1")]
colnames(gr1) = c("chr", "start", "end")
gr2 = hic_example_data[, c("seqnames2", "start2", "end2")]
colnames(gr2) = c("chr", "start", "end")
gr = rbind(gr1, gr2)
gr = unique(gr)
library(circlize)
hic_heatmap = function(pos11, pos12, pos21, pos22, col) {
mid1 = (pos12 + pos11)/2
mid2 = (pos22 + pos21)/2
dist = abs((mid2 - mid1)/2)
x = (mid2 + mid1)/2
y = dist/2
w = ((pos22 - pos21) + (pos12 - pos11))/2
h = w
circos.rect(x - w/2, y - h/2, x + w/2, y + h/2, col = col, border = col)
}
circos.genomicInitialize(gr)
df = hic_example_data
df = df[abs(df$start2 - df$start1) <= 1000000, ]
col_fun = colorRamp2(c(min(df$Z.score), mean(df$Z.score), max(df$Z.score)),
c("red", "white", "blue"))
circos.track(ylim = c(0, max(abs(df$start2 - df$start1))/2),
panel.fun = function(x, y) {
df2 = df[df$seqnames1 == CELL_META$sector.index, ]
hic_heatmap(df2$start1, df2$end1, df2$start2, df2$end2, col_fun(df2$Z.score))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment