Strange clustering of genes with circlize
1
0
Entering edit mode
17 months ago

Hi!

I'm trying to learn the circlize package and I get weird sorting. Can anyone please tell me why the most expressed and the least expressed gene is ending up where they are (see marking) and not following the gradient?

enter image description here

Data looks like this:

From highest:

From highest ...

To lowest:

enter image description here

This is the command I run:

# Create color gradient
col_fun <- colorRamp2(c(-1,0, 1), c("blue", "white", "red"))

# Generate plot on pdf
cairo_pdf("results/plot1_test.pdf", width = 16, height = 9)

# Create gap, start.degree = where to put gap, gap.after = how wide gap should be
circos.par(start.degree = 70, gap.after = 20)

# Create outer track
circos.heatmap(plot1_outer, col = col_fun, rownames.side = "outside", track.height = 0.15)

# Add labels outer track
circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) {
    if(CELL_META$sector.numeric.index == 1) { # the last sector
        cn = "DEG_LogFC"
        n = length(cn)
        circos.text(x = rep(CELL_META$cell.xlim[2], n) + convert_x(0.5, "mm"), 
            y = 1:n - 0.5, labels = cn, 
            cex = 0.5, adj = c(0, 0.5), facing = "inside")
    }
}, bg.border = NA)

# Finnish plot on pdf
dev.off()

I have tried with both cluster = TRUE and cluster = FALSE, also tried sorting the genes before creating the plot but no difference.

Thanks in advance!

/ Jonas

circlize clustering • 1.2k views
ADD COMMENT
0
Entering edit mode

Do you have a reproducible example to share ?

ADD REPLY
0
Entering edit mode

I'm still a newbie sharing examples so please bare with me:), this should do the same that I've done:

Expression data:

library(circlize)

plot1_test <- matrix(c(0.4748492,  0.5351444,  0.8497969,  3.4278286,
                -1.9779784,  0.8765087, -5.8908837,  0.8037300,
                 0.5021405,  0.5998988,  0.6343637,  0.5659290,
                 1.4291314, -1.4149778,  0.7802188,  1.0269317,
                 0.6420512,  0.8561061, -0.7125408,  0.5192895,
                 0.9257238,  0.5288063, -0.3644383,  0.7112215,
                 0.9337274,  0.7363547,  0.5545592,  0.5988651,
                 0.7430341,  0.5978219,  0.8001941,  0.4878343,
                 0.7580226,  1.1410115,  1.0956919,  0.8116950,
                 0.5868673,  0.4762547,  1.6624021, -2.1075874,
                 1.5099941, -0.8946748,  0.9311513,  1.0040981,
                 0.9571870,  0.8888130,  1.2207386,  1.0732732,
                 1.4023531,  0.9773403,  0.3913647,  0.6989768,
                 0.8823830,  0.8397329,  0.6983925,  0.8702640,
                 0.3895301,  1.2378125,  0.6464983,  0.7033468,
                 1.3471489,  1.3073957, -0.7547568,  1.1000356,
                 0.3579646,  1.1231308,  1.0115106,  0.9718779,
                 0.8328745,  1.0591151,  1.1896567,  1.0044788,
                 0.4697877,  0.9125946,  0.8594293,  0.8414113,
                 1.0426547,  4.2487280,  0.8273504,  0.4778255,
                 0.7688796,  0.5477317,  0.5457299,  1.0779658,
                 1.2135389,  1.4035259,  1.1968462,  1.6088494,
                 0.8966552,  1.2994579,  0.6227573,  0.4725519,
                 0.7936587,  0.4772798,  1.2206167,  0.9506172,
                 0.6887560,  0.4361407,  0.6261674,  1.3056722,
                 0.5392434,  0.6819604,  1.1861549,  1.9283673,
                 0.7121887,  0.8097009,  1.1093010,  0.8587159,
                 0.9264578,  0.6554668,  1.1283872,  1.1055221,
                 1.2264729,  1.2078718,  1.2846289,  1.3709123,
                 1.4228383,  0.7584742,  0.5356578,  1.1277608,
                 1.4196110,  1.3276255,  0.6271982,  1.1904942,
                 0.5750034,  1.2576809,  0.8627659,  0.9006491,
                 1.0396896,  0.8691475,  0.6820446,  1.0712047,
                 0.4672566,  0.7652146,  0.7281777,  1.6310587,
                 1.3213242,  1.5035413,  1.3873709,  1.5505445,
                 1.0853602,  1.2766810,  0.5892091,  0.8359556,
                 0.8773134,  0.9466863,  0.6810157, -6.0846084,
                 0.8545320,  1.3528243,  0.5578423,  0.5741580,
                 0.4119951,  0.5616781,  0.5597307, -0.8933222,
                 1.0331076,  0.7352212,  0.6867323,  1.1687474,
                 1.2724813,  1.0016438,  0.7884380,  0.5854143,
                 1.6154984,  1.0793602,  1.0458011,  0.8059026,
                 1.5276903,  0.6257890,  0.5987259,  1.0137737,
                 1.7491244,  1.0787725,  1.0533678,  0.4044182,
                 0.7280915,  0.5569841,  0.9140021,  0.9291537,
                 0.4741540,  0.7562256,  0.7487744,  0.5314093,
                 0.7787232,  1.4742678,  1.1333282,  1.0520202,
                 1.1942212,  1.6232248,  1.7612776,  0.6943532,
                 1.3197289,  1.1941281,  0.9978132,  0.8410580,
                 1.5921791,  0.5663096,  0.7966567,  0.9614676,
                 0.6752435,  0.7482104,  0.9225995,  1.1742201,
                 0.8552826,  0.6667031,  1.1258996,  0.4824958,
                 0.9477075, -1.9010897,  1.3565489,  1.2067280,
                 1.8520390,  0.6534349,  1.2346649,  1.5661147,
                 0.7676541,  0.7674463,  0.6284340,  0.5166927,
                 0.9990062,  0.7890531,  1.3207415,  1.5128454,
                 1.4004072,  0.7205593,  0.9853098, -1.8251111,
                 0.7758262,  0.7575733,  1.3071139,  0.5600479,
                 0.5206294, -2.0506062,  0.8752429,  1.0797814,
                -0.7062786,  0.9633238,  0.4266171,  1.0214466,
                 0.7181451,  0.6762721,  0.9982646, -1.2294903,
                 1.1485967, -1.9010897,  1.1857543,  1.0433829,
                 1.0774660, -1.2965657,  0.6594886,  0.7772028,
                 1.4488522,  1.3835714,  0.4887241, -1.2419381,
                -1.0600931,  0.9213746,  0.9876605,  1.0775845,
                -0.9138965,  1.6079838,  0.4454142,  1.6045913,
                -1.3387024,  1.3721984,  0.7039122,  0.5806491,
                 1.1154164,  1.4948087,  1.1649152,  1.2288630,
                -1.8234571)

)

rownames(plot1_test) <- rep(paste0("gene", 1:273), each = 1)

col_fun <- colorRamp2(c(-1,0, 1), c("blue", "white", "red"))

cairo_pdf("............pdf", width = 16, height = 9)

circos.par(start.degree = 70, gap.after = 20)

circos.heatmap(plot1_test, col = col_fun, rownames.side = "outside", track.height = 0.15)

circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) {
if(CELL_META$sector.numeric.index == 1) {
    cn = "DEG_LogFC"
    n = length(cn)
    circos.text(x = rep(CELL_META$cell.xlim[2], n) + convert_x(0.5, "mm"), 
        y = 1:n - 0.5, labels = cn, 
        cex = 0.5, adj = c(0, 0.5), facing = "inside")
}

}, bg.border = NA)

dev.off()

circos.clear()
ADD REPLY
1
Entering edit mode
17 months ago
Basti ★ 2.0k

The issue is that you used circos_heatmap() which display genes according to clustering.

You should can turn off this clustering but you need to sort your dataframe beforehand and then specify cluster=FALSEin the circus.heatmap arguments:

plot1_test=plot1_test[order(plot1_test[,1],decreasing=TRUE),,drop=FALSE]
circos.heatmap(plot1_test, cluster=FALSE,col = col_fun,rownames.side = "outside")

enter image description here

ADD COMMENT
0
Entering edit mode

Great, thank you so much for your help! how stupid of me, I think I have missunderstood what cluster does in this function... can you please explain what cluster does exactly?

best Jonas

ADD REPLY
0
Entering edit mode

It applies hierarchical clustering on your data, based on Euclidean distance

ADD REPLY
0
Entering edit mode

Agree with Basti .

Just want to add a bit from the documentation.

circos.heatmap() documentation, section 6.4, states firstly that:

By default, the numeric matrix is clustered on rows. cluster argument can be set to FALSE to turn off the clustering.

Of course, when cluster is set to FALSE, no dendrogram is drawn even if dend.side is set.

and secondly that,

Clustering method and distance method are controlled by clustering.method and distance.method arguments.

Please note circos.heatmap() does not directly support clustering on matrix columns. You should apply column reordering before send to circos.heatmap()

ADD REPLY
0
Entering edit mode

Ah I see, thx Basti and thx LauferVA for clarifying! highly appreciated!

ADD REPLY

Login before adding your answer.

Traffic: 2305 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6